CodeSignal Technical Assessment Data Structures — Questions and Answers
Question 1: What is the time complexity of accessing an element in an array by index?
- O(1) (Correct answer)
- O(n)
- O(log n)
- O(n²)
Correct answer: O(1)
Array access by index is constant time because elements are stored in contiguous memory locations.
Question 2: What data structure uses FIFO (First In, First Out) ordering?
- Queue (Correct answer)
- Stack
- Tree
- Graph
Correct answer: Queue
A queue processes elements in the order they arrive, like a line of people waiting.
Question 3: What is the time complexity of searching in a balanced binary search tree?
- O(log n) (Correct answer)
- O(1)
- O(n)
- O(n²)
Correct answer: O(log n)
A balanced BST halves the search space at each comparison, giving logarithmic time complexity.
Question 4: What is a hash table collision?
- When two different keys hash to the same index (Correct answer)
- When a hash table is full
- When a key cannot be found
- When the hash function fails
Correct answer: When two different keys hash to the same index
Collisions occur when the hash function maps different keys to the same bucket, requiring resolution strategies like chaining or open addressing.
Question 5: What is the difference between a stack and a queue?
- Stack uses LIFO (last in, first out); queue uses FIFO (first in, first out) (Correct answer)
- They are identical
- Stack is faster
- Queue uses more memory
Correct answer: Stack uses LIFO (last in, first out); queue uses FIFO (first in, first out)
Stacks process the most recently added element first, while queues process the oldest element first.
Question 6: What is a linked list advantage over an array?
- Efficient insertion and deletion without shifting elements (Correct answer)
- Faster random access
- Less memory usage
- Built-in sorting
Correct answer: Efficient insertion and deletion without shifting elements
Linked lists can insert and delete elements in O(1) time once the position is found, without moving other elements.
What is the time complexity of accessing an element in an array by index?