# Microsoft Core CS Questions with Answers

8 previously-asked core cs questions from Microsoft'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 of the following sorting algorithms is NOT O(n log n) on average?

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

**Answer:** Bubble sort

**Explanation:** Bubble sort is O(n^2); merge, heap, and average quicksort are O(n log n).

### 2. Which data structure is best suited for prefix based autocomplete?

A. Trie
B. Stack
C. Queue
D. Heap

**Answer:** Trie

**Explanation:** A trie stores strings by shared prefixes, enabling efficient prefix search and autocomplete.

### 3. An inorder traversal of a binary search tree produces nodes in what order?

A. Sorted ascending order
B. Reverse order
C. Random order
D. Level order

**Answer:** Sorted ascending order

**Explanation:** Inorder (left, root, right) of a BST yields keys in ascending sorted order.

### 4. Dijkstra shortest path algorithm does NOT work correctly with?

A. Negative edge weights
B. Positive edge weights
C. Directed graphs
D. Large graphs

**Answer:** Negative edge weights

**Explanation:** Dijkstra assumes non-negative weights; negative edges can break its greedy choice, so use Bellman-Ford instead.

### 5. Which of the following uses the divide and conquer strategy?

A. Merge sort
B. BFS
C. Linear search
D. Bubble sort

**Answer:** Merge sort

**Explanation:** Merge sort divides the array, sorts halves, and merges them, which is divide and conquer.

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

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

**Answer:** O(log n)

**Explanation:** Balancing keeps the height near log n.

### 7. Which data structure is used in a breadth first search?

A. DFS stack
B. Queue
C. Binary search tree
D. Priority heap

**Answer:** Queue

**Explanation:** BFS uses a FIFO queue to visit nodes level by level.

### 8. What is a memory leak?

A. Allocated memory that is never freed
B. A stack overflow
C. Accessing a null pointer
D. An integer overflow

**Answer:** Allocated memory that is never freed

**Explanation:** A memory leak occurs when dynamically allocated memory is no longer referenced but not released.

More Microsoft preparation, including the full recruitment process: https://useastra.in/campus/microsoft
