CCP CCP Data Structures & Abstract Data Types 1 ā Questions and Answers
Question 1: Which data structure uses a LIFO (Last In, First Out) access pattern?
- Queue
- Stack (Correct answer)
- Linked List
- Binary Tree
Correct answer: Stack
A stack follows LIFO order, meaning the last element pushed is the first one popped.
Question 2: In a singly linked list, each node contains data and a pointer to which node?
- The previous node
- The head node
- The next node (Correct answer)
- The tail node
Correct answer: The next node
In a singly linked list, each node holds a reference (pointer) to the next node in the sequence.
Question 3: What is the time complexity of accessing an element by index in an array?
- O(n)
- O(log n)
- O(1) (Correct answer)
- O(n²)
Correct answer: O(1)
Arrays provide O(1) random access because elements are stored at contiguous memory addresses.
Question 4: Which abstract data type operates on a FIFO (First In, First Out) principle?
- Stack
- Queue (Correct answer)
- Heap
- Graph
Correct answer: Queue
A queue processes elements in FIFO order ā the first element enqueued is the first dequeued.
Question 5: A doubly linked list differs from a singly linked list in that each node has pointers to:
- Two next nodes
- Both the next and previous nodes (Correct answer)
- The head and tail only
- Every other node
Correct answer: Both the next and previous nodes
A doubly linked list maintains both a next and a previous pointer in each node, enabling bidirectional traversal.
Question 6: Which data structure is most appropriate for implementing an undo feature in a text editor?
- Queue
- Stack (Correct answer)
- Array
- Hash Table
Correct answer: Stack
A stack is ideal for undo because each action is pushed on the stack and the most recent action (last pushed) is reversed first.
Which data structure uses a LIFO (Last In, First Out) access pattern?