York University AK/ITEC INTRODUCTION TO DATA STRUCTURES. Final Sample II. Examiner: S. Chen Duration: Three hours

Similar documents
York University AS/AK/ITEC INTRODUCTION TO DATA STRUCTURES. Midterm Sample I. Examiner: S. Chen Duration: One Hour and 30 Minutes

York University. AP/ITEC Section M INTRODUCTION TO DATA STRUCTURES Winter Midterm Test

York University AK/ITEC OBJECT-BASED PROGRAMMING. Midterm Test Sample. Examiner: S.Y. Chen Duration: One Hour and Fifteen Minutes

COSC 2007 Data Structures II Final Exam. Part 1: multiple choice (1 mark each, total 30 marks, circle the correct answer)

CSE 373 Autumn 2012: Midterm #2 (closed book, closed notes, NO calculators allowed)

Instructions. Definitions. Name: CMSC 341 Fall Question Points I. /12 II. /30 III. /10 IV. /12 V. /12 VI. /12 VII.

CS 112 Final May 8, 2008 (Lightly edited for 2012 Practice) Name: BU ID: Instructions

University of Waterloo Department of Electrical and Computer Engineering ECE 250 Algorithms and Data Structures

Computer Science E-22 Practice Final Exam

Data Structures Brett Bernstein

Prelim 2. CS 2110, November 19, 2015, 7:30 PM Total. Sorting Invariants Max Score Grader

Prelim 2 Solution. CS 2110, November 19, 2015, 7:30 PM Total. Sorting Invariants Max Score Grader

Final Examination CSE 100 UCSD (Practice)

Technical University of Denmark

CSE 332 Autumn 2013: Midterm Exam (closed book, closed notes, no calculators)

CS 314 Final Fall 2011

UNIVERSITY OF WATERLOO DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING E&CE 250 ALGORITHMS AND DATA STRUCTURES

Prelim 2 Solution. CS 2110, November 19, 2015, 5:30 PM Total. Sorting Invariants Max Score Grader

CS350: Data Structures Heaps and Priority Queues

CSCE 2014 Final Exam Spring Version A

Course Review for Finals. Cpt S 223 Fall 2008

Summer Final Exam Review Session August 5, 2009

CSL 201 Data Structures Mid-Semester Exam minutes

CSE 332 Spring 2014: Midterm Exam (closed book, closed notes, no calculators)

CSE 332 Winter 2015: Midterm Exam (closed book, closed notes, no calculators)

MULTIMEDIA COLLEGE JALAN GURNEY KIRI KUALA LUMPUR

Solutions to Exam Data structures (X and NV)

CS24 Week 8 Lecture 1

ECE 242 Data Structures and Algorithms. Heaps I. Lecture 22. Prof. Eric Polizzi

CS210 (161) with Dr. Basit Qureshi Final Exam Weight 40%

CS-301 Data Structure. Tariq Hanif

Exam Datastrukturer. DIT960 / DIT961, VT-18 Göteborgs Universitet, CSE

CSCE 210/2201 Data Structures and Algorithms. Prof. Amr Goneid

Largest Online Community of VU Students

CSCE 210/2201 Data Structures and Algorithms. Prof. Amr Goneid. Fall 2018

CS 112 Final May 8, 2008 (Lightly edited for 2011 Practice) Name: BU ID: Instructions GOOD LUCK!

CSE100 Practice Final Exam Section C Fall 2015: Dec 10 th, Problem Topic Points Possible Points Earned Grader

COS 226 Algorithms and Data Structures Fall Midterm

E.G.S. PILLAY ENGINEERING COLLEGE (An Autonomous Institution, Affiliated to Anna University, Chennai) Nagore Post, Nagapattinam , Tamilnadu.

University of Waterloo Department of Electrical and Computer Engineering ECE 250 Data Structures and Algorithms. Final Examination T09:00

University of Waterloo Department of Electrical and Computer Engineering ECE250 Algorithms and Data Structures Fall 2014

Dartmouth College Computer Science 10, Fall 2014 Solution to Final Exam A

Exam Data structures DIT960/DAT036

Midterm solutions. n f 3 (n) = 3

CSE 373 Sample Midterm #2 (closed book, closed notes, calculators o.k.)

A6-R3: DATA STRUCTURE THROUGH C LANGUAGE

CS/ENGRD2110: Final Exam

ECE 250 Algorithms and Data Structures

Exam Datastrukturer. DIT960 / DIT961, VT-18 Göteborgs Universitet, CSE

University of Waterloo Department of Electrical and Computer Engineering ECE 250 Data Structures and Algorithms. Final Examination

CMSC132, Practice Questions

End-Term Examination Second Semester [MCA] MAY-JUNE 2006

6.006 Final Exam Name 2. Problem 1. True or False [30 points] (10 parts) For each of the following questions, circle either True, False or Unknown.

BINARY HEAP cs2420 Introduction to Algorithms and Data Structures Spring 2015

~UTS UNIVERSITY OF TECHNOLOGY SYDNEY

CS251-SE1. Midterm 2. Tuesday 11/1 8:00pm 9:00pm. There are 16 multiple-choice questions and 6 essay questions.

Data Structures Question Bank Multiple Choice

CSE 214 Computer Science II Heaps and Priority Queues

FINALTERM EXAMINATION Fall 2009 CS301- Data Structures Question No: 1 ( Marks: 1 ) - Please choose one The data of the problem is of 2GB and the hard

1. AVL Trees (10 Points)

COMP 250 Midterm #2 March 11 th 2013

A6-R3: DATA STRUCTURE THROUGH C LANGUAGE

COMP 251 Winter 2017 Online quizzes with answers

Recursion, Binary Trees, and Heaps February 18

Total Score /1 /20 /41 /15 /23 Grader

CSE 332, Spring 2010, Midterm Examination 30 April 2010

COS 226 Algorithms and Data Structures Fall Midterm

Faculty of Science FINAL EXAMINATION COMP-250 A Introduction to Computer Science School of Computer Science, McGill University

Prelim 2. CS 2110, November 20, 2014, 7:30 PM Extra Total Question True/False Short Answer

University of Illinois at Urbana-Champaign Department of Computer Science. Second Examination

Introduction to Algorithms May 14, 2003 Massachusetts Institute of Technology Professors Erik Demaine and Shafi Goldwasser.

EXAMINATIONS 2017 TRIMESTER 2

CS61B, Fall 2011 Final Examination (corrected) P. N. Hilfinger

Total Score /15 /20 /30 /10 /5 /20 Grader

COMP 103. Data Structures and Algorithms

CS 251, LE 2 Fall MIDTERM 2 Tuesday, November 1, 2016 Version 00 - KEY

INSTITUTE OF AERONAUTICAL ENGINEERING

CS301 All Current Final Term Paper Subjective 2013 Solved with refernces

Final Exam. CS2110 Spring May 12, Total. Max Score

Problem Score Maximum MC 34 (25/17) = 50 Total 100

CSE373 Fall 2013, Second Midterm Examination November 15, 2013

CPSC 211, Sections : Data Structures and Implementations, Honors Final Exam May 4, 2001

Second Examination Solution

Computer Science Foundation Exam

Recitation 9. Prelim Review

Draw the resulting binary search tree. Be sure to show intermediate steps for partial credit (in case your final tree is incorrect).

1. [1 pt] What is the solution to the recurrence T(n) = 2T(n-1) + 1, T(1) = 1

CSE 373 Spring 2010: Midterm #2 (closed book, closed notes, NO calculators allowed)

ext Total Score /20 /20 /15 /20 /25 /5 Grader

APJ ABDUL KALAM TECHNOLOGICAL UNIVERSITY THIRD SEMESTER B.TECH DEGREE EXAMINATION, JULY 2017 CS205: DATA STRUCTURES (CS, IT)

University of Illinois at Urbana-Champaign Department of Computer Science. Final Examination

CSE 373 Winter 2009: Midterm #1 (closed book, closed notes, NO calculators allowed)

University of Toronto Department of Electrical and Computer Engineering. Midterm Examination. ECE 345 Algorithms and Data Structures Fall 2012

CS 540: Introduction to Artificial Intelligence

CS171 Final Practice Exam

COS 226 Midterm Exam, Spring 2009

CSE373 Fall 2013, Final Examination December 10, 2013 Please do not turn the page until the bell rings.

CS 2150 Final Exam, Spring 2018 Page 1 of 10 UVa userid:

Prelim 2, CS2110. SOLUTION

Multiple Choice. Write your answer to the LEFT of each problem. 3 points each

Transcription:

York University AK/ITEC 262 3. INTRODUCTION TO DATA STRUCTURES Final Sample II Examiner: S. Chen Duration: Three hours This exam is closed textbook(s) and closed notes. Use of any electronic device (e.g. for computing and/or communicating) is NOT permitted. Do not unstaple this test book any detached sheets will be discarded. Answer all questions in the space provided. No additional sheets are permitted. Work independently. The value of each part of each question is indicated. The total value of all questions is 1. Write your name and student number in the space below. Do the same on the top of each sheet of this exam where indicated. Surname: Given Names: Student Number: Q1. Q6. Totals Q2. Q7. Q3. Q8. Q4. Q9. Q5. Q1. Page 1 of 15

Question 1 (1 marks) Complexity Analysis/Estimation: Assume that an array has n random values. What is the time complexity of the following method that determines if the values in the array are sorted from smallest to largest? Note: you must show all of your work to receive full credit. public boolean issorted (int[] intarray) { for (int i = ; i < intarray.length-1; i++) { if (intarray[i] > intarray[i+1]) return false; } } return true; Page 2 of 15

Question 2 (1 marks) Linked Data Structures: Answer both parts below. Part A (5 marks): The in-order traversal of a binary tree processes the nodes in the order ABCD. The post-order traversal of the same binary tree processes the nodes in the order ACDB. Draw the tree below. Part B (5 marks): Inserting one element at a time, what is the best case time complexity to add n elements to an initially empty linked list so that the stored values will be sorted from smallest to largest? Explain. A BST has n nodes. What is the time complexity of an in-order traversal? Page 3 of 15

Question 3 (1 marks) Recursion: Write a recursive method that will print in order the first i nodes of a binary tree. root D B E A C Note: root is an instance of the class BinNode: public class BinNode { public char value; public BinNode left; public BinNode right; } Thus, the following statements would lead to the underlined output: Example 1: Example 2: printinodes (root, 4, ); A B C D printinodes (root, 12, ); A B C D E Please write your method on the following page. You may use this page for rough work, but anything on this page will not be graded. Page 4 of 15

public static int printinodes (BinNode node, int i, int count) { } Page 5 of 15

Question 4 (1 marks) Heaps: Answer both parts below. Part A (5 marks): Heapify the elements of the following array into a max-heap. original array 1 5 2 6 8 7 9 3 1 heapified array Part B (5 marks): Remove the largest element from the following array which represents a max-heap. original array 1 8 9 7 1 2 3 5 6 final array Page 6 of 15

First name: Student #: Question 5 (1 marks) Grammars: Answer both parts below. Part A (5 marks): A grammar G = (T,N,S,P) has T = {x,y,z}, N = {Z,A}, S = Z, and the following productions P: Z A A x y A A A z A A x A x A y A z Show a parse tree for the sentence x y z z x. Part B (5 marks): Write a grammar for a language whose sentences start with an even and non-zero number of x s, end with an odd number of z s, and have a number of y s in between equal to the total number of x s and z s in the sentence. For example, xxyyyyyzzz is a valid sentence. Page 7 of 15

Question 6 (1 marks) Programming with Data Structures: The API for the Queue class is given below. Constructor Summary Queue () Construct an empty Queue. Method Summary Object dequeue () Remove and return the first element in the Queue. Return null if the Queue is empty. void enqueue (Object item) Add the given item to the end of the Queue. The API for the Node class is given below. Constructor Summary Node () Construct a node that can be used to make a binary tree. The child links will be null and the value will be -1. Node (int value) Construct a Node with the value set to item. Method Summary Node getleft () Returns the left child of this Node. Node getright () Returns the right child of this Node. int getvalue () Returns the value of this Node. Page 8 of 15

Using the above API s for Queues and Nodes, write a method that will perform a level order traversal of a binary tree. Example: binary tree: root 1 2 3 4 5 6 7 8 9 call: printinlevelorder(root); output: 1 2 3 4 5 6 7 8 9 Please write your method on the following page. You may use the above pages for rough work, but anything on these pages will not be graded. Page 9 of 15

public static void printinlevelorder (Node root) { } Page 1 of 15

First name: Student #: Question 7 (1 marks) Graph Algorithms: Shown below is an undirected weighted graph G. a 5 b 1 c 8 2 9 d 8 e 3 4 f 6 5 g 8 6 3 h Using Dijkstra s algorithm on the above graph to determine the Shortest Paths to node F. Fill in the following table that provides the distance estimates after each node is processed. Nodes A B C D E F G H Current Estimate Final Values Page 11 of 15

First name: Student #: Question 8 (1 marks) Graph Algorithms II: Shown below is a weighted graph G. a 7 b 1 c 8 2 3 d 8 e 5 4 f 6 5 g 2 9 7 h Use Prim s algorithm on the above graph to determine the Minimum-Cost Spanning Tree of directed edges with node E as the root of the MCST (e.g. node E is the source of a cable broadcast, and the MCST shows how the signal will be transmitted to every station in the network). Show the graph of your MCST below using an adjacency-list representation, and draw the directed MCST on the graph above. Ties may be broken randomly. A B C D E F G H Page 12 of 15

Question 9 (1 marks) Game Trees: Answer both parts below. Part of the game tree for a fictitious game is shown below. The value returned by the evaluation function applied to each leaf of the tree is indicated inside the leaf. As indicated, the machine has a choice among three moves (a, b, c). The machine is attempting to maximize, and its opponent is attempting to minimize. max a b c min max 3 2 4 6 3 5 4 2 6 min 3 1 1 7 6 3 Part A (4 marks): Using the min-max algorithm, which move should be made by the machine. a, b, or c? What is the end value of this move? Part B (6 marks): Circle the parts of the tree that would be pruned if alpha-beta search is used. Assume the search is done depth-first, left-to-right. Page 13 of 15

Question 1 (1 marks) Hashing: Answer both parts below. Assume a hash table with size H = 11 with the following hash function: h: index = (key mod H) Part A (5 marks): Show the contents of the hash table after the following operations have been performed. Indicate next to each operation the series of cells examined. Assume that linear probing is used to resolve collisions and that the hash table is initially as shown. cells insert 6 6 7 insert 5 insert 15 search 28 delete 4 insert 6 1 2 3 4 5 6 7 8 9 1 114 116 6 Page 14 of 15

Part B (5 marks): Show the contents of the hash table after the following operations have been performed. Indicate next to each operation the series of cells examined. Assume that quadratic probing is used to resolve collisions and that the hash table is initially as shown. insert 3 insert 14 cells 1 2 3 4 114 search 28 delete 3 search 3 5 6 7 8 9 116 1 Page 15 of 15