CodeSignal Technical Assessment Core Data Structures 2 ā Questions and Answers
Question 1: What is the worst-case time complexity for searching an element in a balanced Binary Search Tree (BST)?
- O(n)
- O(log n) (Correct answer)
- O(1)
- O(n log n)
Correct answer: O(log n)
A balanced BST has height O(log n), so search eliminates half the remaining nodes at each step.
Question 2: In a min-heap, which statement is always true?
- The root is the largest element
- Every node is smaller than or equal to its children (Correct answer)
- The tree is always a complete binary tree with sorted levels
- Left child is always smaller than right child
Correct answer: Every node is smaller than or equal to its children
The min-heap property requires every parent node to be less than or equal to its children.
Question 3: Which data structure uses FIFO (First-In, First-Out) ordering?
- Stack
- Priority Queue
- Queue (Correct answer)
- Deque
Correct answer: Queue
A queue strictly processes elements in the order they were added, making the first element added the first removed.
Question 4: What is the time complexity of inserting a key-value pair into a hash map with a good hash function (average case)?
- O(n)
- O(log n)
- O(1) (Correct answer)
- O(n²)
Correct answer: O(1)
With a good hash function and low load factor, insertion computes the bucket index in constant time.
Question 5: A doubly linked list differs from a singly linked list because each node in a doubly linked list:
- Stores two data values
- Has a pointer to both next and previous nodes (Correct answer)
- Can only be traversed forward
- Is stored in contiguous memory
Correct answer: Has a pointer to both next and previous nodes
Doubly linked list nodes carry both a `next` and a `prev` pointer, enabling bidirectional traversal.
Question 6: Which operation on a stack is used to view the top element WITHOUT removing it?
- pop()
- push()
- peek() (Correct answer)
- dequeue()
Correct answer: peek()
peek() (also called top()) returns the top element while leaving the stack unchanged.
Question 7: What happens when a hash map experiences a collision?
- The new key overwrites the existing key
- The hash map automatically resizes
- Two keys map to the same bucket and must be resolved by chaining or open addressing (Correct answer)
- The insertion is rejected
Correct answer: Two keys map to the same bucket and must be resolved by chaining or open addressing
Collisions occur when two keys hash to the same index and are resolved via chaining (linked list) or open addressing (probing).
What is the worst-case time complexity for searching an element in a balanced Binary Search Tree (BST)?