Q. What is the time complexity of enqueuing an element in a queue implemented with a linked list?
A.
O(1)
B.
O(n)
C.
O(log n)
D.
O(n^2)
Show solution
Solution
Enqueuing an element in a queue implemented with a linked list can be done in constant time, O(1), by adding the element to the end of the list.
Correct Answer:
A
— O(1)
Learn More →
Q. What is the time complexity of finding the height of a binary tree?
A.
O(n)
B.
O(log n)
C.
O(n log n)
D.
O(1)
Show solution
Solution
The height of a binary tree can be found by traversing all its nodes, which takes O(n) time.
Correct Answer:
A
— O(n)
Learn More →
Q. What is the time complexity of finding the maximum element in a binary heap?
A.
O(1)
B.
O(log n)
C.
O(n)
D.
O(n log n)
Show solution
Solution
Finding the maximum element in a binary max-heap can be done in constant time, hence O(1).
Correct Answer:
A
— O(1)
Learn More →
Q. What is the time complexity of finding the maximum element in a binary search tree?
A.
O(1)
B.
O(log n)
C.
O(n)
D.
O(n log n)
Show solution
Solution
Finding the maximum element in a binary search tree involves traversing to the rightmost node, which takes O(log n) time in a balanced tree.
Correct Answer:
B
— O(log n)
Learn More →
Q. What is the time complexity of finding the maximum element in a binary search tree (BST)?
A.
O(1)
B.
O(log n)
C.
O(n)
D.
O(n log n)
Show solution
Solution
In a balanced BST, finding the maximum element involves traversing down the rightmost path, which takes O(log n) time.
Correct Answer:
B
— O(log n)
Learn More →
Q. What is the time complexity of finding the maximum element in a linked list?
A.
O(1)
B.
O(n)
C.
O(log n)
D.
O(n^2)
Show solution
Solution
Finding the maximum element in a linked list requires traversing all elements, resulting in O(n) time complexity.
Correct Answer:
B
— O(n)
Learn More →
Q. What is the time complexity of finding the maximum element in an unsorted array?
A.
O(n)
B.
O(log n)
C.
O(n log n)
D.
O(1)
Show solution
Solution
To find the maximum element in an unsorted array, you must check each element, resulting in O(n) time complexity.
Correct Answer:
A
— O(n)
Learn More →
Q. What is the time complexity of finding the minimum element in a stack that supports this operation?
A.
O(1)
B.
O(n)
C.
O(log n)
D.
O(n^2)
Show solution
Solution
Finding the minimum element in a stack that supports this operation can be done in constant time, O(1), if a secondary stack is used to track minimums.
Correct Answer:
A
— O(1)
Learn More →
Q. What is the time complexity of finding the shortest path in an unweighted graph using BFS?
A.
O(n)
B.
O(n^2)
C.
O(m + n)
D.
O(log n)
Show solution
Solution
Breadth-first search (BFS) explores all vertices and edges, resulting in a time complexity of O(m + n), where m is the number of edges and n is the number of vertices.
Correct Answer:
C
— O(m + n)
Learn More →
Q. What is the time complexity of Heap Sort in the worst case?
A.
O(n)
B.
O(n log n)
C.
O(n^2)
D.
O(log n)
Show solution
Solution
The worst-case time complexity of Heap Sort is O(n log n) due to the heap construction and sorting process.
Correct Answer:
B
— O(n log n)
Learn More →
Q. What is the time complexity of implementing a queue using two stacks?
A.
O(1) for enqueue, O(n) for dequeue
B.
O(n) for enqueue, O(1) for dequeue
C.
O(n) for both
D.
O(1) for both
Show solution
Solution
Implementing a queue using two stacks allows O(1) time for enqueue and O(n) time for dequeue, as elements may need to be transferred between stacks.
Correct Answer:
A
— O(1) for enqueue, O(n) for dequeue
Learn More →
Q. What is the time complexity of in-order traversal of a binary tree?
A.
O(n)
B.
O(log n)
C.
O(n log n)
D.
O(1)
Show solution
Solution
The time complexity of in-order traversal of a binary tree is O(n), as it visits each node exactly once.
Correct Answer:
A
— O(n)
Learn More →
Q. What is the time complexity of inserting a node 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 inserting a node is O(log n).
Correct Answer:
B
— O(log n)
Learn More →
Q. What is the time complexity of inserting a node in a binary search tree in the average case?
A.
O(n)
B.
O(log n)
C.
O(n log n)
D.
O(1)
Show solution
Solution
The average case time complexity for inserting a node in a binary search tree is O(log n).
Correct Answer:
B
— O(log n)
Learn More →
Q. What is the time complexity of inserting a node in an AVL tree?
A.
O(1)
B.
O(log n)
C.
O(n)
D.
O(n log n)
Show solution
Solution
The time complexity of inserting a node in an AVL tree is O(log n) due to the need for rebalancing.
Correct Answer:
B
— O(log n)
Learn More →
Q. What is the time complexity of inserting an element at a specific index in an array?
A.
O(1)
B.
O(n)
C.
O(log n)
D.
O(n^2)
Show solution
Solution
Inserting an element at a specific index in an array requires shifting elements, which takes O(n) time in the worst case.
Correct Answer:
B
— O(n)
Learn More →
Q. What is the time complexity of inserting an element at the beginning of a linked list?
A.
O(1)
B.
O(n)
C.
O(log n)
D.
O(n log n)
Show solution
Solution
Inserting an element at the beginning of a linked list is done in constant time, O(1).
Correct Answer:
A
— O(1)
Learn More →
Q. What is the time complexity of inserting an element at the beginning of a singly linked list?
A.
O(1)
B.
O(n)
C.
O(log n)
D.
O(n log n)
Show solution
Solution
Inserting an element at the beginning of a singly linked list takes constant time, hence O(1).
Correct Answer:
A
— O(1)
Learn More →
Q. What is the time complexity of inserting an element at the end of a dynamic array?
A.
O(1)
B.
O(n)
C.
O(log n)
D.
O(n^2)
Show solution
Solution
Inserting at the end of a dynamic array is O(1) on average, but can be O(n) if resizing is needed.
Correct Answer:
A
— O(1)
Learn More →
Q. What is the time complexity of inserting an element at the end of a linked list?
A.
O(1)
B.
O(n)
C.
O(log n)
D.
O(n^2)
Show solution
Solution
Inserting at the end of a linked list requires traversing to the last node, which takes O(n) time.
Correct Answer:
B
— O(n)
Learn More →
Q. What is the time complexity of inserting an element at the end of a singly linked list?
A.
O(1)
B.
O(n)
C.
O(log n)
D.
O(n^2)
Show solution
Solution
Inserting an element at the end of a singly linked list requires O(n) time if the tail pointer is not maintained.
Correct Answer:
B
— O(n)
Learn More →
Q. What is the time complexity of inserting an element in a balanced binary search tree?
A.
O(1)
B.
O(log n)
C.
O(n)
D.
O(n log n)
Show solution
Solution
Inserting an element in a balanced binary search tree has a time complexity of O(log n) due to the tree's balanced nature.
Correct Answer:
B
— O(log n)
Learn More →
Q. What is the time complexity of inserting an element in a binary search tree in the average case?
A.
O(log n)
B.
O(n)
C.
O(n log n)
D.
O(1)
Show solution
Solution
In the average case, inserting an element in a binary search tree takes O(log n) time.
Correct Answer:
A
— O(log n)
Learn More →
Q. What is the time complexity of inserting an element in an AVL tree?
A.
O(n)
B.
O(log n)
C.
O(n log n)
D.
O(1)
Show solution
Solution
Inserting an element in an AVL tree takes O(log n) time due to the tree's balanced nature.
Correct Answer:
B
— O(log n)
Learn More →
Q. What is the time complexity of inserting an element into 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
Inserting an element into a binary search tree (BST) has an average-case time complexity of O(log n).
Correct Answer:
B
— O(log n)
Learn More →
Q. What is the time complexity of inserting an element into a binary search tree in the average case?
A.
O(n)
B.
O(log n)
C.
O(n log n)
D.
O(1)
Show solution
Solution
In the average case, inserting an element into a binary search tree takes O(log n) time, assuming the tree is balanced.
Correct Answer:
B
— O(log n)
Learn More →
Q. What is the time complexity of inserting an element into a max-heap?
A.
O(1)
B.
O(log n)
C.
O(n)
D.
O(n log n)
Show solution
Solution
Inserting an element into a max-heap requires maintaining the heap property, which takes O(log n) time.
Correct Answer:
B
— O(log n)
Learn More →
Q. What is the time complexity of inserting an element into a priority queue implemented with a binary heap?
A.
O(1)
B.
O(log n)
C.
O(n)
D.
O(n log n)
Show solution
Solution
Inserting an element into a binary heap takes O(log n) time due to the need to maintain the heap property.
Correct Answer:
B
— O(log n)
Learn More →
Q. What is the time complexity of inserting an element into a Red-Black tree?
A.
O(log n)
B.
O(n)
C.
O(n log n)
D.
O(1)
Show solution
Solution
The time complexity of inserting an element into a Red-Black 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 inserting an element into a stack implemented using an array?
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) implemented using an array takes constant time, O(1).
Correct Answer:
A
— O(1)
Learn More →
Showing 1861 to 1890 of 3237 (108 Pages)