Q. What is the time complexity of searching for an element in a balanced AVL tree?
A.
O(log n)
B.
O(n)
C.
O(n log n)
D.
O(1)
Show solution
Solution
The time complexity of searching in an AVL tree is O(log n) due to its balanced nature.
Correct Answer:
A
— O(log n)
Learn More →
Q. What is the time complexity of searching for an element in a balanced binary search tree?
A.
O(n)
B.
O(log n)
C.
O(n log n)
D.
O(1)
Show solution
Solution
In a balanced binary search tree, the time complexity for searching an element is O(log n).
Correct Answer:
B
— O(log n)
Learn More →
Q. What is the time complexity of searching for an element in a binary search tree (BST) in the worst case?
A.
O(log n)
B.
O(n)
C.
O(n log n)
D.
O(1)
Show solution
Solution
In the worst case, a binary search tree can become unbalanced, resembling a linked list, leading to a time complexity of O(n) for search operations.
Correct Answer:
B
— O(n)
Learn More →
Q. What is the time complexity of searching for an element in a binary search tree (BST) in the average case?
A.
O(1)
B.
O(log n)
C.
O(n)
D.
O(n log n)
Show solution
Solution
In a balanced binary search tree, the average time complexity for searching an element is O(log n) because each comparison allows the search to skip about half of the tree.
Correct Answer:
B
— O(log n)
Learn More →
Q. What is the time complexity of searching for an element in a hash table?
A.
O(1)
B.
O(n)
C.
O(log n)
D.
O(n log n)
Show solution
Solution
In an ideal hash table with no collisions, searching for an element can be done in constant time O(1).
Correct Answer:
A
— O(1)
Learn More →
Q. What is the time complexity of searching for an element in a queue implemented using an array?
A.
O(1)
B.
O(n)
C.
O(log n)
D.
O(n^2)
Show solution
Solution
Searching for an element in a queue implemented using an array requires checking each element, resulting in a time complexity of O(n).
Correct Answer:
B
— O(n)
Learn More →
Q. What is the time complexity of searching for an element in a Red-Black tree?
A.
O(n)
B.
O(log n)
C.
O(n log n)
D.
O(1)
Show solution
Solution
The time complexity of searching for an element in a Red-Black tree is O(log n) due to its balanced nature.
Correct Answer:
B
— O(log n)
Learn More →
Q. What is the time complexity of searching for an element in a sorted array using binary search?
A.
O(n)
B.
O(log n)
C.
O(n log n)
D.
O(1)
Show solution
Solution
The time complexity of searching for an element in a sorted array using binary search is O(log n).
Correct Answer:
B
— O(log n)
Learn More →
Q. What is the time complexity of searching for an element in a stack?
A.
O(1)
B.
O(n)
C.
O(log n)
D.
O(n^2)
Show solution
Solution
Searching for an element in a stack takes O(n) time in the worst case, as you may need to traverse all elements.
Correct Answer:
B
— O(n)
Learn More →
Q. What is the time complexity of searching for an element in an AVL tree?
A.
O(n)
B.
O(log n)
C.
O(n log n)
D.
O(1)
Show solution
Solution
The time complexity for searching in an AVL tree is O(log n) due to its balanced nature, which ensures that the height of the tree is logarithmic with respect to the number of nodes.
Correct Answer:
B
— O(log n)
Learn More →
Q. What is the time complexity of searching for an element in an unsorted array?
A.
O(1)
B.
O(n)
C.
O(log n)
D.
O(n^2)
Show solution
Solution
Searching for an element in an unsorted array requires checking each element, resulting in O(n) time complexity.
Correct Answer:
B
— O(n)
Learn More →
Q. What is the time complexity of searching for an element in an unsorted linked list?
A.
O(1)
B.
O(n)
C.
O(log n)
D.
O(n log n)
Show solution
Solution
Searching in an unsorted linked list requires traversing the list, leading to O(n) time complexity.
Correct Answer:
B
— O(n)
Learn More →
Q. What is the time complexity of sorting an array using QuickSort on average?
A.
O(n)
B.
O(n log n)
C.
O(n^2)
D.
O(log n)
Show solution
Solution
The average time complexity of QuickSort is O(n log n), making it efficient for sorting large arrays.
Correct Answer:
B
— O(n log n)
Learn More →
Q. What is the time complexity of the best-case scenario for Insertion Sort?
A.
O(n log n)
B.
O(n^2)
C.
O(n)
D.
O(log n)
Show solution
Solution
The best-case time complexity for Insertion Sort is O(n) when the array is already sorted.
Correct Answer:
C
— O(n)
Learn More →
Q. What is the time complexity of the best-case scenario for Quick Sort?
A.
O(n)
B.
O(n log n)
C.
O(n^2)
D.
O(log n)
Show solution
Solution
The best-case time complexity of Quick Sort is O(n log n) when the pivot divides the array into two equal halves.
Correct Answer:
B
— O(n log n)
Learn More →
Q. What is the time complexity of the binary search algorithm?
A.
O(n)
B.
O(log n)
C.
O(n log n)
D.
O(1)
Show solution
Solution
Binary search has a time complexity of O(log n) because it divides the search interval in half with each step.
Correct Answer:
B
— O(log n)
Learn More →
Q. What is the time complexity of the bubble sort algorithm in the worst case?
A.
O(n)
B.
O(n log n)
C.
O(n^2)
D.
O(log n)
Show solution
Solution
Bubble sort has a worst-case time complexity of O(n^2) due to the nested loops.
Correct Answer:
C
— O(n^2)
Learn More →
Q. What is the time complexity of the bubble sort algorithm?
A.
O(n)
B.
O(n log n)
C.
O(n^2)
D.
O(log n)
Show solution
Solution
Bubble sort has a worst-case time complexity of O(n^2) due to the nested loops.
Correct Answer:
C
— O(n^2)
Learn More →
Q. What is the time complexity of the depth-first search (DFS) algorithm in a graph?
A.
O(V + E)
B.
O(V)
C.
O(E)
D.
O(V^2)
Show solution
Solution
DFS also explores all vertices (V) and edges (E), resulting in a time complexity of O(V + E).
Correct Answer:
A
— O(V + E)
Learn More →
Q. What is the time complexity of the dynamic programming solution for the 0/1 Knapsack problem?
A.
O(n)
B.
O(n^2)
C.
O(n * W)
D.
O(2^n)
Show solution
Solution
The time complexity of the dynamic programming solution for the 0/1 Knapsack problem is O(n * W), where n is the number of items and W is the maximum weight capacity.
Correct Answer:
C
— O(n * W)
Learn More →
Q. What is the time complexity of the dynamic programming solution for the edit distance problem?
A.
O(n*m)
B.
O(n^2)
C.
O(n log n)
D.
O(2^n)
Show solution
Solution
The time complexity of the dynamic programming solution for the edit distance problem is O(n*m), where n and m are the lengths of the two strings.
Correct Answer:
A
— O(n*m)
Learn More →
Q. What is the time complexity of the dynamic programming solution for the Fibonacci sequence?
A.
O(n)
B.
O(n^2)
C.
O(2^n)
D.
O(log n)
Show solution
Solution
The time complexity of the dynamic programming solution for the Fibonacci sequence is O(n) because it computes each Fibonacci number only once and stores the results.
Correct Answer:
A
— O(n)
Learn More →
Q. What is the time complexity of the Fibonacci sequence using dynamic programming?
A.
O(2^n)
B.
O(n)
C.
O(n log n)
D.
O(n^2)
Show solution
Solution
Using dynamic programming, the Fibonacci sequence can be computed in O(n) time by storing previously computed values.
Correct Answer:
B
— O(n)
Learn More →
Q. What is the time complexity of the inorder traversal of a binary tree?
A.
O(n)
B.
O(log n)
C.
O(n log n)
D.
O(1)
Show solution
Solution
Inorder traversal visits each node exactly once, resulting in a time complexity of O(n), where n is the number of nodes in the tree.
Correct Answer:
A
— O(n)
Learn More →
Q. What is the time complexity of the K-means algorithm?
A.
O(n^2)
B.
O(nk)
C.
O(n log n)
D.
O(n^3)
Show solution
Solution
The time complexity of the K-means algorithm is O(nk), where n is the number of data points and k is the number of clusters.
Correct Answer:
B
— O(nk)
Learn More →
Q. What is the time complexity of the longest common subsequence problem using dynamic programming?
A.
O(n)
B.
O(m)
C.
O(n*m)
D.
O(n^2)
Show solution
Solution
The longest common subsequence problem can be solved using a dynamic programming approach with a time complexity of O(n*m), where n and m are the lengths of the two sequences.
Correct Answer:
C
— O(n*m)
Learn More →
Q. What is the time complexity of the longest increasing subsequence problem using dynamic programming?
A.
O(n)
B.
O(n log n)
C.
O(n^2)
D.
O(2^n)
Show solution
Solution
The longest increasing subsequence can be solved using dynamic programming in O(n^2) time complexity.
Correct Answer:
C
— O(n^2)
Learn More →
Q. What is the time complexity of the Merge operation in Merge Sort?
A.
O(n)
B.
O(log n)
C.
O(n log n)
D.
O(1)
Show solution
Solution
The time complexity of the Merge operation in Merge Sort is O(n) as it combines two sorted arrays.
Correct Answer:
A
— O(n)
Learn More →
Q. What is the time complexity of the partitioning step in Quick Sort?
A.
O(n)
B.
O(n log n)
C.
O(log n)
D.
O(n^2)
Show solution
Solution
The partitioning step in Quick Sort has a time complexity of O(n) as it involves a single pass through the array.
Correct Answer:
A
— O(n)
Learn More →
Q. What is the time complexity of the quicksort algorithm in the average case?
A.
O(n)
B.
O(n log n)
C.
O(n^2)
D.
O(log n)
Show solution
Solution
The average case time complexity of quicksort is O(n log n) due to the divide and conquer approach.
Correct Answer:
B
— O(n log n)
Learn More →
Showing 1921 to 1950 of 3237 (108 Pages)