What is the primary advantage of a hash table over an array?
A Order preservation
B Fixed size allocation
C Fast insertion
D Easy resizing
A hash table allows for fast insertion and retrieval of data due to its use of a hash function that maps keys directly to indices in an array. This gives it an average time complexity of O(1), unlike arrays that may require shifting elements for insertion.
Which of the following operations is not supported by a stack?
A Search
B Peek
C Push
D Pop
A stack follows the Last In First Out (LIFO) principle and supports the operations of push (add), pop (remove), and peek (view top element). Searching through the stack is not a direct operation and requires popping elements, making it inefficient.
In which data structure is data inserted and removed from opposite ends?
A Stack
B Queue
C Deque
D Priority Queue
A deque (double-ended queue) allows insertion and removal of elements from both ends, making it more flexible than regular queues or stacks, where operations are restricted to one end only.
Which sorting algorithm is considered stable?
A Quick Sort
B Merge Sort
C Selection Sort
D Heap Sort
Merge Sort is a stable sorting algorithm, meaning that elements with equal values maintain their relative order after sorting. This is crucial in scenarios where the order of equal elements matters, such as in sorting records by a secondary field.
Which tree type allows for efficient searching, insertion, and deletion with guaranteed logarithmic time complexity?
A Red-Black Tree
B AVL Tree
C Binary Search Tree
D B-Tree
A Red-Black Tree is a self-balancing binary search tree with guaranteed O(log n) time complexity for insertion, deletion, and search operations, ensuring balance through a set of color-based rules.
Which data structure is used in the implementation of recursive algorithms?
A Stack
B Queue
C Linked List
D Tree
A stack is used to store function calls in recursive algorithms. Each recursive call is pushed onto the stack, and when a function call completes, it is popped from the stack, maintaining the correct execution flow.
Which of these trees is used in database indexing systems?
A AVL Tree
B Red-Black Tree
C B-Tree
D Binary Tree
B-Trees are widely used in database indexing systems due to their ability to handle large amounts of data efficiently. They maintain sorted data and allow for fast searches, insertions, deletions, and balancing.
Which data structure is best for finding the shortest path in a weighted graph?
A Stack
B Deque
C Priority Queue
D Queue
A priority queue is used in algorithms like Dijkstra’s to find the shortest path in a weighted graph. It efficiently selects the node with the lowest path cost, supporting fast updates during the algorithm’s execution.
Which type of linked list allows traversal in both directions?
A Doubly Linked List
B Circular Linked List
C Singly Linked List
D Skip List
A doubly linked list allows traversal in both directions. Each node contains a reference to both the next and previous node, making it more flexible than a singly linked list, which only links to the next node.
Which of these operations is not associated with a binary search tree (BST)?
A Deletion
B Rotation
C Insertion
D Search
Rotations are not a typical operation in a standard binary search tree. They are used in balanced binary search trees like AVL trees and Red-Black trees to maintain balance after insertions or deletions.
What does the term “heap property” refer to?
A Balanced tree
B Nodes are ordered
C Parent is larger than children
D Heap is complete
The heap property refers to the condition that the value of each parent node is greater than or equal to the values of its children in a max-heap, or less than or equal to its children in a min-heap. This ensures efficient retrieval of the maximum or minimum element.
What is the time complexity of accessing an element in an array?
A O(1)
B O(n)
C O(n²)
D O(log n)
In an array, accessing an element by its index is done in constant time, O(1), because the array elements are stored in contiguous memory locations, allowing direct access to any element.
Which data structure is used for implementing recursion?
A Queue
B Stack
C Linked List
D Tree
Recursion in computer programming uses a stack to store function calls. Each time a function is called recursively, a new frame is pushed onto the stack, and when the function completes, the frame is popped.
Which of the following is a disadvantage of an array?
A Fixed size
B Dynamic resizing
C Efficient search
D Linked elements
Arrays have a fixed size, which means they cannot dynamically grow or shrink. This is a major limitation when the number of elements is not known in advance or changes frequently, unlike dynamic data structures like linked lists.
What is the time complexity of deleting an element from a heap?
A O(n log n)
B O(n)
C O(1)
D O(log n)
Deleting an element from a heap takes O(log n) time because after the removal, the heap must be restructured to maintain the heap property. This is done by “bubbling down” the root element to its correct position.