CS 114 Practice Probs

.pdf
School
New Jersey Institute Of Technology**We aren't endorsed by this school
Course
CS 114
Subject
Computer Science
Date
Dec 19, 2024
Pages
5
Uploaded by DeaconNeutronPorcupine31
Practice Multiple Choice QuestionsBinary Search, Sorting, and Searching Algorithms1.What is the key requirement for binary search to work correctly?(a) The array must be sorted.(b) The array must have distinct elements.(c) The array must have an even number of elements.(d) The array must be circular.2.What is the worst-case time complexity of linear search?(a) O(1)(b) O(n)(c) O(logn)(d) O(n^2)3.Which sorting algorithm is best suited for nearly sorted arrays?(a) Merge Sort(b) Quick Sort(c) Selection Sort(d) Insertion Sort4.Which of the following sorting algorithms has the best average case timecomplexity?(a) Bubble Sort(b) Insertion Sort(c) Merge Sort(d) Selection Sort5.What is the time complexity of Merge Sort in the worst case?(a) O(n2)(b) O(nlogn)(c) O(logn)(d) O(n)6.Which sorting algorithm does not require comparisons to sort the data?(a) Quick Sort(b) Counting Sort(c) Merge Sort(d) Heap Sort7.What is the pivot in Quick Sort?(a) The first element in the array.(b) The middle element in the array.(c) A randomly chosen element.(d) Any chosen element used to partition the array.8.What is the key operation in Heapsort?(a) Binary search on the heap.(b) Repeatedly building and maintaining a max heap.
Background image
(c) Performing merges on sorted halves.(d) Selecting the smallest element repeatedly.9.Which of the following algorithms is the most efficient for sorting integers in afixed range?(a) Merge Sort(b) Radix Sort(c) Quick Sort(d) Bubble Sort10.What type of data is Radix Sort most suitable for?(a) Strings(b) Large datasets of integers with small digit ranges(c) Floating-point numbers(d) Randomly generated dataBreadth-First Search (BFS) and Depth-First Search (DFS)11.What data structure is used in Breadth-First Search (BFS)?(a) Stack(b) Queue(c) Priority Queue(d) Linked List12.What is the primary difference between DFS and BFS?(a) BFS explores as deep as possible before backtracking.(b) DFS uses a queue, and BFS uses a stack.(c) DFS explores depth-first, and BFS explores level-by-level.(d) BFS is faster than DFS in all cases.13.Which traversal method guarantees finding the shortest path in an unweightedgraph?(a) DFS(b) BFS(c) Dijkstra's Algorithm(d) A* Algorithm14.Which of the following is true about BFS?(a) It can be used for topological sorting.(b) It uses a stack.(c) It works only for directed graphs.(d) It explores nodes level by level.15.What is the time complexity of BFS for a graph with VV vertices and EE edges?(a) O(V+E)(b) O(VlogV)(c) O(V2)(d) O(E2)
Background image
Binary Search Trees (BST)16.What is the property of a Binary Search Tree (BST)?(a) Each left child is greater than its parent.(b) Each right child is smaller than its parent.(c) The left subtree has values smaller than the root.(d) The tree is always balanced.17.What is the time complexity for searching in a balanced BST?(a) O(1)(b) O(logn)(c) O(n)(d) O(n2)18.Which traversal method gives a sorted order for a BST?(a) Preorder(b) Inorder(c) Postorder(d) Level-order19.What is the height of a perfectly balanced BST with nn nodes?(a) nn(b) logn(c) nlogn(d) n2n220.Which of the following operations does not involve restructuring the BST?(a) Search(b) Insertion(c) Deletion(d) RotationGraphs21.What is an adjacency matrix?(a) A list of vertices adjacent to each vertex.(b) A 2D array where the presence of edges is indicated.(c) A graph represented as a binary tree.(d) A set of edges connecting all nodes.22.Which graph representation is more space-efficient for sparse graphs?(a) Adjacency Matrix(b) Adjacency List(c) Edge List(d) Incidence Matrix23.What is a strongly connected component in a directed graph?
Background image
(a) A subgraph where all vertices are connected directly.(b) A subgraph where every vertex is reachable from every other vertex.(c) A graph with no cycles.(d) A subgraph with a single edge connecting all vertices.24.What algorithm is used to find the shortest path in a weighted graph withnon-negative weights?(a) BFS(b) DFS(c) Dijkstra's Algorithm(d) Kruskal's Algorithm25.What is the purpose of a Minimum Spanning Tree (MST)?(a) To find the shortest path between two nodes.(b) To minimize the total weight of edges connecting all vertices.(c) To detect cycles in a graph.(d) To partition the graph into disjoint sets.Heaps and Priority Queues26.What is the defining property of a max-heap?(a) The root is the smallest element.(b) Each parent is greater than or equal to its children.(c) Each parent is smaller than its children.(d) The heap is sorted in descending order.27.What is the time complexity for inserting an element into a heap?(a) O(1)(b) O(logn)(c) O(n)(d) O(n2)28.What is the time complexity for extracting the maximum element from amax-heap?(a) O(1)(b) O(logn)(c) O(n)(d) O(n2)29.Which data structure is often implemented using a heap?(a) Queue(b) Stack(c) Priority Queue(d) Linked List30.What is the purpose of a priority queue?(a) To always process the largest element first.(b) To process elements based on their priority.(c) To process elements in first-in, first-out order.
Background image
(d) To store data in sorted order.Solutions1.(a)2.(b)3.(d)4.(c)5.(b)6.(b)7.(d)8.(b)9.(b)10. (b)11. (b)12. (c)13. (b)14. (d)15. (a)16. (c)17. (b)18. (b)19. (b)20. (a)21. (b)22. (b)23. (b)24. (c)25. (b)26. (b)27. (b)28. (b)29. (c)30. (b)
Background image