Q. What is the time complexity of inserting an element into a stack?
A.
O(1)
B.
O(n)
C.
O(log n)
D.
O(n log n)
Show solution
Solution
Inserting an element into a stack (push operation) is done in constant time, hence O(1).
Correct Answer:
A
— O(1)
Learn More →
Q. What is the time complexity of inserting an element into an AVL tree?
A.
O(n)
B.
O(log n)
C.
O(n log n)
D.
O(1)
Show solution
Solution
Inserting an element into an AVL tree takes O(log n) time due to the need to maintain balance after insertion.
Correct Answer:
B
— O(log n)
Learn More →
Q. What is the time complexity of level-order traversal of a binary tree?
A.
O(n)
B.
O(log n)
C.
O(n log n)
D.
O(1)
Show solution
Solution
Level-order traversal visits each node once, resulting in a time complexity of O(n).
Correct Answer:
A
— O(n)
Learn More →
Q. What is the time complexity of linear search in an array?
A.
O(1)
B.
O(n)
C.
O(log n)
D.
O(n^2)
Show solution
Solution
Linear search checks each element one by one, resulting in a time complexity of O(n).
Correct Answer:
B
— O(n)
Learn More →
Q. What is the time complexity of linear search in an unsorted array?
A.
O(log n)
B.
O(n)
C.
O(n log n)
D.
O(1)
Show solution
Solution
Linear search checks each element one by one, resulting in a time complexity of O(n).
Correct Answer:
B
— O(n)
Learn More →
Q. What is the time complexity of merge sort?
A.
O(n)
B.
O(n log n)
C.
O(n^2)
D.
O(log n)
Show solution
Solution
Merge sort divides the array and merges sorted halves, resulting in a time complexity of O(n log n).
Correct Answer:
B
— O(n log n)
Learn More →
Q. What is the time complexity of merging two binary trees?
A.
O(n)
B.
O(log n)
C.
O(n log n)
D.
O(1)
Show solution
Solution
Merging two binary trees involves visiting each node, resulting in a time complexity of O(n), where n is the total number of nodes in both trees.
Correct Answer:
A
— O(n)
Learn More →
Q. What is the time complexity of merging two sorted arrays of sizes m and n?
A.
O(m + n)
B.
O(m * n)
C.
O(log(m + n))
D.
O(n)
Show solution
Solution
Merging two sorted arrays takes linear time, O(m + n), as we traverse both arrays.
Correct Answer:
A
— O(m + n)
Learn More →
Q. What is the time complexity of merging two sorted arrays?
A.
O(n)
B.
O(n log n)
C.
O(log n)
D.
O(n^2)
Show solution
Solution
Merging two sorted arrays can be done in linear time, O(n), where n is the total number of elements in both arrays.
Correct Answer:
A
— O(n)
Learn More →
Q. What is the time complexity of merging two sorted binary trees?
A.
O(n)
B.
O(n log n)
C.
O(log n)
D.
O(1)
Show solution
Solution
Merging two sorted binary trees involves visiting each node, resulting in a time complexity of O(n), where n is the total number of nodes.
Correct Answer:
A
— O(n)
Learn More →
Q. What is the time complexity of merging two sorted linked lists?
A.
O(n)
B.
O(n log n)
C.
O(log n)
D.
O(n^2)
Show solution
Solution
Merging two sorted linked lists can be done in linear time, O(n), where n is the total number of elements in both lists.
Correct Answer:
A
— O(n)
Learn More →
Q. What is the time complexity of performing a binary search on a sorted array?
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 repeatedly divides the search interval in half.
Correct Answer:
B
— O(log n)
Learn More →
Q. What is the time complexity of performing a breadth-first search (BFS) on a graph?
A.
O(V)
B.
O(E)
C.
O(V + E)
D.
O(V * E)
Show solution
Solution
The time complexity of performing a breadth-first search (BFS) on a graph is O(V + E), where V is the number of vertices and E is the number of edges.
Correct Answer:
C
— O(V + E)
Learn More →
Q. What is the time complexity of performing a level-order traversal on a Red-Black Tree?
A.
O(n)
B.
O(log n)
C.
O(n log n)
D.
O(1)
Show solution
Solution
A level-order traversal of a Red-Black Tree visits each node once, resulting in a time complexity of O(n).
Correct Answer:
A
— O(n)
Learn More →
Q. What is the time complexity of popping an element from a queue implemented using a linked list?
A.
O(1)
B.
O(n)
C.
O(log n)
D.
O(n^2)
Show solution
Solution
Popping an element from a queue implemented using a linked list can be done in constant time, O(1), if we maintain a pointer to the front of the queue.
Correct Answer:
A
— O(1)
Learn More →
Q. What is the time complexity of popping an element from a stack?
A.
O(1)
B.
O(n)
C.
O(log n)
D.
O(n^2)
Show solution
Solution
Popping an element from a stack is also done in constant time, O(1), as it involves removing the top element.
Correct Answer:
A
— O(1)
Learn More →
Q. What is the time complexity of post-order traversal of a binary tree?
A.
O(n)
B.
O(log n)
C.
O(n log n)
D.
O(1)
Show solution
Solution
Post-order 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 Prim's algorithm for finding the minimum spanning tree using an adjacency matrix?
A.
O(V^2)
B.
O(E log V)
C.
O(V + E)
D.
O(V^3)
Show solution
Solution
Prim's algorithm has a time complexity of O(V^2) when using an adjacency matrix.
Correct Answer:
A
— O(V^2)
Learn More →
Q. What is the time complexity of pushing an element onto a stack implemented using a linked list?
A.
O(1)
B.
O(n)
C.
O(log n)
D.
O(n^2)
Show solution
Solution
Pushing an element onto a stack implemented using a linked list takes constant time, O(1), because it involves adding a new node at the head of the list.
Correct Answer:
A
— O(1)
Learn More →
Q. What is the time complexity of pushing an element onto a stack?
A.
O(1)
B.
O(n)
C.
O(log n)
D.
O(n^2)
Show solution
Solution
Pushing an element onto a stack is done in constant time, hence O(1).
Correct Answer:
A
— O(1)
Learn More →
Q. What is the time complexity of quicksort in the average case?
A.
O(n)
B.
O(n log n)
C.
O(n^2)
D.
O(log n)
Show solution
Solution
Quicksort has an average-case time complexity of O(n log n) due to the divide-and-conquer approach.
Correct Answer:
B
— O(n log n)
Learn More →
Q. What is the time complexity of quicksort in the best case?
A.
O(n)
B.
O(n log n)
C.
O(n^2)
D.
O(log n)
Show solution
Solution
In the best case, quicksort divides the array into two equal halves, leading to a time complexity of O(n log n).
Correct Answer:
B
— O(n log n)
Learn More →
Q. What is the time complexity of removing an element from a queue?
A.
O(1)
B.
O(n)
C.
O(log n)
D.
O(n log n)
Show solution
Solution
Removing an element from a queue is O(1) because it involves removing the front element.
Correct Answer:
A
— O(1)
Learn More →
Q. What is the time complexity of reversing a linked list?
A.
O(1)
B.
O(n)
C.
O(log n)
D.
O(n^2)
Show solution
Solution
Reversing a linked list requires visiting each node once, resulting in O(n) time complexity.
Correct Answer:
B
— O(n)
Learn More →
Q. What is the time complexity of reversing a queue using a stack?
A.
O(n)
B.
O(n log n)
C.
O(n^2)
D.
O(1)
Show solution
Solution
Reversing a queue using a stack involves transferring all elements to the stack and then back to the queue, resulting in a time complexity of O(n).
Correct Answer:
A
— O(n)
Learn More →
Q. What is the time complexity of reversing a stack using another stack?
A.
O(n)
B.
O(n log n)
C.
O(n^2)
D.
O(1)
Show solution
Solution
Reversing a stack using another stack takes O(n) time, as each element is pushed and popped once.
Correct Answer:
A
— O(n)
Learn More →
Q. What is the time complexity of reversing a stack using recursion?
A.
O(n)
B.
O(n log n)
C.
O(n^2)
D.
O(1)
Show solution
Solution
Reversing a stack using recursion has a time complexity of O(n) as each element is processed once.
Correct Answer:
A
— O(n)
Learn More →
Q. What is the time complexity of searching for a value in a balanced binary search 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 a value in a balanced binary search tree is O(log n).
Correct Answer:
B
— O(log n)
Learn More →
Q. What is the time complexity of searching for a value in a binary search tree (BST) with n nodes?
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 average time complexity for searching is O(log n), but in the worst case (unbalanced), it can be O(n).
Correct Answer:
B
— O(log n)
Learn More →
Q. What is the time complexity of searching for a value in a Red-Black tree?
A.
O(n)
B.
O(log n)
C.
O(n log n)
D.
O(1)
Show solution
Solution
Searching for a value in a Red-Black tree takes O(log n) time due to its balanced structure.
Correct Answer:
B
— O(log n)
Learn More →
Showing 1891 to 1920 of 3237 (108 Pages)