Tech

Data Structures

Data structures are the building blocks of efficient software. Understanding how arrays, linked lists, trees, graphs, heaps, and hash maps work — and when to use each — is central to most technical interviews, especially at product and engineering companies. These questions assess your ability to reason about time and space complexity and choose the right tool for the problem at hand.

What you get

Questions

20

Difficulty

3 levels

Answer Formats

2

Use the toggle on each card to move between an interview-ready answer and a simpler explanation. Questions are sorted from beginner to advanced, and the keywords are highlighted. You can also blur the answers to practice recalling them from memory.

Questions

Practice the answers out loud.

All topics

Question 1

What is a data structure?

Beginner

How to answer in an interview

A data structure is a specialized format for organizing, storing, and managing data so it can be accessed and modified efficiently. The choice of data structure affects the time and space complexity of operations like searching, inserting, and deleting, so selecting the right one is key to writing efficient programs.

Question 2

What is the difference between an array and a linked list?

Beginner

How to answer in an interview

An array stores elements in contiguous memory locations, allowing constant-time random access via an index but requiring costly shifting for insertions or deletions in the middle. A linked list stores elements as nodes connected via pointers, allowing efficient insertion and deletion but only sequential access, since there's no direct indexing.

Question 3

What is a stack and where is it used?

Beginner

How to answer in an interview

A stack is a linear data structure that follows Last-In-First-Out (LIFO) order, supporting push (add) and pop (remove) operations at one end. It's used in scenarios like function call management (the call stack), undo features in editors, and expression evaluation.

Question 4

What is a queue and what are its types?

Beginner

How to answer in an interview

A queue is a linear data structure following First-In-First-Out (FIFO) order, where elements are added at the rear (enqueue) and removed from the front (dequeue). Variants include circular queues, which reuse freed space efficiently, and priority queues, where elements are dequeued based on priority rather than order of insertion.

Question 5

What is the difference between a singly and doubly linked list?

Beginner

How to answer in an interview

A singly linked list has nodes that only point to the next node, allowing traversal in one direction only. A doubly linked list has nodes with pointers to both the next and previous nodes, enabling traversal in both directions at the cost of extra memory per node.

Question 6

Explain Big O notation.

Beginner

How to answer in an interview

Big O notation describes the upper bound of an algorithm's time or space complexity as the input size grows, focusing on the worst-case scenario and ignoring constant factors. For example, O(1) means constant time regardless of input size, while O(n) means time grows linearly with input size, helping compare algorithm efficiency at scale.

Question 7

What is the difference between a set and a list?

Beginner

How to answer in an interview

A list is an ordered collection that allows duplicate elements and preserves insertion order. A set is an unordered collection that automatically enforces uniqueness, disallowing duplicate values, and typically offers faster membership checks due to underlying hash-based implementation.

Question 8

Explain a binary search tree (BST).

Intermediate

How to answer in an interview

A binary search tree is a tree data structure where each node has at most two children, and for every node, all values in the left subtree are smaller and all values in the right subtree are larger. This property enables efficient search, insertion, and deletion, all averaging O(log n) time in a balanced tree, though worst case can degrade to O(n) if unbalanced.

Question 9

What is a hash table and how does it handle collisions?

Intermediate

How to answer in an interview

A hash table stores key-value pairs by computing a hash of the key to determine which bucket to place it in, giving average O(1) time for lookups. Collisions, where two keys hash to the same bucket, are typically resolved through chaining, storing multiple entries in a linked list per bucket, or open addressing, which probes for the next available slot.

Question 10

Compare the time complexity of common operations on arrays vs linked lists.

Intermediate

How to answer in an interview

Arrays offer O(1) random access but O(n) insertion or deletion in the middle due to shifting elements. Linked lists offer O(1) insertion or deletion once you have a reference to the node, but O(n) access time since you must traverse from the head to reach a specific position.

Question 11

What is a heap?

Intermediate

How to answer in an interview

A heap is a complete binary tree that satisfies the heap property: in a min-heap, every parent node is smaller than or equal to its children, while in a max-heap, every parent is larger than or equal to its children. Heaps are commonly used to implement priority queues and algorithms like heap sort, offering O(log n) insertion and O(1) access to the min or max element.

Question 12

How are graphs represented in code?

Intermediate

How to answer in an interview

Graphs are commonly represented using an adjacency list, where each node stores a list of its neighboring nodes, which is memory-efficient for sparse graphs, or an adjacency matrix, a 2D array where each cell indicates whether an edge exists between two nodes, which is faster for edge lookups but uses more memory for sparse graphs.

Question 13

What is the difference between BFS and DFS?

Intermediate

How to answer in an interview

Breadth-First Search (BFS) explores a graph level by level using a queue, making it ideal for finding the shortest path in unweighted graphs. Depth-First Search (DFS) explores as far as possible along one branch before backtracking, typically implemented with a stack or recursion, and is useful for tasks like detecting cycles or topological sorting.

Question 14

What is a circular linked list and where is it used?

Intermediate

How to answer in an interview

A circular linked list is a variation where the last node points back to the first node instead of null, forming a loop. It's useful for applications requiring continuous cycling through elements, such as round-robin CPU scheduling or managing playlists that loop back to the beginning.

Question 15

What is a priority queue?

Intermediate

How to answer in an interview

A priority queue is an abstract data structure where each element has an associated priority, and elements are served based on priority rather than insertion order, with higher (or lower) priority elements dequeued first. It's typically implemented using a heap, giving O(log n) insertion and removal.

Question 16

What is a trie and what is it used for?

Advanced

How to answer in an interview

A trie, or prefix tree, is a tree-like data structure used to store strings where common prefixes are shared among nodes, enabling fast prefix-based searches. It's commonly used for implementing autocomplete features, spell checkers, and IP routing tables, offering O(m) search time where m is the length of the string.

Question 17

What is a balanced binary tree, such as an AVL tree?

Advanced

How to answer in an interview

A balanced binary tree, like an AVL tree, maintains a height difference of at most one between the left and right subtrees of any node, ensuring operations remain O(log n) even in worst-case scenarios. AVL trees achieve this by performing rotations, such as left or right rotations, whenever an insertion or deletion causes the tree to become unbalanced.

Question 18

What is memoization and how does it relate to data structures?

Advanced

How to answer in an interview

Memoization is an optimization technique that stores the results of expensive function calls, typically using a hash map or array, and returns the cached result when the same inputs occur again, avoiding redundant computation. It's a core technique in dynamic programming used to reduce exponential time complexity to polynomial time in problems with overlapping subproblems.

Question 19

Explain collision resolution techniques in hashing: chaining vs open addressing.

Advanced

How to answer in an interview

Chaining resolves collisions by storing multiple key-value pairs that hash to the same bucket in a linked list or similar structure at that index. Open addressing resolves collisions by searching for the next available slot in the table itself, using strategies like linear probing, quadratic probing, or double hashing, avoiding extra memory for linked structures but requiring careful handling of deletions.

Question 20

Explain amortized time complexity using dynamic array resizing as an example.

Advanced

How to answer in an interview

Amortized time complexity averages the cost of an operation over a sequence of operations, rather than looking at any single worst case in isolation. For a dynamic array, most insertions are O(1), but occasionally the array must resize and copy all elements, an O(n) operation; because resizing happens infrequently and the cost is spread across many prior cheap insertions, the amortized cost per insertion remains O(1).

More in Tech

Keep browsing related topics.

Browse all