Which of the following is a feature of a stack data structure?
A LIFO
B FIFO
C Random access
D Fixed size
A stack operates on a Last In, First Out (LIFO) principle, meaning the last element added is the first one to be removed. It is commonly used for recursion, backtracking algorithms, and expression evaluation.
Which of the following is a primary advantage of using a doubly linked list over a singly linked list?
A More memory efficient
B Faster traversal
C Allows two way traversal
D Fixed size
A doubly linked list allows traversal in both directions (from head to tail and tail to head) because each node has two pointers: one to the next node and one to the previous node, providing more flexibility than a singly linked list.
What is the main disadvantage of using an array for dynamic data storage?
A Fixed size
B Slow access time
C Inefficient searching
D No direct access
Arrays have a fixed size, which makes them inefficient for dynamic datasets. If the array runs out of space, it requires resizing, which involves creating a new array and copying all elements, leading to overhead.
Which data structure is most efficient for implementing a priority queue?
A Stack
B Queue
C Binary Heap
D Array
A Binary Heap is the most efficient data structure for implementing a priority queue, as it allows inserting and removing the highest (or lowest) priority element in O(log n) time, making it ideal for scheduling tasks or managing events.
What is the time complexity of searching for an element in a balanced binary search tree (BST)?
A O(log n)
B O(n)
C O(1)
D O(n log n)
In a balanced binary search tree (e.g., AVL or Red Black Tree), the search operation has a time complexity of O(log n), as the tree is balanced and the height is logarithmic with respect to the number of nodes.
Which of the following is a key feature of a Red Black Tree?
A It is a complete binary tree
B It is always perfectly balanced
C It maintains a set of color rules to ensure balance
D It allows only left rotations
A Red Black Tree is a self balancing binary search tree where each node has a color (either red or black). The tree maintains balance through a set of color based rules that ensure logarithmic time complexity for search, insert, and delete operations.
Which of the following is the primary use of a hash table?
A Sorting data
B Searching for elements
C Representing graphs
D Storing ordered data
A hash table is primarily used for efficient searching and retrieval of elements. It uses a hash function to map keys to array indices, allowing for O(1) average time complexity for search, insert, and delete operations.
Which of the following is true about a graph traversal using Depth First Search (DFS)?
A It uses a queue
B It explores all neighbors before moving to the next level
C It explores as deep as possible before backtracking
D It always finds the shortest path
Depth First Search (DFS) explores a graph by starting from the root (or an arbitrary node) and going as deep as possible along each branch before backtracking. It uses a stack for managing the traversal path.
Which of the following operations does a circular queue allow?
A Only insertion at the front
B Only insertion at the rear
C Insertion and deletion at both ends
D Insertion and deletion at one end
In a circular queue, both insertion and deletion occur at one end: insertion at the rear and deletion at the front. This allows efficient use of space in a fixed size queue by reusing empty slots as elements are removed.
Which of the following is a characteristic of a Binary Search Tree (BST)?
A Left child is smaller than the parent node
B Right child is larger than the parent node
C Both A and B
D Parent node can be larger than both children
In a Binary Search Tree, the left child is smaller than the parent node, and the right child is larger. This property ensures that the tree remains ordered, enabling efficient search, insertion, and deletion operations.
What is the time complexity of accessing an element in an array by index?
A O(1)
B O(log n)
C O(n)
D O(n²)
Accessing an element in an array by index is a constant time operation, O(1), because the elements are stored in contiguous memory locations, allowing direct access using the index.
Which of the following algorithms is used to find the shortest path in a weighted graph?
A Dijkstra’s Algorithm
B BFS
C Merge Sort
D Quick Sort
Dijkstra’s Algorithm is used to find the shortest path in a weighted graph with non negative edge weights. It works by progressively selecting the closest unvisited node and updating its neighbors’ distances, ensuring the shortest path is found.
What is the primary disadvantage of a linked list compared to an array?
A Larger memory overhead
B Slower access time
C Requires dynamic memory allocation
D Cannot be resized
Linked lists have slower access times than arrays because elements are not stored contiguously in memory. To access an element, the list must be traversed from the head, leading to O(n) time complexity for search operations.
Which data structure is commonly used to implement undo operations in applications?
A Queue
B Stack
C Linked List
D Tree
Stacks are ideal for implementing undo operations in applications. Each action is pushed onto the stack, and when an undo is requested, the most recent action is popped from the stack, restoring the previous state.
Which of the following sorting algorithms is the most efficient in the average case?
A Selection Sort
B Merge Sort
C Bubble Sort
D Quick Sort
Quick Sort has an average case time complexity of O(n log n), making it one of the most efficient sorting algorithms for large datasets. It uses a divide and conquer strategy to partition the array and recursively sort the subarrays.