Basic Data Structures Flashcards
7 cards from real AMCAT practice questions. Tap to flip, then mark Knew It or Still Learning โ missed cards come back until you master them.
Read the first 7 Basic Data Structures flashcards as text
What is the time complexity to access an element in an array by its index?
Answer: O(1)
Arrays provide direct, random access to elements using their index. The memory location is calculated directly from the base address and the index, which is a constant-time operation regardless of the array's size.
Which data structure follows the Last-In, First-Out (LIFO) principle?
Answer: Stack
A stack operates like a pile of plates. The last item added (pushed) is the first one to be removed (popped), which defines the LIFO principle.
In a standard queue, where are new elements added?
Answer: At the rear
A queue follows the First-In, First-Out (FIFO) principle. New elements are enqueued at the rear (or tail) and existing elements are dequeued from the front (or head).
What is a potential issue with implementing a queue using a simple, fixed-size array?
Answer: The queue has a fixed size and can become full.
When a queue is implemented with a standard array, it has a predefined, fixed capacity. If the number of elements to be enqueued exceeds this capacity, an overflow condition occurs, and no more elements can be added.
The operation of removing an element from a stack is called:
Answer: Pop
'Push' is the term for adding an element to a stack. 'Pop' is the term for removing the topmost element from the stack, following the LIFO principle.
A circular queue is an improvement over a linear queue because it:
Answer: Utilizes the empty space in the array more efficiently.
In a linear queue implemented with an array, space at the beginning of the array becomes unusable after elements are dequeued. A circular queue overcomes this by wrapping around, allowing the rear to point to the start of the array if space is available, thus using memory more effectively.
If the elements 'A', 'B', 'C', and 'D' are placed in a stack in that order, what will be the order of elements when they are popped?
Answer: D, C, B, A
Due to the LIFO (Last-In, First-Out) nature of a stack, the last element pushed ('D') will be the first one popped. The sequence of popping will be the exact reverse of the pushing sequence.