
MCQs on Data Structures and Algorithms
Explore multiple-choice questions (MCQs) covering topics like recursive formulas, binary trees, AVL trees, binary search trees, and more in the context of data structures and algorithms.
Uploaded on | 0 Views
Download Presentation

Please find below an Image/Link to download the presentation.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.
You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.
E N D
Presentation Transcript
COMP 352 SUMMER 2018 Tutorial Session 12 1
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)= (n2) 2
MCQ -2A 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-2B 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-2C 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 following keys into the tree in the following order: 40, 20, 15, 25, 30, 80, 75, 95, 90, 35, 100 Which key would be in the root of the tree after inserting all the keys? 75 40 35 What is the height of the above AVL tree? 3 4 5 D. 6 A. B. C. A. B. C. 6
MCQ 4 If the binary tree below is printed by a preorder traversal, what will the result be? A. 9 4 17 16 12 11 6 B. 9 17 6 4 16 22 12 C. 6 9 17 4 16 22 12 D. 6 17 22 9 4 16 12 E. 6 17 9 4 22 16 12 7
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 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 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 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 statements is true? If A is almost sorted, selection sort should be used. 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. A. B. 12
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? 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 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