CPA Data Structures & Algorithms 1 — Questions and Answers
Question 1: What is a linked list?
- An array
- A stack
- A data structure where each element points to the next (Correct answer)
- A queue
Correct answer: A data structure where each element points to the next
A linked list is a linear data structure where each element (node) points to the next node, allowing for efficient insertions and deletions.
Question 2: What is a stack in data structures?
- A queue
- A stack follows FIFO
- A collection where the last item added is the first to be removed (Correct answer)
- A sorted list
Correct answer: A collection where the last item added is the first to be removed
A stack is a collection of elements that follows the Last In, First Out (LIFO) principle.
Question 3: What is the difference between an array and a linked list?
- Arrays store data in nodes
- Linked lists have contiguous memory allocation
- Arrays store data in contiguous memory, linked lists use nodes (Correct answer)
- Both store data in nodes
Correct answer: Arrays store data in contiguous memory, linked lists use nodes
Arrays store elements in contiguous memory locations, while linked lists store elements in nodes that are linked together.
Question 4: What is a binary search tree?
- A type of heap
- A tree where left children are smaller than the parent (Correct answer)
- A type of linked list
- A stack with two branches
Correct answer: A tree where left children are smaller than the parent
A binary search tree is a hierarchical data structure where each node has at most two children, and the left child is smaller than the parent.
Question 5: What is a hash table?
- A list of values
- A key-value pair storage structure (Correct answer)
- A data structure for sorting
- A type of queue
Correct answer: A key-value pair storage structure
A hash table is a data structure that uses a hash function to map keys to values, allowing for fast access and insertion.
Question 6: What is the purpose of an algorithm?
- To define a data structure
- To solve a problem in a series of steps (Correct answer)
- To store values
- To visualize data
Correct answer: To solve a problem in a series of steps
An algorithm is a step-by-step process used to solve a problem or complete a task efficiently.
Question 7: What is the time complexity of accessing an element in an array?
- O(n)
- O(log n)
- O(1) (Correct answer)
- O(n^2)
Correct answer: O(1)
Accessing an element in an array is an O(1) operation, meaning it is done in constant time.
Question 8: What is the purpose of quicksort in algorithms?
- To perform addition
- To sort elements by dividing and conquering (Correct answer)
- To search for values
- To find the median
Correct answer: To sort elements by dividing and conquering
Quicksort is a sorting algorithm that uses divide and conquer to efficiently sort elements by recursively partitioning the array.
Question 9: What is a queue in data structures?
- A priority queue
- A data structure that follows FIFO (Correct answer)
- A tree-like structure
- A stack
Correct answer: A data structure that follows FIFO
A queue is a fundamental linear data structure that operates on the First-In, First-Out (FIFO) principle. This means the first element added to the queue is always the first one to be removed, much like a line of people waiting. Elements are added at the 'rear' and removed from the 'front' of the queue.
What is a linked list?