COMP 352 SUMMER 2018 1 Tutorial Session 12

  • Slides: 15
Download presentation
COMP 352 –SUMMER 2018 1 Tutorial Session 12

COMP 352 –SUMMER 2018 1 Tutorial Session 12

MCQ 1 The following recursive formula T(n)= T(n/3)+O(1) has as solution : A. T(n)=

MCQ 1 The following recursive formula T(n)= T(n/3)+O(1) has as solution : A. T(n)= Θ(n) B. T(n)=Θ(nlogn) C. T(n)=Θ(logn) D. T(n)=Θ(n 2) 2

MCQ -2 A public class Node { public int val; public Node left; public

MCQ -2 A public class Node { public int val; public Node left; public Node right; } Consider the following method: public static Node mystery(Node root) { if (root. right == null) return root; else return mystery(root. right); } 3

MCQ-2 B You consult three supposedly tech-savvy consultants, and you get the following three

MCQ-2 B You consult three supposedly tech-savvy consultants, and you get the following three opinions about what the method does when passed a reference to the root node of a binary tree: I. It returns the last node visited by an inorder traversal II. It returns the last node visited by a postorder traversal III. It returns the last node visited by a level-order traversal 4

MCQ-2 C Which of these opinions is correct regardless of the contents of the

MCQ-2 C Which of these opinions is correct regardless of the contents of the tree? A. I only B. II only C. III only D. I and III E. II and III 5

MCQ 3 If you began with an empty AVL tree, and then inserted the

MCQ 3 If you began with an empty AVL tree, and then inserted the following keys into the tree in the following order: 40, 20, 15, 25, 30, 80, 75, 90, 35, 100 Which key would be in the root of the tree after inserting all the keys? A. 75 B. 40 C. 35 What is the height of the above AVL tree? A. 3 B. 4 C. 5 D. 6 6

MCQ 4 If the binary tree below is printed by a preorder traversal, what

MCQ 4 If the binary tree below is printed by a preorder traversal, what will the result be? A. B. C. D. E. 9 4 17 16 12 11 6 9 17 6 4 16 22 12 6 9 17 4 16 22 12 6 17 22 9 4 16 12 6 17 9 4 22 16 12 7

MCQ 5 If a binary search tree is not allowed to have duplicates, there

MCQ 5 If a binary search tree is not allowed to have duplicates, there is more than one way to delete a node in the tree when that node has two children. One way involves choosing a replacement node from the left subtree. If this is done, which node are we looking for? A. the largest node in the subtree B. the smallest node in the subtree C. the root of the left subtree D. the next-to-smallest node in the subtree E. it doesn’t matter – any node in the left subtree will do 8

MCQ 6 Suppose that you need to maintain a collection of data whose contents

MCQ 6 Suppose that you need to maintain a collection of data whose contents are fixed— i. e. , you need to search for and retrieve existing items, but never need to add or delete items. Although the collection of data may be quite large, you may assume that it can fit in the computer’s memory. Which of the following data structures is the most efficient one to use for this task? A. sorted array B. a linked list C. a binary search tree D. a queue E. all of the above perform the same in this case 9

MCQ 7 A graph implementation that uses a two-dimensional array to represent the edges

MCQ 7 A graph implementation that uses a two-dimensional array to represent the edges would be most reasonable for which of the following cases? A. 1000 nodes, 1200 edges B. 100 nodes, 4000 edges C. 1000 nodes, 10000 edges D. 10 nodes, 20 edges E. none of these, since a graph can only be represented by a linked structure. 10

MCQ 8 Consider the following directed graph. Which of the following is a valid

MCQ 8 Consider the following directed graph. Which of the following is a valid order of node visitation during depth first search (DFS) traversal? A. A D B C F E B. B F E A D C C. D B F C A E D. C F B A E D E. E A D B C F 11

MCQ 9 Let A be an array storing n elements. Which of the following

MCQ 9 Let A be an array storing n elements. Which of the following statements is true? A. If A is almost sorted, selection sort should be used. B. Mergesort is always the fastest algorithm in practice to sort A. C. Quicksort is always the fastest algorithm in practice to sort A. D. If A is so large that it does not fit into the main memory, insertion sort should be used. E. If A is so large that it does not fit into the main memory, merge sort should be used. 12

MCQ 10 Suppose you have a directed graph representing all the flights that an

MCQ 10 Suppose you have a directed graph representing all the flights that an airline flies. What algorithm might be used to find the best sequence of connections from one city to another? A. Breadth first search. B. Depth first search. C. A cycle-finding algorithm. D. A shortest-path algorithm. 13

MCQ 11 What is the best definition of a collision in a hash table?

MCQ 11 What is the best definition of a collision in a hash table? A. Two entries are identical except for their keys. B. Two entries with different data have the exact same key. C. Two entries with different keys have the same exact hash value. D. Two entries with the exact same key have different hash values. 14

MCQ 12 What kind of initialization needs to be done for an open-address hash

MCQ 12 What kind of initialization needs to be done for an open-address hash table? A. None. B. The key at each array location must be initialized. C. The head pointer of each chain must be set to null. D. Both B and C must be carried out 15