Test your understanding of core data structures like arrays, linked lists, stacks, queues, and hash tables. This quiz covers basic operations, characteristics, and real-world applications to help reinforce key data structure concepts.
Which data structure allows direct access to its elements using a numerical index, such as retrieving the third item using array[2]?
Explanation: Arrays store elements in contiguous memory locations, enabling direct access via indices. Stacks and queues require removing elements in a specific order and do not allow random access. Hash tables use keys instead of numerical indices for access, so array is the correct choice.
In which data structure is the last element added always the first to be removed, following the LIFO principle?
Explanation: A stack operates in a Last-In First-Out (LIFO) manner, meaning the most recently added item is the first to be taken out. Queues use FIFO (First-In First-Out), while linked lists do not enforce this strict removal order. Heap refers to a specific tree-based structure used for prioritization.
Which data structure is most suitable for processing data in the exact order it was received, like customers waiting in line?
Explanation: A queue follows a First-In First-Out (FIFO) discipline, where the first element added is the first to be removed, just like a line of customers. Hash tables don't maintain order and are used for key-value lookups. Arrays do not guarantee removal order, and trees arrange elements hierarchically.
In a singly linked list, what type of link does each node typically contain?
Explanation: Each node in a singly linked list contains data and a pointer to the next node, enabling forward traversal. Doubly linked lists would require pointers to both next and previous nodes. Pointers to random nodes are not standard, and linking only to the first node is incorrect.
If you need to quickly find an element based on a unique key, which basic data structure is most suited for this purpose?
Explanation: Hash tables are optimized for fast lookups using keys, making data retrieval efficient. Stacks and queues access elements based on insertion/removal order, not keys. Arrays require searching through elements unless the index is known, which is less efficient than hash table lookup.
Which two primary operations are associated with stack data structures?
Explanation: Stacks support 'push' to add and 'pop' to remove the topmost item. Enqueue and dequeue are queue operations. Peek is checking the top item without removal, and rear is not a standard stack term. Insert and RemoveLast can apply to other data structures but are not stack-specific.
If you enqueue 'apple', 'banana', and 'cherry' into a queue, which item is removed first on dequeue?
Explanation: 'Apple' is enqueued first and will be at the front, making it the first item to be dequeued under FIFO rules. 'Cherry' and 'banana' are behind apple in the queue. The queue is not empty, so that option is incorrect.
What major limitation does a typical static array have compared to a linked list?
Explanation: Static arrays are declared with a fixed size that cannot be changed during runtime, unlike linked lists which can grow or shrink dynamically. Arrays have random access, while linked lists do not. Key-value storage is for hash tables, and hierarchical traversal is related to trees.
Which advantage do linked lists have over arrays when inserting elements in the middle of the structure?
Explanation: Linked lists enable efficient insertion and deletion from anywhere in the structure without shifting other elements. Arrays allow direct access by index but require shifting elements for insertion. Linked lists typically use more memory for pointers, not less, and searching is generally slower.
What term describes the event when two different keys produce the same index in a hash table?
Explanation: A collision occurs in a hash table when distinct keys hash to the same index. Overflow is a different concept, usually in memory or stacks. Stacking and crosslink are not standard data structure terms in this context.
Which of these is an everyday application of a stack data structure?
Explanation: Undo functionality uses a stack to store previous states, popping the most recent change when undo is pressed. Phone queues use queues, not stacks. Runway scheduling and finding the minimum involve other algorithms or data structures.
What is the main benefit of using a circular queue over a standard linear queue?
Explanation: Circular queues reuse freed-up spaces as the front and rear pointers wrap around, optimizing storage. They don't provide faster random access or key-value storage. Allowing hierarchy is a characteristic of tree structures, not queues.
Under ideal conditions, what is the average-case time complexity for searching an element in a hash table?
Explanation: Hash tables achieve O(1) time for search on average due to direct indexing by hashing. O(n) would occur in worst-case collision scenarios; O(log n) and O(n log n) are not typical for hash tables but may apply to trees or sorting algorithms instead.
How are the elements in a singly linked list commonly connected to each other?
Explanation: In a singly linked list, every node contains a reference or pointer to the next node, forming a chain. Pointing to two children is a binary tree property. Sharing the same parent or pointing at random are not characteristics of linked lists.
Standing in line to buy movie tickets is an example of which data structure in everyday life?
Explanation: Waiting lines are modeled as queues, since the first person to join is the first to be served. Stacks remove the most recent entry, which doesn't represent queue behavior. Trees offer hierarchies, and hash tables are for key-based access.
When accessing the fifth element in a typical array, what is the time complexity?
Explanation: Array elements can be accessed instantly through their indices, resulting in constant time, or O(1) complexity. O(n) would apply to searching or accessing in a linked list. O(log n) and O(n^2) are not relevant for direct array access.