# Amazon Core CS Questions with Answers

8 previously-asked core cs questions from Amazon's hiring process, each with the correct answer and a worked explanation. Written against the company's actual test pattern.

_Source: Astra (https://useastra.in). Updated 2026-09-05._

### 1. Which data structure offers average O(1) insertion, search, and deletion?

A. Array
B. Hash table
C. Linked list
D. Stack

**Answer:** Hash table

**Explanation:** A hash table gives average constant time for these operations via hashing.

### 2. What is the time complexity of heap sort?

A. O(n^2)
B. O(n log n)
C. O(n)
D. O(log n)

**Answer:** O(n log n)

**Explanation:** Building the heap is O(n) and each of n extractions is O(log n), giving O(n log n).

### 3. Topological sorting can be applied to which kind of graph?

A. Directed acyclic graph
B. Undirected cyclic graph
C. Any graph
D. Only trees

**Answer:** Directed acyclic graph

**Explanation:** Topological order exists only for a directed acyclic graph (DAG).

### 4. What is the height of a balanced binary search tree with n nodes?

A. O(log n)
B. O(n)
C. O(1)
D. O(n log n)

**Answer:** O(log n)

**Explanation:** A balanced BST keeps its height proportional to log n.

### 5. Which algorithm finds the shortest path in an unweighted graph?

A. BFS
B. DFS
C. Dijkstra
D. Bellman-Ford

**Answer:** BFS

**Explanation:** Breadth first search explores level by level and finds shortest paths in unweighted graphs.

### 6. What is the amortized time complexity of appending to a dynamic array?

A. O(1)
B. O(n)
C. O(log n)
D. O(n^2)

**Answer:** O(1)

**Explanation:** Occasional resizes cost O(n), but averaged over many appends the cost is O(1).

### 7. Which sorting algorithm is in-place and has O(n log n) worst case time?

A. Merge sort
B. Heap sort
C. Counting sort
D. Bubble sort

**Answer:** Heap sort

**Explanation:** Heap sort sorts in place using a heap and is O(n log n) even in the worst case; merge sort needs extra space.

### 8. What is the space complexity of BFS on a graph with V vertices?

A. O(1)
B. O(V)
C. O(E)
D. O(V^2)

**Answer:** O(V)

**Explanation:** BFS stores vertices in a queue and a visited set, so it uses O(V) space.

More Amazon preparation, including the full recruitment process: https://useastra.in/campus/amazon
