WorksheetsMastering Data Structures and Algorithms
Total questions: 20
Worksheet time: 10mins
What is the time complexity of the recursive Fibonacci algorithm?
O(n)
O(log n)
O(2^n)
O(n^2)
Which of the following is a characteristic of backtracking?
It relies on dynamic programming for optimal solutions.
It incrementally builds candidates and abandons invalid ones.
It explores all possible solutions without pruning.
It solves problems using a divide-and-conquer approach.
In a binary search, what is the average time complexity?
O(log n)
O(n)
O(1)
O(n log n)
What is the worst-case time complexity of merge sort?
O(n)
O(n log n)
O(n^2)
O(log n)
Which of the following is true about heap sort?
Heap sort is a comparison-based algorithm with O(n^2) complexity.
Heap sort is stable and requires O(n log n) space complexity.
Heap sort has a time complexity of O(n log n) and is not stable.
Heap sort has a time complexity of O(n) and is stable.
What is the primary purpose of a hash table?
To ensure data is encrypted securely.
To sort data in ascending order efficiently.
To provide efficient data retrieval and storage.
To maintain a fixed size for all data entries.
In the context of recursion, what does the term 'base case' refer to?
The base case is the condition that terminates the recursion.
The base case is the part that repeats the recursion.
The base case is the main function of the recursion.
The base case is the variable that tracks recursion depth.
What is the time complexity of accessing an element in a hash table?
O(1) for all cases, O(n) in average
O(log n) for all cases
O(n) on average, O(1) in the worst case
O(1) on average, O(n) in the worst case
Which sorting algorithm is not stable?
Merge sort
Bubble sort
Insertion sort
Quick sort
What is the result of a hash collision?
A hash collision occurs when the same input generates multiple hash values.
A hash collision results in different inputs mapping to the same hash value.
A hash collision leads to identical inputs producing different hash values.
A hash collision results in a single input mapping to multiple hash values.
In a max heap, which property must be maintained?
The value of each node is equal to its children only.
The value of each node is greater than or equal to its children.
The value of each node is randomly assigned without order.
The value of each node is less than or equal to its children.
What is the time complexity of inserting an element into a binary search tree in the average case?
O(n)
O(1)
O(n log n)
O(log n)
Which of the following algorithms uses a divide-and-conquer approach?
Merge Sort
Selection Sort
Insertion Sort
Bubble Sort
What is the space complexity of the recursive implementation of quicksort?
O(n log n) on average, O(n^2) in the worst case
O(log n) on average, O(n) in the worst case
O(log n) on average, O(log n) in the worst case
O(n) on average, O(log n) in the worst case
In the context of asymptotic notation, what does O(n log n) signify?
It indicates a linear complexity of n.
It represents a quadratic complexity of n squared.
It signifies a constant time complexity.
It represents a complexity class indicating that the algorithm's performance scales with n log n.
What is the primary advantage of using a heap data structure?
Limited capacity for storing large datasets.
Slow insertion of elements into the structure.
Efficient retrieval of the maximum or minimum element.
Complexity in maintaining order during updates.
Which of the following is a valid operation in a hash table?
Inserting a key-value pair
Sorting the hash table
Removing a key-value pair
Searching for a key
What is the time complexity of deleting an element from a balanced binary search tree?
O(1)
O(n)
O(n log n)
O(log n)
In backtracking, what is the purpose of 'pruning'?
To eliminate branches of the search space that do not lead to a valid solution.
To increase the number of branches in the search space.
To find the optimal solution among all branches.
To explore all possible solutions without restrictions.
What is the average time complexity of searching in a balanced binary search tree?
O(1)
O(log n)
O(log n^2)
O(n)
