1Which algorithm design paradigm is primarily used by both Merge Sort and Quick Sort?
Merge Sort and Quick Sort
Easy
A.Divide and Conquer
B.Dynamic Programming
C.Backtracking
D.Greedy Approach
Correct Answer: Divide and Conquer
Explanation:
Both Merge Sort and Quick Sort work by dividing the problem into smaller subproblems, solving them recursively, and then combining the results, which is the core of the Divide and Conquer paradigm.
Incorrect! Try again.
2What is the worst-case time complexity of the Binary Search algorithm on a sorted array of elements?
Binary Search
Easy
A.
B.
C.
D.
Correct Answer:
Explanation:
Binary search halves the search space at each step, leading to a logarithmic worst-case time complexity of .
Incorrect! Try again.
3The Karatsuba algorithm for multiplying large integers reduces the number of recursive multiplications from 4 to what number?
Multiplication of Large Integers
Easy
A.5
B.3
C.6
D.2
Correct Answer: 3
Explanation:
Karatsuba's algorithm cleverly computes the middle term using the results of other multiplications, reducing the number of recursive multiplications from 4 to 3.
Incorrect! Try again.
4Strassen's Matrix Multiplication algorithm is faster than the standard matrix multiplication. What is its time complexity?
Strassen's Matrix Multiplication
Easy
A.
B.
C.
D.
Correct Answer:
Explanation:
Strassen's algorithm reduces the number of submatrix multiplications from 8 to 7, resulting in a time complexity of , which is approximately .
Incorrect! Try again.
5The Master Method is typically applied to recurrences of which of the following forms?
Master Method for Solving Recurrence
Easy
A.
B.
C.
D.
Correct Answer:
Explanation:
The Master Theorem provides bounds for recurrences of the form , where and .
Incorrect! Try again.
6In a recursion tree used to solve a recurrence relation, what does the value at each node represent?
Recursion-Tree Method for Solving Recurrences
Easy
A.The total number of recursive calls
B.The cost of the subproblem at that level
C.The size of the subproblem
D.The height of the tree
Correct Answer: The cost of the subproblem at that level
Explanation:
In a recursion tree, each node represents the cost of a single subproblem in the set of recursive function invocations.
Incorrect! Try again.
7What is the primary mathematical technique used to prove the guessed bounds in the Substitution Method?
Substitution Method for Solving Recurrences
Easy
A.Mathematical Induction
B.Linear Programming
C.Probability Theory
D.Integration
Correct Answer: Mathematical Induction
Explanation:
The substitution method involves guessing the form of the solution and then using mathematical induction to prove that the guess is correct.
Incorrect! Try again.
8Insertion Sort is a classic example of the Decrease and Conquer paradigm. By how much does it decrease the problem size in each step?
Decrease and Conquer: Insertion Sort
Easy
A.By a constant amount of 1
B.By a constant factor of
C.By a constant factor of 2
D.By a variable amount
Correct Answer: By a constant amount of 1
Explanation:
Insertion sort processes the array one element at a time, decreasing the remaining unsorted portion (the problem size) by exactly 1 at each step.
Incorrect! Try again.
9Which data structure is primarily used to implement Breadth-First Search (BFS)?
Depth-First Search and Breadth-First Search
Easy
A.Stack
B.Hash Table
C.Queue
D.Priority Queue
Correct Answer: Queue
Explanation:
BFS uses a Queue (FIFO data structure) to keep track of the vertices to visit next, ensuring vertices are explored level by level.
Incorrect! Try again.
10Which data structure is naturally suited for implementing Depth-First Search (DFS) iteratively?
Depth-First Search and Breadth-First Search
Easy
A.Binary Search Tree
B.Stack
C.Linked List
D.Queue
Correct Answer: Stack
Explanation:
DFS can be implemented recursively (using the call stack) or iteratively using an explicit Stack (LIFO data structure).
Incorrect! Try again.
11Topological sorting is only possible for which type of graph?
Topological Sort
Easy
A.Complete graphs
B.Undirected graphs
C.Bipartite graphs
D.Directed Acyclic Graphs (DAGs)
Correct Answer: Directed Acyclic Graphs (DAGs)
Explanation:
Topological sorting requires the graph to be directed and have no cycles (DAG), otherwise, dependencies cannot be linearly ordered.
Incorrect! Try again.
12In the context of the Transform and Conquer paradigm, what is 'presorting'?
Transform and Conquer: Presorting
Easy
A.Randomizing the input to avoid worst-case scenarios
B.Sorting the input list before solving the main problem
C.Using a sorted data structure internally
D.Sorting the output before printing
Correct Answer: Sorting the input list before solving the main problem
Explanation:
Presorting involves transforming the problem instance by sorting its input items first, which often makes solving the actual problem (like finding duplicates) much easier.
Incorrect! Try again.
13In an AVL tree, what is the maximum allowed difference in height between the left and right subtrees of any node?
Balanced Search Trees
Easy
A.1
B.0
C.
D.2
Correct Answer: 1
Explanation:
An AVL tree is a self-balancing binary search tree where the difference between heights of left and right subtrees cannot be more than 1 for all nodes.
Incorrect! Try again.
14Which of the following sorting algorithms is a non-comparison-based integer sorting algorithm?
Counting Sort
Easy
A.Counting Sort
B.Heap Sort
C.Quick Sort
D.Merge Sort
Correct Answer: Counting Sort
Explanation:
Counting sort determines the sorted order by counting the occurrences of each element, rather than comparing elements directly.
Incorrect! Try again.
15How does Radix Sort typically process the individual digits of numbers?
Radix Sort
Easy
A.From the most significant digit to the least significant digit only
B.By adding all digits together
C.By dividing digits into buckets randomly
D.From the least significant digit to the most significant digit
Correct Answer: From the least significant digit to the most significant digit
Explanation:
The standard version of Radix Sort (LSD) processes digits from the least significant digit (rightmost) to the most significant digit (leftmost) using a stable sort.
Incorrect! Try again.
16Bucket Sort works most efficiently when the input elements are:
Bucket Sort
Easy
A.Sorted in reverse order
B.All identical
C.Uniformly distributed over a range
D.Already sorted
Correct Answer: Uniformly distributed over a range
Explanation:
Bucket sort divides the interval into multiple buckets. It achieves average-case linear time complexity when the input is uniformly distributed across the range.
Incorrect! Try again.
17In a Max-Heap, what is the required relationship between a parent node and its children?
Heaps and Heapsort
Easy
A.There is no required relationship
B.The parent must be greater than or equal to its children
C.The parent must be equal to its children
D.The parent must be strictly less than its children
Correct Answer: The parent must be greater than or equal to its children
Explanation:
The Max-Heap property states that for any given node , the value of is greater than or equal to the values of its children.
Incorrect! Try again.
18What is the primary purpose of a hash function in a Hash Table?
Hashing
Easy
A.To map a key to a specific index in an array
B.To encrypt the keys
C.To compress the data size
D.To sort the data securely
Correct Answer: To map a key to a specific index in an array
Explanation:
A hash function takes a key as input and computes an integer index, which is used to store or look up a value in the hash table's underlying array.
Incorrect! Try again.
19Which sorting algorithm works by repeatedly swapping adjacent elements if they are in the wrong order?
Selection Sort and Bubble Sort
Easy
A.Selection Sort
B.Insertion Sort
C.Merge Sort
D.Bubble Sort
Correct Answer: Bubble Sort
Explanation:
Bubble Sort iterates through the array, compares adjacent elements, and swaps them if they are in the wrong order, causing the largest elements to 'bubble' to the end.
Incorrect! Try again.
20The Convex-Hull problem aims to find the smallest convex polygon that:
Closest-Pair and Convex-Hull Problems by Divide and Conquer
Easy
A.Contains only half of the given points
B.Connects any two given points
C.Contains all the given points
D.Excludes all given points
Correct Answer: Contains all the given points
Explanation:
The convex hull of a set of points is defined as the smallest convex polygon that encloses all the points in the set.
Incorrect! Try again.
21What is the time complexity of the recurrence relation using the Master Theorem?
Master Method for Solving Recurrence
Medium
A.
B.
C.
D.
Correct Answer:
Explanation:
Here, , , and . . Since , by Case 2 of the Master Theorem, .
Incorrect! Try again.
22In Quick Sort, if the partition algorithm always chooses the largest or smallest element as the pivot, what is the resulting time complexity?
Merge Sort and Quick Sort
Medium
A.
B.
C.
D.
Correct Answer:
Explanation:
Choosing the extreme element as the pivot results in highly unbalanced partitions (size 0 and ). This gives the recurrence , which evaluates to .
Incorrect! Try again.
23How many scalar multiplications are required by Strassen's algorithm to multiply two matrices, and what is its asymptotic time complexity?
Strassen's Matrix Multiplication
Medium
A.7 multiplications,
B.8 multiplications,
C.7 multiplications,
D.8 multiplications,
Correct Answer: 7 multiplications,
Explanation:
Strassen's algorithm reduces the number of multiplications for a matrix from 8 to 7. The recurrence is , yielding or .
Incorrect! Try again.
24Which of the following is the recurrence relation for the standard Binary Search algorithm?
Binary Search
Medium
A.
B.
C.
D.
Correct Answer:
Explanation:
Binary search divides the search space in half at each step and performs a constant amount of work to check the middle element. Thus, .
Incorrect! Try again.
25Karatsuba's algorithm for multiplying two -digit integers reduces the number of recursive multiplications from 4 to 3. What is its time complexity?
Multiplication of Large Integers
Medium
A.
B.
C.
D.
Correct Answer:
Explanation:
The recurrence for Karatsuba's algorithm is . By the Master Theorem, this solves to , which is approximately .
Incorrect! Try again.
26In the divide and conquer algorithm for the Closest-Pair problem, after dividing the points into two halves, what is the maximum number of points in the strip that need to be checked for a given point?
Closest-Pair and Convex-Hull Problems by Divide and Conquer
Medium
A.
B.4
C.6
D.8
Correct Answer: 6
Explanation:
Geometric properties of the strip (of width ) guarantee that at most 6 points can reside in the bounding rectangle of size without violating the assumption that the minimum distance in each half is .
Incorrect! Try again.
27Suppose we guess that for the recurrence . What is the condition on to make the inductive proof work (ignoring base cases)?
Substitution Method for Solving Recurrences
Medium
A.Any positive value of
B.
C.
D.
Correct Answer:
Explanation:
Substituting the guess into the recurrence: . For this to be , we need , which implies .
Incorrect! Try again.
28In the recursion tree for , what is the total cost at depth of the tree?
Recursion-Tree Method for Solving Recurrences
Medium
A.
B.
C.
D.
Correct Answer:
Explanation:
At depth , there are nodes. Each node processes a subproblem of size . The cost per node is . Total cost is .
Incorrect! Try again.
29Which data structure is primarily used to implement Breadth-First Search (BFS) and Depth-First Search (DFS) respectively?
Depth-First Search and Breadth-First Search
Medium
A.Priority Queue and Array
B.Queue and Stack
C.Stack and Queue
D.Linked List and Tree
Correct Answer: Queue and Stack
Explanation:
BFS explores nodes level by level, making a Queue (FIFO) suitable. DFS explores as deeply as possible before backtracking, making a Stack (LIFO) suitable.
Incorrect! Try again.
30Topological sorting can only be applied to which type of graph?
Topological Sort
Medium
A.Complete Graph
B.Directed Acyclic Graph (DAG)
C.Directed Cyclic Graph
D.Undirected Graph
Correct Answer: Directed Acyclic Graph (DAG)
Explanation:
Topological sorting orders vertices such that for every directed edge , vertex comes before . This is only possible if there are no cycles; hence, the graph must be a Directed Acyclic Graph (DAG).
Incorrect! Try again.
31In the worst-case scenario, how many comparisons are made by Insertion Sort to sort an array of elements?
Decrease and Conquer: Insertion Sort
Medium
A.
B.
C.
D.
Correct Answer:
Explanation:
In the worst case (when the array is sorted in reverse order), the -th element must be compared to all preceding elements, leading to comparisons.
Incorrect! Try again.
32What is the minimum number of comparisons required to find both the minimum and maximum of an array of elements simultaneously?
Minimum and Maximum
Medium
A.
B.
C.
D.
Correct Answer:
Explanation:
By pairing elements and comparing them first, then comparing the larger with the current max and the smaller with the current min, we process 2 elements using 3 comparisons. This results in comparisons.
Incorrect! Try again.
33Which of the following is a key limitation of the Counting Sort algorithm?
Counting Sort
Medium
A.Its time complexity is in the worst case.
B.It requires the input array to be partially sorted.
C.It requires extra space proportional to the range of input values.
D.It cannot sort integers.
Correct Answer: It requires extra space proportional to the range of input values.
Explanation:
Counting sort uses an auxiliary array of size (where is the maximum value in the input). If is significantly larger than , the algorithm becomes inefficient in terms of both space and time.
Incorrect! Try again.
34If Radix Sort uses Counting Sort as a subroutine to sort numbers having digits each, what is the overall time complexity? (Assume the base/radix is ).
Radix Sort
Medium
A.
B.
C.
D.
Correct Answer:
Explanation:
Counting sort takes time. Radix sort applies Counting sort times (once for each digit), resulting in a total time complexity of .
Incorrect! Try again.
35What is the time complexity to build a max-heap from an unsorted array of elements using the standard bottom-up build-heap approach?
Heaps and Heapsort
Medium
A.
B.
C.
D.
Correct Answer:
Explanation:
Although inserting elements one by one takes time, the bottom-up build-heap algorithm takes time because most nodes are near the leaves and require very little percolating down.
Incorrect! Try again.
36In open addressing with linear probing, the hash function is modified to . What primary issue does linear probing suffer from?
Hashing
Medium
A.Primary clustering
B.Inability to delete elements
C.Secondary clustering
D.High load factor limits
Correct Answer: Primary clustering
Explanation:
Linear probing suffers from primary clustering, where long runs of occupied slots build up, increasing the search time for subsequent insertions and lookups.
Incorrect! Try again.
37In an AVL tree, what is the maximum allowed difference in heights between the left and right subtrees of any node?
Balanced Search Trees
Medium
A.
B.2
C.0
D.1
Correct Answer: 1
Explanation:
An AVL tree is a self-balancing binary search tree where the height difference (balance factor) between the left and right subtrees of any node is at most 1.
Incorrect! Try again.
38How does presorting an array optimize the problem of checking for duplicate elements in an array?
Transform and Conquer: Presorting
Medium
A.It avoids the need to iterate through the array.
B.It allows the use of hashing.
C.It reduces the time complexity to .
D.It reduces the time complexity from to .
Correct Answer: It reduces the time complexity from to .
Explanation:
A brute-force check for duplicates takes time. By presorting the array in time, duplicates will be adjacent, allowing them to be found in a single pass. Thus, total time becomes .
Incorrect! Try again.
39Which algorithm is commonly used to find all Strongly Connected Components (SCCs) of a directed graph in time?
Connected Components
Medium
A.Dijkstra's Algorithm
B.Kosaraju's Algorithm
C.Prim's Algorithm
D.Kruskal's Algorithm
Correct Answer: Kosaraju's Algorithm
Explanation:
Kosaraju's algorithm uses two passes of DFS (one on the original graph and one on the transposed graph) to find all strongly connected components in time.
Incorrect! Try again.
40Which sorting algorithm performs the minimum number of swaps in the worst-case scenario?
Selection Sort and Bubble Sort
Medium
A.Insertion Sort
B.Bubble Sort
C.Merge Sort
D.Selection Sort
Correct Answer: Selection Sort
Explanation:
Selection sort performs exactly swaps in the worst case, as it finds the minimum element and swaps it into its correct position once per pass. Bubble and Insertion sort can perform swaps.
Incorrect! Try again.
41Consider the recurrence relation . Which case of the Master Theorem applies, and what is the tight asymptotic bound?
Master Method for Solving Recurrence
Hard
A.Case 2 applies,
B.Case 1 applies,
C.The Master Theorem does not apply directly without the extended version.
D.Case 3 applies,
Correct Answer: The Master Theorem does not apply directly without the extended version.
Explanation:
Here , , and . . . Since is larger than by a polylogarithmic factor (not polynomially larger), the standard Master Theorem fails. The extended Master Theorem gives .
Incorrect! Try again.
42In Quick Sort, suppose the partition function is modified such that it always produces a split of and of the array elements. What is the exact depth of the deepest node in the recursion tree (in terms of )?
Merge Sort and Quick Sort
Hard
A.
B.
C.
D.
Correct Answer:
Explanation:
The deepest path in the recursion tree corresponds to the largest subproblem at each step, which is of the array. The recursion terminates when , giving .
Incorrect! Try again.
43Strassen's algorithm multiplies two matrices using $7$ multiplications of matrices. If a new divide-and-conquer algorithm breaks matrices into submatrices, what is the maximum number of submatrix multiplications it can use to be asymptotically faster than Strassen's?
Strassen's Matrix Multiplication
Hard
A.22
B.27
C.21
D.26
Correct Answer: 21
Explanation:
Strassen's complexity is . For the new algorithm, the recurrence is . We need , meaning . So the maximum integer is $21$.
Incorrect! Try again.
44When solving the recurrence using the substitution method to prove , why does a direct induction hypothesis often fail for the base cases (e.g., )?
Substitution Method for Solving Recurrences
Hard
A.Because the floor function violates the monotonicity of the logarithm.
B.Because evaluates to $0$ at , which cannot bound a positive base case.
C.Because the constant must be negative.
D.Because the substitution method requires exact powers of 2.
Correct Answer: Because evaluates to $0$ at , which cannot bound a positive base case.
Explanation:
At , . Since , the base case fails. This is overcome by extending the base cases to and , or by subtracting a lower-order term in the hypothesis.
Incorrect! Try again.
45In the divide-and-conquer algorithm for the Closest-Pair problem in 2D, a strip of width is analyzed where is the minimum distance found in the left and right subsets. What is the maximum number of points in the right half of the strip that need to be compared against a given point in the left half, ensuring the distance condition is maintained?
Closest-Pair and Convex-Hull Problems by Divide and Conquer
Hard
A.8
B.7
C.6
D.4
Correct Answer: 6
Explanation:
Within the strip, each box of size can contain at most one point. A rectangle of size contains at most 8 such boxes. Since the point itself and its side are considered, geometric packing arguments guarantee that at most 6 points in the other half need to be checked.
Incorrect! Try again.
46Given a Directed Acyclic Graph (DAG) , how many unique topological sorts exist if is a set of disjoint directed paths, where the -th path has length ?
Topological Sort
Hard
A.
B.
C.
D.
Correct Answer:
Explanation:
Any topological sort of the graph must interleave the vertices of the paths such that the relative order of vertices within each path is preserved. This is an arrangement of a multiset, given by the multinomial coefficient .
Incorrect! Try again.
47In a directed graph, a DFS is performed. Which combination of edge types implies the graph has a cycle?
Depth-First Search and Breadth-First Search
Hard
A.Tree edges and Forward edges
B.Tree edges and Cross edges
C.Back edges
D.Cross edges and Forward edges
Correct Answer: Back edges
Explanation:
A directed graph contains a cycle if and only if a DFS reveals a back edge (an edge from a node to one of its ancestors in the DFS tree).
Incorrect! Try again.
48Karatsuba's algorithm for multiplying two -bit integers achieves a time complexity of . If applied to two numbers of size , what is the size of the recursive subproblems, and how many are there?
Multiplication of Large Integers
Hard
A.4 subproblems of size
B.2 subproblems of size
C.3 subproblems of size
D.3 subproblems of size
Correct Answer: 3 subproblems of size
Explanation:
Karatsuba's algorithm reduces the naive 4 multiplications of -bit numbers to 3 multiplications of -bit numbers, leading to the recurrence .
Incorrect! Try again.
49For the recurrence , what is the total cost of the nodes at depth in the recursion tree, assuming the tree is full at that depth?
Recursion-Tree Method for Solving Recurrences
Hard
A.
B.
C.
D.
Correct Answer:
Explanation:
At depth , the sum of the sizes of all subproblems is exactly , because the fractions and sum to $1$. Thus, the cost at any completely full level is .
Incorrect! Try again.
50In an AVL tree, what is the maximum number of rotations required to restore the AVL property after a single node deletion?
Balanced Search Trees
Hard
A.
B.
C.$2$
D.$1$
Correct Answer:
Explanation:
Unlike insertion, which requires at most 2 rotations to restore balance, deletion in an AVL tree can cause a cascading effect where rebalancing one node imbalances its parent, potentially requiring rotations up to the root.
Incorrect! Try again.
51Counting Sort is stable. If an array of elements has a maximum value , why is standard Counting Sort generally not used, and how can Radix Sort resolve this?
C.Counting sort is not stable for . Radix sort preserves stability.
D.Space complexity becomes . Radix sort with base reduces time and space to .
Correct Answer: Space complexity becomes . Radix sort with base reduces time and space to .
Explanation:
Counting sort takes time and space. For , this is . Using Radix sort with base , the numbers have 2 digits (since in base has at most 2 digits). Radix sort applies counting sort twice, each taking time and space.
Incorrect! Try again.
52Given an array of elements, the Floyd method to build a Max-Heap (calling max_heapify bottom-up) takes time. Why is it strictly faster asymptotically than inserting elements one by one into an initially empty heap?
Heaps and Heapsort
Hard
A.Insertion takes time on average, but worst-case is , making it .
B.Bottom-up build-heap uses fewer comparisons per level.
C.The sum of heights of all nodes in a complete binary tree is , whereas the sum of depths is .
D.Insertions require dynamically resizing the array, adding overhead.
Correct Answer: The sum of heights of all nodes in a complete binary tree is , whereas the sum of depths is .
Explanation:
Floyd's algorithm bounds the work at each node by its height. Most nodes are near the leaves and have small heights; the sum of heights is . Repeated insertions bound the work by depth. Most nodes are near the leaves and have large depths; the sum of depths is .
Incorrect! Try again.
53In a hash table using open addressing with linear probing, the table size is and there are elements. If and the step size are not coprime, what is the worst-case consequence for insertion?
Hashing
Hard
A.The probe sequence will only visit a subset of slots, potentially causing an infinite loop if those slots are full.
B.The hash function will map all keys to the same slot.
C.Primary clustering is eliminated completely.
D.The load factor will exceed 1.
Correct Answer: The probe sequence will only visit a subset of slots, potentially causing an infinite loop if those slots are full.
Explanation:
For linear probing to visit every slot in the table, the step size and the table size must be relatively prime (). Otherwise, the probe sequence cycles through distinct slots. If all are occupied, insertion fails even if the table is not full.
Incorrect! Try again.
54To find both the minimum and maximum of an array of elements simultaneously, the optimal number of comparisons is:
Minimum and Maximum
Hard
A.
B.
C.
D.
Correct Answer:
Explanation:
By pairing elements and comparing them ( comparisons), and then comparing the smaller with the running min and the larger with the running max (2 comparisons per pair), the total number of comparisons is .
Incorrect! Try again.
55When analyzing Insertion Sort, the number of shifts (or swaps) is directly proportional to which specific property of the input array?
Decrease and Conquer: Insertion Sort
Hard
A.The number of distinct elements.
B.The number of inversions.
C.The maximum element in the array.
D.The longest strictly increasing subsequence.
Correct Answer: The number of inversions.
Explanation:
An inversion is a pair of indices such that and . Each swap in insertion sort removes exactly one inversion, so the number of shifts is exactly equal to the number of inversions.
Incorrect! Try again.
56In Tarjan's strongly connected components algorithm, a node is identified as the root of an SCC if and only if:
Connected Components
Hard
A.lowlink[u] == dfn[u]
B.lowlink[u] < dfn[u]
C.It has no outgoing edges to nodes in different SCCs.
D.It is the first node visited in the DFS traversal.
Correct Answer: lowlink[u] == dfn[u]
Explanation:
In Tarjan's algorithm, dfn is the discovery time and lowlink is the lowest discovery time reachable. A node is the root (first discovered node) of an SCC if no node in its DFS subtree has a back-edge to a node discovered before it, which means lowlink[u] == dfn[u].
Incorrect! Try again.
57Given a sorted array of distinct integers , finding an index such that can be done in time using Binary Search. If the integers are not distinct, what is the worst-case time complexity?
Binary Search
Hard
A.
B.
C.
D.
Correct Answer:
Explanation:
If duplicates are allowed, the strict monotonicity that guarantees skipping half the array is broken. For example, if , knowing does not rule out the right half. Thus, in the worst case, one might have to check all elements, yielding time.
Incorrect! Try again.
58Suppose we sort strings of length over an alphabet of size using LSD (Least Significant Digit) Radix sort. If , what is the overall time complexity?
Radix Sort
Hard
A.
B.
C.
D.
Correct Answer:
Explanation:
LSD Radix Sort applies counting sort times. Each counting sort takes . Since , each pass is . Therefore, passes take time.
Incorrect! Try again.
59An algorithm determines if an array contains two elements that sum to exactly . By presorting the array in time, the search phase can be reduced to:
Transform and Conquer: Presorting
Hard
A. time using two pointers.
B. time using repeated binary searches.
C. time using hashing.
D. time using binary search.
Correct Answer: time using two pointers.
Explanation:
Once the array is sorted, we can place one pointer at the beginning and one at the end. By advancing pointers based on their sum compared to , the search phase scans the array at most once, taking time.
Incorrect! Try again.
60Consider Bubble Sort and Selection Sort applied to an array of elements. Which statement accurately compares their minimum number of element swaps in the worst-case input scenario?
In the worst case (e.g., reverse sorted array), Bubble Sort swaps adjacent elements times. Selection Sort only performs at most swaps in total, regardless of the input, making its swap complexity .