# Technical Aptitude Practice Questions with Solutions

> 300 practice questions for Technical Aptitude, spanning Programming Fundamentals, Data Structures, Algorithms, and 4 more topics, each with a full worked solution and a Basic, Intermediate, or Advanced difficulty tag.

Canonical: https://devsunite.com/resources/aptitude-prep/technical-aptitude
Last updated: 2026-11-22

300 questions in 3 difficulty levels (Basic: 100, Intermediate: 100, Advanced: 100). Each question lists its options (where it has them), the answer and a worked solution.

## Basic level

### Programming Fundamentals

**Q1.** What does this C snippet print: `int x = 5; printf("%d", x++);`?

- A) 6
- B) 4
- C) 5
- D) 5 6

**Answer:** 5

**Solution:** `x++` is post-increment, so `printf` reads the current value of `x` (5) before the increment happens, then `x` becomes 6 afterward.

**Q2.** In Python, what does `print(3 * "hello")` output?

- A) hellohellohello
- B) hello3
- C) 15
- D) Error: can't multiply string

**Answer:** hellohellohello

**Solution:** Multiplying a string by an integer repeats it that many times: `3 * "hello"` gives `"hellohellohello"`.

**Q3.** Trace this Java code. What is `x` afterward: `int x = 10; x += 5;`?

- A) 50
- B) 5
- C) 105
- D) 15

**Answer:** 15

**Solution:** `x += 5` is shorthand for `x = x + 5`, so `x` becomes `10 + 5 = 15`.

**Q4.** What gets printed by this C++ snippet: `int a = 3, b = 4; cout << a + b;`?

- A) 34
- B) 7
- C) 12
- D) 1

**Answer:** 7

**Solution:** `a + b` evaluates to `3 + 4 = 7`, and `cout` writes `7`.

**Q5.** What effect does this Python code have: `x = [1, 2, 3]; x.append(4)`?

- A) Adds 4 at the beginning of the list
- B) Adds 4 to the list
- C) Replaces the list with [4]
- D) Creates a new list with 4 added, leaving x unchanged

**Answer:** Adds 4 to the list

**Solution:** `append(4)` adds `4` onto the end of list `x`, turning it into `[1, 2, 3, 4]`.

**Q6.** What is the output of this C code: `int x = 8; printf("%d", x >> 1);`?

- A) 16
- B) 2
- C) 7
- D) 4

**Answer:** 4

**Solution:** `x >> 1` shifts the bits right by one place. `8` in binary is `1000`, which becomes `0100`, i.e. `4`.

**Q7.** What does this Java line output: `boolean x = true; System.out.println(!x);`?

- A) false
- B) true
- C) 1
- D) !true

**Answer:** false

**Solution:** The `!` operator flips a boolean, so `!x` turns `true` into `false`.

**Q8.** Work out the output of this Python code: `x = 10; y = 3; print(x // y)`?

- A) 3.33
- B) 3.3333333333333335
- C) 3
- D) 1

**Answer:** 3

**Solution:** `//` performs floor (integer) division, discarding the remainder: `10 // 3 = 3`.

**Q9.** What does this C++ snippet print: `int x = 5; if(x > 3) cout << "Yes"; else cout << "No";`?

- A) No
- B) YesNo
- C) 5
- D) Yes

**Answer:** Yes

**Solution:** Since `5 > 3` is true, the `if` branch runs and prints `Yes`.

**Q10.** What is printed by this Python loop: `for i in range(3): print(i)`?

- A) 1 2 3
- B) 0 1 2
- C) 0 1 2 3
- D) 3

**Answer:** 0

1

2

**Solution:** `range(3)` produces the sequence `0, 1, 2`, and the loop prints each one on its own line.

**Q11.** What does this C code output: `int x = 3; printf("%d", x & 1);`?

- A) 1
- B) 3
- C) 0
- D) 2

**Answer:** 1

**Solution:** `x & 1` is a bitwise AND. `3` is `11` in binary and `1` is `01`; ANDing them gives `01`, i.e. `1`.

**Q12.** What is printed by this Java snippet: `int x = 7; System.out.println(x % 2);`?

- A) 3
- B) 0
- C) 1
- D) 3.5

**Answer:** 1

**Solution:** `%` computes the remainder: `7 % 2` leaves a remainder of `1`.

**Q13.** What is the output of this Python code: `x = [1, 2]; x.pop(0); print(x)`?

- A) [1]
- B) [2]
- C) [1, 2]
- D) []

**Answer:** [2]

**Solution:** `pop(0)` removes the element at index `0` (which is `1`), leaving the list `[2]`.

**Q14.** What does this C++ code print: `int x = 4; cout << ++x;`?

- A) 4
- B) 6
- C) 45
- D) 5

**Answer:** 5

**Solution:** `++x` is pre-increment: `x` becomes `5` first, and that updated value is what gets printed.

**Q15.** What is the output of this C snippet: `int x = 5; printf("%d", x | 2);`?

- A) 7
- B) 5
- C) 3
- D) 2

**Answer:** 7

**Solution:** `x | 2` is a bitwise OR. `5` is `101` in binary and `2` is `010`; ORing them gives `111`, i.e. `7`.

**Q16.** What does this Python code output: `x = {1, 2, 2}; print(len(x))`?

- A) 3
- B) 1
- C) 2
- D) SyntaxError

**Answer:** 2

**Solution:** Sets automatically drop duplicate values, so `{1, 2, 2}` collapses to `{1, 2}`, and `len` reports `2`.

**Q17.** What is printed by this Java code: `String s = "Hello"; System.out.println(s.length());`?

- A) 4
- B) 6
- C) Hello
- D) 5

**Answer:** 5

**Solution:** `length()` returns the number of characters in the string; `"Hello"` has `5`.

**Q18.** What is the output of this C++ loop: `int x = 10; while(x > 8) { cout << x << " "; x--; }`?

- A) 10 9 8
- B) 10 9
- C) 9 8
- D) 10

**Answer:** 10 9

**Solution:** The loop keeps running while `x > 8`, printing `10` then `9` before `x` drops to `8` and the loop stops.

**Q19.** What does this Python line output: `x = 5; print(x ** 2)`?

- A) 10
- B) 7
- C) 25
- D) 52

**Answer:** 25

**Solution:** `**` is the exponentiation operator: `5 ** 2 = 25`.

**Q20.** What is printed by this C code: `int x = 6; printf("%d", x ^ 3);`?

- A) 5
- B) 3
- C) 9
- D) 2

**Answer:** 5

**Solution:** `x ^ 3` is a bitwise XOR. `6` is `110` and `3` is `011`; XORing gives `101`, i.e. `5`.

### Data Structures

**Q21.** How fast is element access on an array, in Big-O terms?

- A) O(n)
- B) O(log n)
- C) O(n²)
- D) O(1)

**Answer:** O(1)

**Solution:** An array lets you jump straight to any index, so access takes constant time.

**Q22.** For a singly linked list, what's the time complexity of inserting a new node at the head?

- A) O(n)
- B) O(1)
- C) O(log n)
- D) O(n²)

**Answer:** O(1)

**Solution:** Inserting at the head is just repointing the head reference, which takes constant time regardless of list size.

**Q23.** Follow this Python stack code. What's printed: `s = []; s.append(1); s.append(2); s.pop(); print(s)`?

- A) [2]
- B) [1, 2]
- C) [1]
- D) []

**Answer:** [1]

**Solution:** Using a list as a stack (LIFO): `append` pushes `1` then `2`, `pop` removes the most recent item (`2`), leaving `[1]`.

**Q24.** For a queue, what's the final element order after: enqueue(1), enqueue(2), dequeue(), enqueue(3)?

- A) 2, 3
- B) 1, 3
- C) 3, 2
- D) 1, 2, 3

**Answer:** 2, 3

**Solution:** A queue is FIFO: `1` and `2` are enqueued, `dequeue()` removes the oldest item (`1`), then `3` is enqueued, leaving `2, 3` in order.

**Q25.** What's the time complexity of a linear search through an unsorted array of n elements?

- A) O(log n)
- B) O(1)
- C) O(n²)
- D) O(n)

**Answer:** O(n)

**Solution:** Without any ordering to exploit, the search may have to inspect every element, giving n comparisons in the worst case.

**Q26.** In a binary tree rooted at level 0, what's the largest possible number of nodes at level k?

- A) 2^(k+1)
- B) k^2
- C) 2^k
- D) 2k

**Answer:** 2^k

**Solution:** Each level can have at most twice as many nodes as the one above it, so level k can hold up to 2^k nodes.

**Q27.** What does this Python list operation produce: `x = [1, 2, 3]; x.insert(1, 4); print(x)`?

- A) [4, 1, 2, 3]
- B) [1, 4, 2, 3]
- C) [1, 2, 4, 3]
- D) [1, 2, 3, 4]

**Answer:** [1, 4, 2, 3]

**Solution:** `insert(1, 4)` places `4` at index `1`, shifting the rest over, giving `[1, 4, 2, 3]`.

**Q28.** What's the amortized time complexity of appending to the end of a dynamic array?

- A) O(1)
- B) O(n)
- C) O(log n)
- D) O(n²)

**Answer:** O(1)

**Solution:** Occasional resizing aside, appends average out to constant time, since resizes happen rarely relative to the number of appends.

**Q29.** In a size-5 circular queue, after enqueue(1, 2, 3), dequeue(), enqueue(4), what's at the front?

- A) 1
- B) 4
- C) 3
- D) 2

**Answer:** 2

**Solution:** After enqueuing `1, 2, 3`, dequeue removes `1`. Enqueuing `4` afterward doesn't change the front, which is now `2`.

**Q30.** For a balanced binary tree with 7 nodes, how tall is it?

- A) 3
- B) 7
- C) 2
- D) 1

**Answer:** 2

**Solution:** A balanced tree's height follows ⌊log₂(n)⌋; for `n = 7` that's `⌊log₂(7)⌋ = 2`, spanning levels 0 through 2.

**Q31.** What does this Python dictionary lookup return: `d = {1: 'a', 2: 'b'}; print(d[1])`?

- A) b
- B) a
- C) 1
- D) KeyError

**Answer:** a

**Solution:** Looking up key `1` in the dictionary returns its associated value, `'a'`.

**Q32.** What's the time complexity of removing the last node from a singly linked list of n nodes?

- A) O(n)
- B) O(1)
- C) O(log n)
- D) O(n²)

**Answer:** O(n)

**Solution:** Without a tail pointer's predecessor known, you must walk to the second-to-last node first, which takes O(n).

**Q33.** On this stack: push(1), push(2), pop(), push(3), what ends up on top?

- A) 2
- B) 1
- C) 1, 3
- D) 3

**Answer:** 3

**Solution:** Pushing `1` then `2`, popping removes `2`, and pushing `3` puts `3` on top.

**Q34.** For a balanced binary search tree with n nodes, what's the search time complexity?

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

**Answer:** O(log n)

**Solution:** A balanced BST's height grows logarithmically with n, so search takes O(log n).

**Q35.** What is the result of this Python set operation: `s = {1, 2, 3}; s.add(4); print(s)`?

- A) {1, 2, 3, [4]}
- B) {1, 2, 3, 4}
- C) {4}
- D) {1, 2, 3}

**Answer:** {1, 2, 3, 4}

**Solution:** `add(4)` inserts `4` into the set, giving `{1, 2, 3, 4}`.

**Q36.** What's the space complexity of storing a binary tree with n nodes?

- A) O(n)
- B) O(log n)
- C) O(n²)
- D) O(1)

**Answer:** O(n)

**Solution:** Every node carries its own data plus two child pointers, so total storage scales linearly: O(n).

**Q37.** Trace this queue sequence: enqueue(1, 2), dequeue(), enqueue(3, 4), dequeue(). What's the front now?

- A) 2
- B) 4
- C) 1
- D) 3

**Answer:** 3

**Solution:** Enqueue `1, 2`; dequeue removes `1`; enqueue `3, 4`; dequeue removes `2`. The front is now `3`.

**Q38.** On average, what's the time complexity of inserting a key into a hash table?

- A) O(n)
- B) O(log n)
- C) O(1)
- D) O(n²)

**Answer:** O(1)

**Solution:** With a decent hash function distributing keys evenly, insertion averages out to O(1).

**Q39.** What is the output of this Python list method: `x = [1, 2, 3]; x.remove(2); print(x)`?

- A) [1, 2]
- B) [1, 3]
- C) [3]
- D) [1]

**Answer:** [1, 3]

**Solution:** `remove(2)` deletes the first occurrence of `2` from the list, leaving `[1, 3]`.

**Q40.** For a binary tree of height h, what's the largest possible number of nodes it can hold?

- A) 2^(h+1) - 1
- B) 2^h - 1
- C) 2^h
- D) h^2

**Answer:** 2^(h+1) - 1

**Solution:** Summing the maximum node count across every level from 0 to h gives 2^(h+1) - 1.

### Algorithms

**Q41.** What's the time complexity of bubble sort on n elements?

- A) O(n log n)
- B) O(n)
- C) O(n²)
- D) O(log n)

**Answer:** O(n²)

**Solution:** Bubble sort's nested comparison-and-swap loops give it O(n²) time.

**Q42.** What does this Python search return: `x = [3, 1, 4]; print(x.index(4))`?

- A) 4
- B) 1
- C) 0
- D) 2

**Answer:** 2

**Solution:** `index(4)` returns the position of the first `4` in the list, which is index `2`.

**Q43.** What's the time complexity of binary search over a sorted array of n elements?

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

**Answer:** O(log n)

**Solution:** Each comparison cuts the remaining search space in half, giving O(log n).

**Q44.** Trace this recursive C factorial function. What does it print: `int fact(int n) { if(n == 0) return 1; return n * fact(n-1); } printf("%d", fact(3));`?

- A) 6
- B) 3
- C) 9
- D) 24

**Answer:** 6

**Solution:** `fact(3)` unwinds as `3 × fact(2) = 3 × 2 × fact(1) = 3 × 2 × 1 = 6`.

**Q45.** What's the space complexity of a recursive factorial implementation?

- A) O(1)
- B) O(log n)
- C) O(n)
- D) O(n²)

**Answer:** O(n)

**Solution:** Each recursive call adds a frame to the call stack, so n calls use O(n) stack space.

**Q46.** What does this Python sort produce: `x = [5, 2, 8]; print(sorted(x))`?

- A) [8, 5, 2]
- B) [5, 2, 8]
- C) None
- D) [2, 5, 8]

**Answer:** [2, 5, 8]

**Solution:** `sorted(x)` returns a brand-new sorted list without touching the original: `[2, 5, 8]`.

**Q47.** What's the time complexity of scanning for the maximum in an unsorted array of n elements?

- A) O(log n)
- B) O(n)
- C) O(1)
- D) O(n²)

**Answer:** O(n)

**Solution:** Without any ordering to rely on, every element has to be checked once: O(n).

**Q48.** Trace this recursive C summing function. What's printed: `int sum(int n) { if(n == 0) return 0; return n + sum(n-1); } printf("%d", sum(4));`?

- A) 10
- B) 4
- C) 6
- D) 16

**Answer:** 10

**Solution:** `sum(4)` expands to `4 + sum(3) = 4 + 3 + sum(2) = 4 + 3 + 2 + sum(1) = 4 + 3 + 2 + 1 = 10`.

**Q49.** What's the time complexity of selection sort on n elements?

- A) O(n log n)
- B) O(n)
- C) O(n²)
- D) O(log n)

**Answer:** O(n²)

**Solution:** Selection sort scans for the minimum on every pass, giving it O(n²) overall.

**Q50.** What does this Python slice produce: `x = [1, 2, 3]; print(x[::-1])`?

- A) [1, 2, 3]
- B) []
- C) [3, 1, 2]
- D) [3, 2, 1]

**Answer:** [3, 2, 1]

**Solution:** The slice `[::-1]` walks the list backward, reversing it to `[3, 2, 1]`.

**Q51.** What's the time complexity of testing membership in a sorted array via binary search?

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

**Answer:** O(log n)

**Solution:** Binary search halves the candidate range each step, so it runs in O(log n).

**Q52.** What does this C++ loop compute: `int x = 5; for(int i = 1; i <= 3; i++) x += i; cout << x;`?

- A) 11
- B) 8
- C) 14
- D) 6

**Answer:** 11

**Solution:** The loop adds `1`, `2`, and `3` onto `x` in turn: `5 + 1 + 2 + 3 = 11`.

**Q53.** What's the space complexity of bubble sort?

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

**Answer:** O(1)

**Solution:** Bubble sort swaps elements in place and needs no extra structures, so its space use is constant: O(1).

**Q54.** What does this Python code output: `x = [1, 2, 3]; print(sum(x))`?

- A) 3
- B) 123
- C) 5
- D) 6

**Answer:** 6

**Solution:** `sum(x)` totals the list's elements: `1 + 2 + 3 = 6`.

**Q55.** What's the time complexity of inserting a value into a sorted array of n elements while keeping it sorted?

- A) O(log n)
- B) O(n)
- C) O(1)
- D) O(n²)

**Answer:** O(n)

**Solution:** Making room for the new element means shifting the ones after it, which costs O(n).

**Q56.** What does this C conditional print: `int a = 3, b = 5; if(a > b) printf("%d", a); else printf("%d", b);`?

- A) 5
- B) 3
- C) 8
- D) 35

**Answer:** 5

**Solution:** `3 > 5` is false, so the `else` branch runs and prints `b`, which is `5`.

**Q57.** What's the time complexity of merging two already-sorted arrays of sizes m and n?

- A) O(m * n)
- B) O(log(m + n))
- C) O(m + n)
- D) O((m + n) log(m + n))

**Answer:** O(m + n)

**Solution:** Merging walks through both arrays once, comparing and copying as it goes: O(m + n).

**Q58.** What does this Python string method return: `x = "abc"; print(x.upper())`?

- A) abc
- B) Abc
- C) ABC()
- D) ABC

**Answer:** ABC

**Solution:** `upper()` returns an all-caps version of the string: `"ABC"`.

**Q59.** What's the time complexity of reversing an array of n elements in place?

- A) O(n²)
- B) O(n)
- C) O(log n)
- D) O(1)

**Answer:** O(n)

**Solution:** Swapping elements from opposite ends toward the middle touches each pair once, giving O(n).

**Q60.** What does this C++ snippet print: `int x = 4; x *= 3; cout << x;`?

- A) 12
- B) 7
- C) 43
- D) 1

**Answer:** 12

**Solution:** `x *= 3` multiplies `x` by `3`: `4 * 3 = 12`.

### Database Basics

**Q61.** What does this SQL statement do: `SELECT * FROM table_name;`?

- A) Deletes all data
- B) Counts all rows
- C) Fetches only column names
- D) Fetches all data

**Answer:** Fetches all data

**Solution:** It pulls back every column for every row stored in `table_name`.

**Q62.** What does `SELECT name FROM employees WHERE salary > 50000;` return?

- A) All columns of employees with salary > 50000
- B) Names of employees with salary < 50000
- C) Names of employees with salary > 50000
- D) Total salary of employees over 50000

**Answer:** Names of employees with salary > 50000

**Solution:** It returns the `name` values for employee rows whose `salary` is above 50000.

**Q63.** What guarantee does the SQL `PRIMARY KEY` constraint provide?

- A) Uniqueness and non-null
- B) Uniqueness only, nulls allowed
- C) Non-null only, duplicates allowed
- D) Enforces referential integrity to another table

**Answer:** Uniqueness and non-null

**Solution:** It guarantees every value in that column is both unique and never null.

**Q64.** What does `SELECT COUNT(*) FROM students WHERE age = 20;` return?

- A) List of students aged 20
- B) Number of students aged 20
- C) Number of students not aged 20
- D) Average age of all students

**Answer:** Number of students aged 20

**Solution:** It counts how many rows in `students` have `age` equal to 20.

**Q65.** What does the statement `DELETE FROM table_name WHERE id = 1;` do?

- A) Deletes all rows
- B) Deletes the table itself
- C) Updates the row with id = 1
- D) Deletes row with id = 1

**Answer:** Deletes row with id = 1

**Solution:** It deletes whichever row has `id` equal to `1`.

**Q66.** What role does the SQL `JOIN` clause play?

- A) Deletes duplicate rows
- B) Sorts table rows
- C) Merges tables
- D) Creates a new table permanently

**Answer:** Merges tables

**Solution:** It combines rows across two or more tables based on how a shared column relates them.

**Q67.** What effect does `INSERT INTO users (name, age) VALUES ('Alice', 25);` have?

- A) Inserts a new user
- B) Updates an existing user's age to 25
- C) Deletes the user named Alice
- D) Creates a new users table

**Answer:** Inserts a new user

**Solution:** It inserts a new row into `users` with `name` set to `'Alice'` and `age` set to `25`.

**Q68.** What does `SELECT MAX(salary) FROM employees;` return?

- A) Minimum salary
- B) Maximum salary
- C) Average salary
- D) Total of all salaries

**Answer:** Maximum salary

**Solution:** It returns whichever `salary` value in the table is the largest.

**Q69.** What does the SQL `WHERE` clause do?

- A) Sorts data
- B) Groups data
- C) Joins tables
- D) Filters data

**Answer:** Filters data

**Solution:** It narrows down the returned rows to just those matching a given condition.

**Q70.** What does `UPDATE products SET price = 100 WHERE id = 5;` do?

- A) Updates price for all products
- B) Inserts a new product with price 100
- C) Updates price for id = 5
- D) Deletes the product with id = 5

**Answer:** Updates price for id = 5

**Solution:** It changes `price` to `100` for the row whose `id` is `5`.

### Computer Networks

**Q71.** Why does every device on a network need an IP address?

- A) Device identification
- B) Data encryption
- C) Bandwidth allocation
- D) Error correction

**Answer:** Device identification

**Solution:** An IP address is what uniquely identifies a device so it can be found on the network.

**Q72.** Which port does HTTP traffic normally use?

- A) 443
- B) 80
- C) 21
- D) 8080

**Answer:** 80

**Solution:** HTTP defaults to port `80`.

**Q73.** What does the abbreviation TCP stand for?

- A) Transfer Control Protocol
- B) Transmission Communication Protocol
- C) Total Control Protocol
- D) Transmission Control Protocol

**Answer:** Transmission Control Protocol

**Solution:** Transmission Control Protocol; it's designed to guarantee reliable delivery of data.

**Q74.** What job does DNS do on a network?

- A) IP address assignment
- B) Data encryption
- C) Domain name resolution
- D) Packet routing

**Answer:** Domain name resolution

**Solution:** It converts human-readable domain names, like google.com, into the IP addresses computers actually use.

**Q75.** How do IPv4 and IPv6 differ?

- A) Address length and capacity
- B) IPv6 is faster but less secure
- C) IPv4 supports more devices than IPv6
- D) IPv6 only works on wireless networks

**Answer:** Address length and capacity

**Solution:** IPv4 addresses are 32 bits (e.g. 192.168.0.1); IPv6 addresses are 128 bits, giving vastly more room for addresses.

**Q76.** What does "bandwidth" mean in networking?

- A) Signal strength
- B) Data transfer rate
- C) Number of connected devices
- D) Physical cable length

**Answer:** Data transfer rate

**Solution:** It's the upper limit on how much data a connection can carry per unit of time.

**Q77.** What does a router actually do inside a network?

- A) Assigns IP addresses
- B) Encrypts network traffic
- C) Resolves domain names
- D) Routes data

**Answer:** Routes data

**Solution:** It forwards packets of data between different networks.

**Q78.** What's the default subnet mask for a Class C address?

- A) 255.255.0.0
- B) 255.0.0.0
- C) 255.255.255.0
- D) 255.255.255.255

**Answer:** 255.255.255.0

**Solution:** Class C reserves 24 bits for the network portion, giving a mask of `255.255.255.0`.

**Q79.** What does the ARP protocol handle?

- A) Address resolution
- B) Domain name resolution
- C) Error detection in packets
- D) Assigning dynamic IP addresses

**Answer:** Address resolution

**Solution:** It resolves IP addresses down to the corresponding MAC addresses.

**Q80.** What does UDP stand for, and how is it different from TCP?

- A) Universal Data Protocol, more reliable than TCP
- B) User Datagram Protocol, less reliable
- C) User Data Packet, identical reliability to TCP
- D) Uniform Delivery Protocol, used only for email

**Answer:** User Datagram Protocol, less reliable

**Solution:** User Datagram Protocol; it's quicker than TCP but sacrifices reliability, since it skips TCP's error-checking.

### Operating Systems

**Q81.** At a high level, what does an operating system actually do?

- A) Application development
- B) Network security only
- C) Data storage only
- D) Resource management

**Answer:** Resource management

**Solution:** It manages the machine's hardware and software resources and gives the user a way to interact with them.

**Q82.** What exactly is a "process" in an OS's terms?

- A) A block of code saved on disk
- B) A lightweight unit sharing memory with others
- C) Executing program
- D) A scheduling algorithm

**Answer:** Executing program

**Solution:** It's a running instance of a program, complete with its own memory space and resources.

**Q83.** What's the scheduler's job inside an OS?

- A) CPU allocation
- B) Memory allocation
- C) Disk space management
- D) Network traffic control

**Answer:** CPU allocation

**Solution:** It decides how CPU time gets divided among competing processes so execution stays efficient.

**Q84.** What's a deadlock, in operating-systems terms?

- A) A crashed process that must restart
- B) Resource conflict standstill
- C) A memory leak that slows the system
- D) A scheduling algorithm that prioritizes urgent tasks

**Answer:** Resource conflict standstill

**Solution:** It's a standoff where processes are each holding a resource another needs, so none of them can proceed.

**Q85.** What does "virtual memory" mean?

- A) A backup copy of RAM
- B) Memory reserved exclusively for the OS kernel
- C) Cache memory built into the CPU
- D) Extended memory

**Answer:** Extended memory

**Solution:** It's a technique that borrows disk space to effectively extend available RAM, letting larger programs run.

**Q86.** What does a file system actually manage inside an OS?

- A) CPU scheduling
- B) Network connections
- C) Data organization
- D) Process memory allocation

**Answer:** Data organization

**Solution:** It organizes how data is stored and retrieved on disk.

**Q87.** What's a "thread" in the context of an operating system?

- A) Lightweight process
- B) A separate program with its own memory space
- C) A hardware component that executes instructions
- D) A type of file system

**Answer:** Lightweight process

**Solution:** It's a lighter-weight execution unit that shares its parent process's memory space.

**Q88.** Why do interrupts exist in an OS?

- A) To permanently pause a process
- B) Event handling
- C) To allocate memory to new processes
- D) To schedule background tasks at fixed intervals

**Answer:** Event handling

**Solution:** They let the CPU know it needs to stop and handle something urgent, like hardware input.

**Q89.** How does a kernel differ from a shell?

- A) Kernel: interface, Shell: core
- B) Kernel and shell are the same thing
- C) Kernel: file storage, Shell: memory management
- D) Kernel: core, Shell: interface

**Answer:** Kernel: core, Shell: interface

**Solution:** The kernel is the OS's core, managing resources directly; the shell is the interface a user interacts with.

**Q90.** What's the page table's role in virtual memory?

- A) Process scheduling order
- B) Disk defragmentation
- C) Address mapping
- D) User permission management

**Answer:** Address mapping

**Solution:** It keeps the mapping between virtual addresses and where they actually live in physical memory.

### AI/ML Foundations

**Q91.** What defines supervised learning in machine learning?

- A) Learning with labeled data
- B) Learning without any data
- C) Learning by finding patterns with no labels
- D) Learning through trial-and-error rewards

**Answer:** Learning with labeled data

**Solution:** The model learns from labeled examples (input/output pairs), so it can predict outputs for new inputs.

**Q92.** Why do ML models use a loss function?

- A) Data storage
- B) Error measurement
- C) Feature selection
- D) Model deployment

**Answer:** Error measurement

**Solution:** It quantifies how far off the model's predictions are from the real answers, giving optimization something to minimize.

**Q93.** What's meant by "overfitting" in machine learning?

- A) Insufficient training on the data
- B) Using too many test examples
- C) Training a model too quickly
- D) Excessive training fit

**Answer:** Excessive training fit

**Solution:** It's when a model fits the training data too closely, memorizing its noise, and then performs poorly on unseen data.

**Q94.** What is a "feature" in the context of ML?

- A) The model's predicted output
- B) A type of neural network layer
- C) Input variable
- D) The final trained model file

**Answer:** Input variable

**Solution:** It's one of the input variables the model uses to make its predictions.

**Q95.** Why split data into training and test sets before building a model?

- A) Model training and evaluation
- B) To reduce the amount of data needed
- C) To speed up training time
- D) To remove duplicate data

**Answer:** Model training and evaluation

**Solution:** The training set is what the model learns from; the test set checks how well it generalizes to data it hasn't seen.

**Q96.** What is a neuron, in the context of a neural network?

- A) A single training example
- B) Computational unit
- C) The final output layer
- D) A type of loss function

**Answer:** Computational unit

**Solution:** It's a small computational unit that takes inputs, applies weights to them, and produces an output.

**Q97.** What does the activation function contribute in a neural network?

- A) Data normalization
- B) Weight initialization
- C) Error backpropagation
- D) Non-linearity function

**Answer:** Non-linearity function

**Solution:** It introduces non-linearity, determining whether and how strongly a neuron fires.

**Q98.** What is gradient descent used for in ML?

- A) Data collection
- B) Feature extraction
- C) Parameter optimization
- D) Model evaluation

**Answer:** Parameter optimization

**Solution:** It's an optimization method that nudges the model's parameters step by step to shrink the loss function.

**Q99.** What characterizes unsupervised learning in ML?

- A) Learning without labels
- B) Learning with labeled data
- C) Learning through rewards and penalties
- D) Learning with no data at all

**Answer:** Learning without labels

**Solution:** The model looks for structure or patterns in data that has no predefined output labels.

**Q100.** Why normalize features before training an ML model?

- A) Feature deletion
- B) Feature scaling
- C) Label encoding
- D) Data augmentation

**Answer:** Feature scaling

**Solution:** Scaling features onto a common range tends to improve how well the model trains.

## Intermediate level

### Programming Fundamentals

**Q1.** Trace this C snippet. What's the output: `int x = 5; printf("%d %d", x++, ++x);`?

- A) 5 5
- B) 6 6
- C) 5 7
- D) 6 7

**Answer:** 6 6

**Solution:** `printf`'s arguments are evaluated right-to-left here: `++x` runs first, bumping `x` to 6; then `x++` reads that 6 (and bumps `x` to 7 afterward). Both printed values come out as `6`.

**Q2.** What does this Python code print: `x = [1, 2, 3]; y = x; y[0] = 4; print(x)`?

- A) [1, 2, 3, 4]
- B) [1, 2, 3]
- C) [1, 2, 4]
- D) [4, 2, 3]

**Answer:** [4, 2, 3]

**Solution:** `y = x` doesn't copy the list; `y` just points at the same object as `x`. Changing `y[0]` is therefore visible through `x` too: `[4, 2, 3]`.

**Q3.** What does this Java code output: `String s = "hello"; s = s.concat(" world"); System.out.println(s);`?

- A) hello world
- B) hello
- C) world hello
- D) helloworld

**Answer:** hello world

**Solution:** `concat` builds a new string, `"hello world"`, which gets assigned back to `s`.

**Q4.** What is printed by this C++ ternary expression: `int x = 10; cout << (x > 5 ? x : 5);`?

- A) 10
- B) 1
- C) true
- D) 5

**Answer:** 10

**Solution:** Since `x > 5` holds, the ternary evaluates to `x`, so `10` is printed.

**Q5.** What does this Python function call print: `def f(x): x += 1; x = 5; f(x); print(x)`?

- A) 6
- B) UnboundLocalError
- C) 5
- D) None

**Answer:** 5

**Solution:** Integers are passed by value in Python, so the `x` modified inside `f` is a local copy; the outer `x` stays `5`.

**Q6.** What is the output of this C code: `int x = 10; printf("%d", x << 2);`?

- A) 40
- B) 80
- C) 2
- D) 20

**Answer:** 40

**Solution:** `x << 2` shifts `10` (`1010` in binary) left by two bits, landing on `101000`, i.e. `40`.

**Q7.** What does this Java array access print: `int[] arr = {1, 2, 3}; System.out.println(arr[arr.length - 1]);`?

- A) 2
- B) 3
- C) 1
- D) ArrayIndexOutOfBoundsException

**Answer:** 3

**Solution:** `arr.length - 1` is `2`, and `arr[2]` holds `3`.

**Q8.** What does this Python dict update produce: `x = {1: 'a', 2: 'b'}; x.update({2: 'c'}); print(x)`?

- A) {1: 'a', 2: 'b'}
- B) {2: 'c'}
- C) KeyError: 2
- D) {1: 'a', 2: 'c'}

**Answer:** {1: 'a', 2: 'c'}

**Solution:** `update` overwrites the value for key `2` with `'c'`, giving `{1: 'a', 2: 'c'}`.

**Q9.** What is printed by this C++ loop: `int x = 5; for(int i = 0; i < 3; i++) x *= 2; cout << x;`?

- A) 20
- B) 80
- C) 40
- D) 11

**Answer:** 40

**Solution:** Doubling `x` three times in the loop gives `5 * 2 * 2 * 2 = 40`.

**Q10.** What is the output of this C code: `int a = 7, b = 3; printf("%d", a ^ b);`?

- A) 343
- B) 7
- C) 3
- D) 4

**Answer:** 4

**Solution:** `a ^ b` is a bitwise XOR: `7` (`111`) XOR `3` (`011`) gives `100`, i.e. `4`.

**Q11.** What does this Python slice return: `x = [1, 2, 3]; print(x[1:3])`?

- A) [2, 3]
- B) [1, 2]
- C) [3]
- D) [1, 2, 3]

**Answer:** [2, 3]

**Solution:** The slice `[1:3]` grabs indices `1` and `2`, giving `[2, 3]`.

**Q12.** What is printed by this Java bitwise expression: `int x = 15; System.out.println(x & (x - 1));`?

- A) 0
- B) 14
- C) 15
- D) 1

**Answer:** 14

**Solution:** `x & (x - 1)` clears the lowest set bit of `x`. `15` is `1111` and `14` is `1110`; ANDing them gives `1110`, i.e. `14`.

**Q13.** What does this C++ snippet output: `string s = "abc"; reverse(s.begin(), s.end()); cout << s;`?

- A) abc
- B) bac
- C) CBA
- D) cba

**Answer:** cba

**Solution:** `reverse` flips the string's character order in place, turning `"abc"` into `"cba"`.

**Q14.** What does this Python lambda return: `x = lambda a: a * 2; print(x(3))`?

- A) 9
- B) <function <lambda> at 0x...>
- C) 6
- D) TypeError: <lambda>() missing 1 required positional argument

**Answer:** 6

**Solution:** The lambda doubles its argument: `3 * 2 = 6`.

**Q15.** What does this C code print: `int x = 5; printf("%d", ~x);`?

- A) 5
- B) 0
- C) -6
- D) -5

**Answer:** -6

**Solution:** `~x` flips every bit of `5` (`00000101`), giving `11111010`; in two's-complement, that's `-6`.

**Q16.** What is printed by this Java shift: `int x = 8; System.out.println(x >> 1);`?

- A) 8
- B) 16
- C) 2
- D) 4

**Answer:** 4

**Solution:** `x >> 1` right-shifts `8` (`1000`) to `0100`, i.e. `4`.

**Q17.** What does this Python copy operation print: `x = [1, 2]; y = x.copy(); y[0] = 3; print(x)`?

- A) [1, 2, 1, 2]
- B) [1, 2]
- C) [2]
- D) [3, 2]

**Answer:** [1, 2]

**Solution:** `copy()` makes a shallow but independent copy, so changing `y` leaves `x` untouched: `[1, 2]`.

**Q18.** What does this C++ expression evaluate to: `int x = 3; cout << (x << 1) + (x >> 1);`?

- A) 12
- B) 8
- C) 6
- D) 7

**Answer:** 7

**Solution:** `x << 1` doubles `3` to `6`; `x >> 1` halves it (integer division) to `1`. Adding them: `6 + 1 = 7`.

**Q19.** What is the output of this C pointer arithmetic: `int arr[3] = {1, 2, 3}; printf("%d", *(arr + 1));`?

- A) 1
- B) 3
- C) 2
- D) Garbage value (undefined behavior)

**Answer:** 2

**Solution:** `*(arr + 1)` dereferences one past the array's start, landing on `arr[1]`, which is `2`.

**Q20.** What does this Python map/lambda combination produce: `x = [1, 2, 3]; print(list(map(lambda x: x**2, x)))`?

- A) <map object at 0x...>
- B) [1, 4, 9]
- C) [1, 8, 27]
- D) [2, 4, 6]

**Answer:** [1, 4, 9]

**Solution:** `map` squares every element: `1² = 1`, `2² = 4`, `3² = 9`, giving `[1, 4, 9]`.

### Data Structures

**Q21.** What's the time complexity of appending a node to the end of a singly linked list with n nodes?

- A) O(n)
- B) O(1)
- C) O(n²)
- D) O(log n)

**Answer:** O(n)

**Solution:** With no tail pointer, you have to walk the whole list to reach the end first, giving O(n).

**Q22.** Trace this Python stack sequence. What's left: `s = []; s.append(1); s.append(2); s.append(3); s.pop(); s.pop(); print(s)`?

- A) [3]
- B) [1]
- C) [1, 2, 3]
- D) [1, 2]

**Answer:** [1]

**Solution:** Pushing `1, 2, 3` then popping twice removes `3` and `2` in that order, leaving `[1]`.

**Q23.** In a doubly linked list, what's the time complexity of deleting a node once you already have a pointer to it?

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

**Answer:** O(1)

**Solution:** You just repoint the neighboring nodes' prev/next links, which is constant time: O(1).

**Q24.** Trace this queue: enqueue(1, 2, 3), dequeue(), enqueue(4), dequeue(). What's at the front now?

- A) 2
- B) 4
- C) 1
- D) 3

**Answer:** 3

**Solution:** Enqueuing `1, 2, 3` then dequeuing removes `1`; enqueuing `4` and dequeuing again removes `2`. The front is now `3`.

**Q25.** What's the search time complexity for an unbalanced binary search tree with n nodes?

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

**Answer:** O(n)

**Solution:** In the worst case the tree degenerates into something resembling a linked list, giving O(n).

**Q26.** Trace this Python deque code. What's the result: `from collections import deque; q = deque([1, 2]); q.append(3); q.popleft(); print(q)`?

- A) deque([2, 3])
- B) deque([3, 2])
- C) deque([1, 2, 3])
- D) deque([1, 2])

**Answer:** deque([2, 3])

**Solution:** Appending `3` gives `[1, 2, 3]`; `popleft()` removes the front (`1`), leaving `deque([2, 3])`.

**Q27.** What's the time complexity of inserting an element into a min-heap with n elements?

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

**Answer:** O(log n)

**Solution:** The new element is placed at the bottom and bubbled up to restore the heap property: O(log n).

**Q28.** What's the time complexity of computing the height of a binary tree?

- A) O(n²)
- B) O(1)
- C) O(log n)
- D) O(n)

**Answer:** O(n)

**Solution:** Every node has to be visited once via recursion, giving O(n).

**Q29.** What does this Python dict `.pop` call produce: `d = {'a': 1, 'b': 2}; d.pop('a'); print(d)`?

- A) {}
- B) {'b': 2}
- C) {'a': None, 'b': 2}
- D) {'a': 1}

**Answer:** {'b': 2}

**Solution:** `pop('a')` removes the key `'a'` entirely, leaving `{'b': 2}`.

**Q30.** What's the time complexity of removing the root from a max-heap with n elements?

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

**Answer:** O(log n)

**Solution:** The last element takes the root's place and is bubbled down to restore order: O(log n).

**Q31.** In a circular linked list, what's the time complexity of inserting a node right after a given one?

- A) O(n²)
- B) O(1)
- C) O(log n)
- D) O(n)

**Answer:** O(1)

**Solution:** Only the given node's and its successor's pointers need updating: O(1).

**Q32.** What does this Python set method give: `s = {1, 2, 3}; s.discard(2); print(s)`?

- A) KeyError: 2
- B) {1, 2}
- C) set()
- D) {1, 3}

**Answer:** {1, 3}

**Solution:** `discard(2)` removes `2` from the set (silently, if it weren't present), leaving `{1, 3}`.

**Q33.** In a binary search tree, what's the time complexity of locating the minimum element?

- A) O(1)
- B) O(log n) (balanced)
- C) O(log n) (always, regardless of balance)
- D) O(n)

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

**Solution:** You just keep following left children until there are none, which takes O(h), O(log n) if the tree is balanced.

**Q34.** What's the space complexity of a depth-first search over a binary tree with n nodes?

- A) O(log n) (regardless of tree shape)
- B) O(1)
- C) O(log n) (balanced)
- D) O(n)

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

**Solution:** The recursion stack grows with the tree's height, h, O(log n) in the balanced case.

**Q35.** What does this nested-list mutation print in Python: `x = [[1, 2], [3, 4]]; x[0].append(5); print(x)`?

- A) [[1, 2], [3, 4], 5]
- B) [[1, 2, 5], [3, 4]]
- C) [[1, 2], [3, 4]]
- D) [[5], [3, 4]]

**Answer:** [[1, 2, 5], [3, 4]]

**Solution:** Appending `5` onto `x[0]` turns that inner list into `[1, 2, 5]`, giving `[[1, 2, 5], [3, 4]]`.

**Q36.** What's the time complexity of a level-order (BFS) traversal of a binary tree with n nodes?

- A) O(n²)
- B) O(n log n)
- C) O(n)
- D) O(log n)

**Answer:** O(n)

**Solution:** BFS visits every node exactly once via a queue, giving O(n).

**Q37.** For a hash table using chaining, with n elements spread across m buckets, what's the average search time?

- A) O(m)
- B) O(n)
- C) O(log n)
- D) O(1) (assuming m ≈ n)

**Answer:** O(1) (assuming m ≈ n)

**Solution:** The average chain length is n/m, so search averages O(n/m), and if m scales with n, that's effectively O(1).

**Q38.** What does this Python `Counter` code output: `from collections import Counter; c = Counter([1, 2, 2, 3]); print(c[2])`?

- A) 1
- B) True
- C) KeyError: 2
- D) 2

**Answer:** 2

**Solution:** `Counter` tallies occurrences, and `2` shows up twice, so `c[2]` is `2`.

**Q39.** What's the time complexity of checking whether a binary tree is height-balanced?

- A) O(n)
- B) O(n log n)
- C) O(n²)
- D) O(log n)

**Answer:** O(n)

**Solution:** Each subtree's height needs computing and comparing, which touches every node: O(n).

**Q40.** Follow this stack sequence. What's on top: push(1, 2, 3), pop(), push(4), pop()?

- A) 3
- B) Empty stack
- C) 2
- D) 4

**Answer:** 2

**Solution:** Pushing `1, 2, 3` and popping removes `3`; pushing `4` and popping again removes `4`; what's left on top is `2`.

### Algorithms

**Q41.** What's the time complexity of merge sort on n elements?

- A) O(n)
- B) O(log n)
- C) O(n log n)
- D) O(n²)

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

**Solution:** Splitting and merging the array runs in O(n log n).

**Q42.** Trace this Python binary search function. What does it return: `def bs(arr, t): l, r = 0, len(arr)-1; while l <= r: m = (l+r)//2; if arr[m] == t: return m; elif arr[m] < t: l = m+1; else: r = m-1; return -1; print(bs([1, 2, 3, 4], 3))`?

- A) -1
- B) 3
- C) 2
- D) 1

**Answer:** 2

**Solution:** Searching `[1, 2, 3, 4]` for `3` lands on index `2`.

**Q43.** What's the space complexity of quicksort?

- A) O(log n) (average)
- B) O(n log n)
- C) O(n)
- D) O(1)

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

**Solution:** The recursion stack averages O(log n), but can degrade to O(n) in the worst case.

**Q44.** Trace this recursive C GCD function. What's printed: `int gcd(int a, int b) { if(b == 0) return a; return gcd(b, a % b); } printf("%d", gcd(48, 18));`?

- A) 30
- B) 12
- C) 144
- D) 6

**Answer:** 6

**Solution:** The Euclidean algorithm unwinds as `gcd(48,18) = gcd(18,12) = gcd(12,6) = gcd(6,0) = 6`.

**Q45.** What's the time complexity of finding all pairs in an n-element array that sum to a target value?

- A) O(n log n)
- B) O(n²)
- C) O(1)
- D) O(n) (with hash set)

**Answer:** O(n) (with hash set)

**Solution:** Using a hash set to check complements as you go gets this down to O(n); without one, it's O(n²).

**Q46.** What does this in-place sort produce in Python: `x = [4, 2, 5, 1]; x.sort(); print(x)`?

- A) [4, 2, 5, 1]
- B) [5, 4, 2, 1]
- C) [1, 2, 4, 5]
- D) None

**Answer:** [1, 2, 4, 5]

**Solution:** `sort()` reorders the list in place into ascending order: `[1, 2, 4, 5]`.

**Q47.** Using a priority queue, what's Dijkstra's algorithm's time complexity for a graph with V vertices and E edges?

- A) O(V log V)
- B) O(E log E)
- C) O(V²)
- D) O((V + E) log V)

**Answer:** O((V + E) log V)

**Solution:** The priority-queue operations dominate, giving O((V + E) log V).

**Q48.** What does this C++ rotate leave at the front: `vector<int> v = {1, 2, 3}; rotate(v.begin(), v.begin()+1, v.end()); cout << v[0];`?

- A) Undefined behavior (missing #include <algorithm>)
- B) 1
- C) 2
- D) 3

**Answer:** 2

**Solution:** `rotate` shifts the vector left by one position, turning it into `[2, 3, 1]`; the new front element is `2`.

**Q49.** What's the time complexity of insertion sort on n elements?

- A) O(n²)
- B) O(n)
- C) O(n log n)
- D) O(log n)

**Answer:** O(n²)

**Solution:** Each element is compared against and shifted past the sorted prefix, giving O(n²) overall.

**Q50.** What does this Python list comprehension produce: `x = [1, 2, 3, 4]; print([i for i in x if i % 2 == 0])`?

- A) [1, 2, 3, 4]
- B) [1, 3]
- C) []
- D) [2, 4]

**Answer:** [2, 4]

**Solution:** The comprehension keeps only the even values, giving `[2, 4]`.

**Q51.** What's the time complexity of checking whether a string of length n is a palindrome?

- A) O(n log n)
- B) O(1)
- C) O(n²)
- D) O(n)

**Answer:** O(n)

**Solution:** Comparing characters from both ends inward touches each character once: O(n).

**Q52.** Trace this recursive C Fibonacci function. What's printed: `int fib(int n) { if(n <= 1) return n; return fib(n-1) + fib(n-2); } printf("%d", fib(5));`?

- A) 5
- B) 8
- C) 3
- D) 2

**Answer:** 5

**Solution:** Unwinding the recursion: `fib(5) = fib(4) + fib(3) = (fib(3)+fib(2)) + (fib(2)+fib(1)) = (2+1) + (1+1) = 5`.

**Q53.** What's the space complexity of merge sort?

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

**Answer:** O(n)

**Solution:** It needs an auxiliary array the same size as the input while merging: O(n).

**Q54.** What does this Python code output: `x = "hello"; print(''.join(reversed(x)))`?

- A) hello
- B) olleh
- C) ehllo
- D) olle

**Answer:** olleh

**Solution:** `reversed(x)` iterates the string backward, and joining it back together gives `"olleh"`.

**Q55.** What's the time complexity of finding the longest common prefix shared by n strings of length m?

- A) O(n log m)
- B) O(m²)
- C) O(n * m)
- D) O(n + m)

**Answer:** O(n * m)

**Solution:** Comparing characters position-by-position across all the strings costs O(n * m).

**Q56.** What does this C++ pointer arithmetic print: `int arr[] = {1, 2, 3}; int *p = arr; cout << *(p + 2);`?

- A) Garbage value (out of bounds)
- B) A memory address, not a value
- C) 3
- D) 2

**Answer:** 3

**Solution:** `*(p + 2)` dereferences two past the start of the array, which is `arr[2] = 3`.

**Q57.** What's the time complexity of counting sort on n elements with value range k?

- A) O(k)
- B) O(n log n)
- C) O(n + k)
- D) O(n * k)

**Answer:** O(n + k)

**Solution:** Building the count array and writing the output both take time proportional to n and k: O(n + k).

**Q58.** What does this Python code produce: `x = [1, 2, 2, 3]; print(list(set(x)))`?

- A) [1, 2, 2, 3]
- B) [3, 2, 1]
- C) [1]
- D) [1, 2, 3]

**Answer:** [1, 2, 3]

**Solution:** Converting to a `set` drops the duplicate `2`, and converting back to a list gives `[1, 2, 3]` (order not guaranteed, but here it comes out that way).

**Q59.** What's the time complexity of detecting a cycle in a linked list?

- A) O(n²)
- B) O(1)
- C) O(log n)
- D) O(n)

**Answer:** O(n)

**Solution:** Floyd's two-pointer technique traverses the list a bounded number of times: O(n).

**Q60.** What does this C `qsort` call leave as the first element: `int arr[] = {3, 1, 4}; qsort(arr, 3, sizeof(int), [](const void* a, const void* b){return *(int*)a - *(int*)b;}); printf("%d", arr[0]);`?

- A) 4
- B) 1
- C) 3
- D) 1 3 4

**Answer:** 1

**Solution:** `qsort` sorts the array ascending into `[1, 3, 4]`, so `arr[0]` is `1`.

### Database Basics

**Q61.** What does this SQL query return: `SELECT name, salary FROM employees WHERE department = 'IT' ORDER BY salary DESC;`?

- A) All employees sorted by salary (highest first)
- B) IT employees sorted by salary (lowest first)
- C) IT employees sorted by name
- D) IT employees sorted by salary (highest first)

**Answer:** IT employees sorted by salary (highest first)

**Solution:** It pulls `name` and `salary` for IT-department employees, ordered from highest salary to lowest.

**Q62.** What does `SELECT * FROM orders INNER JOIN customers ON orders.customer_id = customers.id;` do?

- A) Returns only customers with no orders
- B) Returns only orders with no matching customer
- C) Combines all orders and all customers regardless of match
- D) Joins orders with customer details

**Answer:** Joins orders with customer details

**Solution:** It combines matching rows from `orders` and `customers` wherever `customer_id` equals `id`.

**Q63.** What does this grouped query return: `SELECT department, COUNT(*) FROM employees GROUP BY department;`?

- A) Department-wise employee counts
- B) Average salary per department
- C) Total employee count across all departments
- D) Department names only, no counts

**Answer:** Department-wise employee counts

**Solution:** It returns the number of employees in each department.

**Q64.** What does the `FOREIGN KEY` constraint enforce in SQL?

- A) Uniqueness of values
- B) Data type validation
- C) Referential integrity
- D) Preventing NULL values

**Answer:** Referential integrity

**Solution:** It ensures a column's values correspond to real primary-key values in another table: referential integrity.

**Q65.** What does `SELECT product_name FROM products WHERE price BETWEEN 50 AND 100;` return?

- A) Products priced below 50
- B) Products priced above 100
- C) Products priced exactly 50 or 100
- D) Products priced 50–100

**Answer:** Products priced 50–100

**Solution:** It returns products priced anywhere from 50 to 100, inclusive.

**Q66.** What does `SELECT DISTINCT city FROM customers;` return?

- A) The most common city
- B) All cities, including duplicates
- C) Unique cities
- D) Number of unique cities

**Answer:** Unique cities

**Solution:** It returns each distinct `city` value appearing in `customers`, with duplicates removed.

**Q67.** What does this subquery return: `SELECT name FROM students WHERE marks > (SELECT AVG(marks) FROM students);`?

- A) Students with below-average marks
- B) The single student with the highest marks
- C) Students with above-average marks
- D) All students with their average marks shown

**Answer:** Students with above-average marks

**Solution:** It returns the names of students whose marks beat the class average.

**Q68.** What does `ALTER TABLE employees ADD COLUMN email VARCHAR(100);` do?

- A) Renames a column to email
- B) Adds email column
- C) Changes the email column's data type
- D) Deletes the email column

**Answer:** Adds email column

**Solution:** It adds a new `email` column, up to 100 characters, to the `employees` table.

**Q69.** What does this left join return: `SELECT order_id, customer_name FROM orders LEFT JOIN customers ON orders.customer_id = customers.id;`?

- A) All customers with their orders (or NULL)
- B) All orders with customer names (or NULL)
- C) Only customers with no orders
- D) Only orders that have a matching customer

**Answer:** All orders with customer names (or NULL)

**Solution:** Every order is kept, with `customer_name` filled in where there's a match and `NULL` where there isn't.

**Q70.** What does `CREATE INDEX idx_name ON employees(name);` accomplish?

- A) Prevents NULL values in the name column
- B) Sorts the table permanently on disk
- C) Improves query performance
- D) Enforces uniqueness of names

**Answer:** Improves query performance

**Solution:** It builds an index on the `name` column so lookups/filters on it run faster.

### Computer Networks

**Q71.** What is the OSI model's overall purpose?

- A) Assigns IP addresses to devices
- B) Encrypts all network traffic
- C) Compresses data for faster transmission
- D) Standardizes network communication

**Answer:** Standardizes network communication

**Solution:** It's a layered reference framework standardizing how network communication is structured.

**Q72.** Which OSI layer is responsible for routing packets?

- A) Network layer
- B) Physical layer
- C) Data Link layer
- D) Transport layer

**Answer:** Network layer

**Solution:** That's the Network layer (Layer 3).

**Q73.** Which port does HTTPS traffic use?

- A) 8443
- B) 21
- C) 443
- D) 80

**Answer:** 443

**Solution:** Secure HTTP traffic goes over port `443`.

**Q74.** What problem does NAT (Network Address Translation) solve?

- A) IP address mapping
- B) Domain name resolution
- C) Data encryption
- D) Bandwidth throttling

**Answer:** IP address mapping

**Solution:** It maps private internal IP addresses to a shared public IP so devices can reach the internet.

**Q75.** How does a hub differ from a switch?

- A) Hub: broadcasts, Switch: targeted
- B) Hub: operates at Layer 3, Switch: operates at Layer 1
- C) Hub: targeted, Switch: broadcasts
- D) Hub and Switch behave identically, only speed differs

**Answer:** Hub: broadcasts, Switch: targeted

**Solution:** A hub blasts incoming data out every port; a switch is smarter and sends it only to the intended device.

**Q76.** What is a MAC address used for?

- A) Routing between networks
- B) IP address assignment
- C) Data encryption
- D) Device identification

**Answer:** Device identification

**Solution:** It uniquely identifies a device at the data-link layer.

**Q77.** What three steps make up the TCP handshake?

- A) Error correction
- B) Connection termination
- C) Connection establishment
- D) Data compression

**Answer:** Connection establishment

**Solution:** SYN, then SYN-ACK, then ACK; that sequence establishes the connection.

**Q78.** What is ICMP used for?

- A) Data encryption
- B) Routing table updates
- C) Address resolution
- D) Error reporting

**Answer:** Error reporting

**Solution:** It carries error messages and diagnostic info, such as what `ping` relies on.

**Q79.** With a subnet mask of 255.255.255.240, how many hosts can that subnet support?

- A) 14
- B) 15
- C) 16
- D) 30

**Answer:** 14

**Solution:** That mask is a `/28` (240 = `11110000`), giving 2⁴ = 16 addresses total; subtract the network and broadcast addresses and you're left with 14 usable hosts.

**Q80.** What role does BGP play in networking?

- A) Intra-domain routing
- B) Packet encryption
- C) Address translation
- D) Inter-domain routing

**Answer:** Inter-domain routing

**Solution:** Border Gateway Protocol handles routing decisions between different autonomous systems.

### Operating Systems

**Q81.** How do preemptive and non-preemptive scheduling differ?

- A) Preemptive: used only for I/O-bound processes, Non-preemptive: only for CPU-bound
- B) Preemptive: interruptible, Non-preemptive: uninterruptible
- C) Preemptive: uninterruptible, Non-preemptive: interruptible
- D) Preemptive and Non-preemptive both allow interruption, differing only in priority rules

**Answer:** Preemptive: interruptible, Non-preemptive: uninterruptible

**Solution:** Preemptive scheduling lets the CPU interrupt a running process; non-preemptive lets it run to completion first.

**Q82.** What is a semaphore used for in an operating system?

- A) Synchronization mechanism
- B) Process scheduling algorithm
- C) Memory allocation mechanism
- D) File access permission system

**Answer:** Synchronization mechanism

**Solution:** It coordinates access to shared resources so processes don't step on each other.

**Q83.** What is paging for, in memory management?

- A) Memory allocation
- B) CPU scheduling
- C) Disk defragmentation
- D) Process synchronization

**Answer:** Memory allocation

**Solution:** It breaks memory into fixed-size chunks, simplifying how allocation is handled.

**Q84.** How does a process differ from a thread?

- A) Process: shared memory, Thread: isolated
- B) Process: isolated, Thread: shared memory
- C) Process and Thread are identical in modern OSes
- D) Process: runs on one core, Thread: runs across multiple cores automatically

**Answer:** Process: isolated, Thread: shared memory

**Solution:** A process is an independent program with its own memory; a thread is a lighter-weight unit that shares its parent process's memory.

**Q85.** What is swap space used for in an OS?

- A) Extends virtual memory
- B) Stores permanent program backups
- C) Speeds up CPU processing
- D) Caches frequently accessed files

**Answer:** Extends virtual memory

**Solution:** It's disk space the OS uses to hold pages that don't currently fit in RAM.

**Q86.** What happens during a context switch?

- A) Deadlock resolution
- B) Process switching
- C) Memory compaction
- D) Thread creation

**Answer:** Process switching

**Solution:** The OS saves the current process's state and loads another's so execution can move to it.

**Q87.** What is the LRU page-replacement algorithm trying to achieve?

- A) Guarantees zero page faults
- B) Optimizes disk defragmentation
- C) Optimizes page replacement
- D) Optimizes CPU scheduling

**Answer:** Optimizes page replacement

**Solution:** It evicts whichever page hasn't been used in the longest time, aiming to minimize page faults.

**Q88.** What is a race condition?

- A) A memory leak caused by unreleased pointers
- B) A CPU scheduling starvation issue
- C) A type of deadlock
- D) Concurrent access issue

**Answer:** Concurrent access issue

**Solution:** It's what happens when multiple processes touch shared data concurrently without coordination, producing unpredictable results.

**Q89.** What does a file allocation table (FAT) do?

- A) File access permission tracking
- B) File location tracking
- C) Memory page tracking
- D) File compression tracking

**Answer:** File location tracking

**Solution:** It keeps track of where each file's data actually sits on disk.

**Q90.** What does a mutex provide in an OS?

- A) Mutual exclusion
- B) Deadlock prevention
- C) Process priority boosting
- D) Memory protection

**Answer:** Mutual exclusion

**Solution:** It enforces mutual exclusion, keeping more than one process out of a critical section at a time.

### AI/ML Foundations

**Q91.** How do classification and regression differ in ML?

- A) Classification is for supervised learning, Regression is for unsupervised learning
- B) Classification: labels, Regression: values
- C) Classification: values, Regression: labels
- D) Classification and Regression both predict continuous values, differing only in the algorithm used

**Answer:** Classification: labels, Regression: values

**Solution:** Classification predicts a discrete category; regression predicts a continuous numeric value.

**Q92.** Why use cross-validation when evaluating an ML model?

- A) Faster model training
- B) Robust model evaluation
- C) Automatic feature selection
- D) Guaranteed prevention of overfitting

**Answer:** Robust model evaluation

**Solution:** Splitting the data into multiple folds gives a more robust read on how the model actually generalizes.

**Q93.** What is the bias-variance tradeoff about?

- A) Balances precision and recall
- B) Balances model size and memory usage
- C) Balances underfitting and overfitting
- D) Balances training time and accuracy

**Answer:** Balances underfitting and overfitting

**Solution:** High bias tends toward underfitting, high variance toward overfitting; good models balance the two.

**Q94.** What does the learning rate control in gradient descent?

- A) Step size control
- B) Regularization strength
- C) Number of training epochs
- D) Number of hidden layers

**Answer:** Step size control

**Solution:** It sets how large each parameter update step is during optimization.

**Q95.** Why add regularization to an ML model?

- A) Speeds up convergence
- B) Reduces the number of features automatically
- C) Prevents overfitting
- D) Increases model capacity

**Answer:** Prevents overfitting

**Solution:** It penalizes excessive model complexity, which helps guard against overfitting.

**Q96.** How does a perceptron differ from a multi-layer perceptron (MLP)?

- A) Perceptron is used for regression only, MLP is used for classification only
- B) Perceptron: single, MLP: multiple layers
- C) Perceptron and MLP are the same, differing only in name
- D) Perceptron: multiple layers, MLP: single layer

**Answer:** Perceptron: single, MLP: multiple layers

**Solution:** A perceptron is a single layer; an MLP stacks multiple layers, letting it capture non-linear relationships.

**Q97.** What does the softmax function do in a neural network?

- A) Weight initialization
- B) Gradient computation
- C) Probability conversion
- D) Loss calculation

**Answer:** Probability conversion

**Solution:** It converts raw output scores (logits) into probabilities across classes.

**Q98.** What does the parameter k control in k-nearest neighbors?

- A) Neighbor count
- B) Distance metric type
- C) Number of output classes
- D) Number of training iterations

**Answer:** Neighbor count

**Solution:** It's how many nearby neighbors get considered when making a prediction.

**Q99.** How do bagging and boosting differ as ensemble techniques?

- A) Bagging: parallel, Boosting: sequential
- B) Bagging: sequential, Boosting: parallel
- C) Bagging is for classification only, Boosting is for regression only
- D) Bagging and Boosting both train models sequentially, differing only in the loss function

**Answer:** Bagging: parallel, Boosting: sequential

**Solution:** Bagging trains models in parallel and combines them (e.g. Random Forest); boosting trains them sequentially, each correcting the last (e.g. AdaBoost).

**Q100.** What is PCA used for in machine learning?

- A) Feature scaling
- B) Data augmentation
- C) Dimensionality reduction
- D) Missing value imputation

**Answer:** Dimensionality reduction

**Solution:** It reduces a dataset's dimensionality by projecting it onto its principal components.

## Advanced level

### Programming Fundamentals

**Q1.** Trace this C pointer code. What's printed: `int x = 5; int *p = &x; *p += 2; printf("%d %d", x, *p);`?

- A) 5 7
- B) 5 5
- C) 7 5
- D) 7 7

**Answer:** 7 7

**Solution:** `p` points at `x`, so `*p += 2` changes the same memory `x` occupies, bumping it to `7`. Both `x` and `*p` refer to that same value, so both print `7`.

**Q2.** What does this Python list-of-lists code output: `x = [[0]*2]*3; x[0][0] = 1; print(x)`?

- A) [[1, 0], [1, 0], [1, 0]]
- B) [[1, 0], [0, 0], [0, 0]]
- C) [[0, 0], [0, 0], [0, 0]]
- D) [[1, 0]]

**Answer:** [[1, 0], [1, 0], [1, 0]]

**Solution:** `[[0]*2]*3` doesn't make three independent inner lists; it repeats a reference to the *same* one three times. Changing `x[0][0]` therefore shows up in every row: `[[1, 0], [1, 0], [1, 0]]`.

**Q3.** What does this Java comparison print: `String s1 = new String("test"); String s2 = new String("test"); System.out.println(s1 == s2);`?

- A) true
- B) false
- C) Compilation error
- D) Runtime exception (NullPointerException)

**Answer:** false

**Solution:** `==` on objects compares references, not contents. `new String(...)` always allocates a fresh object, so `s1` and `s2` point at different objects: `false`.

**Q4.** What does this C++ lambda-capture code print: `int x = 10; auto f = [&x]() { x += 5; return x; }; cout << f() << " " << x;`?

- A) 10 15
- B) 15 15
- C) 10 10
- D) 15 10

**Answer:** 15 15

**Solution:** The lambda captures `x` by reference, so calling `f()` mutates the outer `x` directly, bumping it to `15` and returning that. Printing `x` afterward also shows `15`.

**Q5.** What does this Python default-argument code print: `def f(x=[]): x.append(1); return x; print(f(), f())`?

- A) [1] [1]
- B) [] [1]
- C) [1] [1, 1]
- D) [1, 1] [1, 1]

**Answer:** [1] [1, 1]

**Solution:** A mutable default argument is created once and reused across calls. The first call to `f()` leaves the default list as `[1]`; the second call appends onto that *same* list, giving `[1, 1]`. Output: `[1] [1, 1]`.

**Q6.** What does this C void-pointer code print: `int x = 5; void *p = &x; printf("%d", *(int*)p);`?

- A) Compilation error
- B) Address value (memory address printed)
- C) 5
- D) Garbage value

**Answer:** 5

**Solution:** `p` holds the address of `x` as a generic pointer; casting it back to `int*` and dereferencing recovers `5`.

**Q7.** What does this Java boxed-integer comparison print: `Integer a = 127; Integer b = 127; System.out.println(a == b);`?

- A) Compilation error
- B) It depends on JVM implementation
- C) false
- D) true

**Answer:** true

**Solution:** Java caches boxed `Integer` values from `-128` to `127`, so `a` and `b` both reference the same cached object here: `true`.

**Q8.** What does this Python shallow-copy code print: `x = {1: [1], 2: [2]}; y = x.copy(); y[1].append(3); print(x[1])`?

- A) [1, 3]
- B) [1, 2, 3]
- C) [3]
- D) [1]

**Answer:** [1, 3]

**Solution:** `copy()` only copies the top level; the inner lists are still shared. Appending to `y[1]` is really appending to the same list `x[1]` points at: `[1, 3]`.

**Q9.** What does this C++ pointer-arithmetic code print: `int arr[] = {1, 2, 3}; int *p = arr; cout << *(p + 1) * *(p + 2);`?

- A) 2
- B) 5
- C) 6
- D) 9

**Answer:** 6

**Solution:** `*(p + 1)` is `arr[1] = 2` and `*(p + 2)` is `arr[2] = 3`; multiplying gives `6`.

**Q10.** What does this C union code print: `union U { int x; char c; } u; u.x = 258; printf("%d", u.c);`?

- A) 0
- B) 2
- C) 1
- D) 258

**Answer:** 2

**Solution:** A union shares one block of memory across its members. `258` in binary is `00000001 00000010`; reading just the first byte through `c` recovers `2`.

**Q11.** What does this Python `reduce` call output: `from functools import reduce; print(reduce(lambda x, y: x + y, [1, 2, 3], 0))`?

- A) 3
- B) 0
- C) 6
- D) 5

**Answer:** 6

**Solution:** `reduce` folds the list with `+`, starting from `0`: `((0 + 1) + 2) + 3 = 6`.

**Q12.** What does this Java try/catch/finally block print: `try { throw new Exception("Error"); } catch (Exception e) { System.out.println("Caught"); } finally { System.out.println("Finally"); }`?

- A) Finally Caught
- B) Error Finally
- C) Caught Finally
- D) Caught

**Answer:** Caught Finally

**Solution:** The exception is caught, printing `Caught`; `finally` runs regardless afterward, printing `Finally`.

**Q13.** What does this C++ `transform` code print: `vector<int> v = {1, 2, 3}; transform(v.begin(), v.end(), v.begin(), [](int x) { return x * x; }); cout << v[1];`?

- A) 9
- B) 1
- C) 2
- D) 4

**Answer:** 4

**Solution:** `transform` squares every element in place, turning `v` into `[1, 4, 9]`; `v[1]` is `4`.

**Q14.** What does this Python iterator code print: `x = [1, 2, 3]; y = iter(x); next(y); print(next(y))`?

- A) None
- B) 2
- C) 1
- D) 3

**Answer:** 2

**Solution:** The first `next(y)` consumes `1` (its result is discarded); the second `next(y)`, which is printed, returns `2`.

**Q15.** What does this C code print: `int x = 5; int y = x++ + ++x; printf("%d %d", x, y);`?

- A) 7 11
- B) 6 12
- C) 6 11
- D) 7 12 (compiler-dependent)

**Answer:** 7 12 (compiler-dependent)

**Solution:** Modifying `x` more than once between sequence points here is undefined behavior in C; the actual result depends on the compiler. A common outcome is `x` ending at `7` and `y` at `12` (5 + 7), but this isn't guaranteed.

**Q16.** What does this Java `replaceAll` code print: `List<Integer> list = Arrays.asList(1, 2, 3); list.replaceAll(x -> x + 1); System.out.println(list);`?

- A) UnsupportedOperationException
- B) [2, 4, 6]
- C) [1, 2, 3]
- D) [2, 3, 4]

**Answer:** [2, 3, 4]

**Solution:** `replaceAll` adds `1` to every element in place, turning the list into `[2, 3, 4]`.

**Q17.** What does this Python `deepcopy` code print: `import copy; x = [[1], [2]]; y = copy.deepcopy(x); y[0].append(3); print(x)`?

- A) [[1], [2], [3]]
- B) [[1, 3], [2]]
- C) [[1, 3], [2, 3]]
- D) [[1], [2]]

**Answer:** [[1], [2]]

**Solution:** `deepcopy` recursively copies everything, so `y` and `x` share nothing. Modifying `y` leaves `x` unchanged: `[[1], [2]]`.

**Q18.** What does this C++ reference-capturing `std::function` print: `int x = 5; function<int(int)> f = [&](int a) { x += a; return x; }; cout << f(3);`?

- A) 11
- B) 3
- C) 8
- D) 5

**Answer:** 8

**Solution:** The lambda captures `x` by reference, so `f(3)` adds `3` onto the outer `x` (making it `8`) and returns that.

**Q19.** What does this C struct code print: `struct S { int x; char c; } s = {10, 'A'}; printf("%d %c", s.x, s.c);`?

- A) 0 A
- B) A 10
- C) 10 65
- D) 10 A

**Answer:** 10 A

**Solution:** `s.x` is `10` and `s.c` is `'A'`, so both print as given.

**Q20.** What does this Python `filter` code print: `x = [1, 2, 3]; print(list(filter(lambda x: x % 2 == 1, x)))`?

- A) [1, 3]
- B) [2]
- C) [1, 2, 3]
- D) []

**Answer:** [1, 3]

**Solution:** The filter keeps only the odd values from `x`: `[1, 3]`.

### Data Structures

**Q21.** For a binary search tree with n nodes, what's the time complexity of finding the lowest common ancestor?

- A) O(n)
- B) O(1)
- C) O(n log n)
- D) O(log n) (balanced)

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

**Solution:** Comparing node values while walking down from the root takes O(h) steps, O(log n) if the tree is balanced.

**Q22.** Trace this simplified Python tree-insertion code. What's printed: `class Node: def __init__(self, val): self.val = val; self.left = self.right = None; root = Node(10); root.left = Node(5); root.right = Node(15); root.right.right = Node(20); print(root.right.right.val)`?

- A) 15
- B) 20
- C) 10
- D) None

**Answer:** 20

**Solution:** The tree built here is `10 -> 15 -> 20` along the right spine, so `root.right.right.val` is `20`.

**Q23.** What's the time complexity of heapifying an n-element array into a binary heap?

- A) O(n²)
- B) O(n log n)
- C) O(log n)
- D) O(n)

**Answer:** O(n)

**Solution:** Building bottom-up rather than inserting one at a time brings this down to O(n).

**Q24.** For a graph with V vertices and E edges, what's the time complexity of cycle detection via DFS?

- A) O(E log V)
- B) O(V + E)
- C) O(V * E)
- D) O(V²)

**Answer:** O(V + E)

**Solution:** DFS visits every vertex and edge once: O(V + E).

**Q25.** What does this Python `defaultdict` code print: `from collections import defaultdict; d = defaultdict(list); d[1].append(2); d[1].append(3); print(d)`?

- A) {1: [2, 3]}
- B) defaultdict(<class 'list'>, {1: [2, 3]})
- C) [2, 3]
- D) defaultdict(<class 'list'>, {1: [2, 3], 2: []})

**Answer:** defaultdict(<class 'list'>, {1: [2, 3]})

**Solution:** `defaultdict(list)` auto-creates an empty list for a missing key, so appending builds `d[1]` up to `[2, 3]`.

**Q26.** What's the time complexity of finding the shortest path in an unweighted graph via BFS?

- A) O(V + E)
- B) O(E log E)
- C) O(V log V)
- D) O(V²)

**Answer:** O(V + E)

**Solution:** BFS still touches every vertex and edge once: O(V + E).

**Q27.** In a trie holding n words with average length k, what's the time complexity of searching for one word?

- A) O(log n)
- B) O(k)
- C) O(n)
- D) O(n * k)

**Answer:** O(k)

**Solution:** Searching only walks down one character path, proportional to the word's own length: O(k).

**Q28.** Trace this Python linked-list code. What's printed: `class Node: def __init__(self, val): self.val = val; self.next = None; head = Node(1); head.next = Node(2); head.next.next = Node(3); print(head.next.next.val)`?

- A) 2
- B) 1
- C) None
- D) 3

**Answer:** 3

**Solution:** The list built here is `1 -> 2 -> 3`, so `head.next.next.val` is `3`.

**Q29.** For Kruskal's minimum spanning tree algorithm on a graph with V vertices and E edges, what's the time complexity?

- A) O(E log V)
- B) O(V²)
- C) O(V log V)
- D) O(E log E)

**Answer:** O(E log V)

**Solution:** Sorting the edges costs O(E log E), and union-find operations add roughly O(E log V) more; the total is O(E log V).

**Q30.** For a segment tree over n elements supporting range-sum queries, what's the time complexity of a single query?

- A) O(n)
- B) O(n log n)
- C) O(log n)
- D) O(sqrt(n))

**Answer:** O(log n)

**Solution:** A query walks down the tree's height: O(log n).

**Q31.** Trace this Python min-heap code. What's printed: `from heapq import heappush, heappop; h = []; heappush(h, 3); heappush(h, 1); heappush(h, 2); print(heappop(h))`?

- A) None
- B) 1
- C) 3
- D) 2

**Answer:** 1

**Solution:** After pushing `3`, `1`, and `2`, the heap's smallest element is `1`, which `heappop` returns.

**Q32.** What's the time complexity of deleting a node from a red-black tree with n nodes?

- A) O(log n)
- B) O(n)
- C) O(1)
- D) O(log n) amortized

**Answer:** O(log n)

**Solution:** Rebalancing after the deletion still bounds the operation at O(log n).

**Q33.** For a weighted graph, what's the time complexity of the Bellman-Ford single-source shortest-path algorithm?

- A) O(V²)
- B) O(V * E)
- C) O(E log V)
- D) O(V + E)

**Answer:** O(V * E)

**Solution:** It relaxes every edge across V-1 rounds: O(V * E).

**Q34.** Trace this Python BFS code. How many nodes get visited: `from collections import deque; g = {1: [2, 3], 2: [4], 3: [4], 4: []}; q = deque([1]); visited = {1}; while q: n = q.popleft(); for nei in g[n]: if nei not in visited: visited.add(nei); q.append(nei); print(len(visited))`?

- A) 2
- B) 4
- C) 3
- D) 5

**Answer:** 4

**Solution:** Starting from node `1`, the BFS reaches every node in this connected graph (`1, 2, 3, 4`), so `len(visited)` is `4`.

**Q35.** What's the space complexity of storing a sparse graph with V vertices and E edges?

- A) O(V²)
- B) O(V + E)
- C) O(E)
- D) O(V * E)

**Answer:** O(V + E)

**Solution:** An adjacency-list representation only stores what's actually present: O(V + E).

**Q36.** In a B-tree of order m holding n keys, what's the time complexity of a search?

- A) O(n)
- B) O(n log n)
- C) O(log n)
- D) O(m log n)

**Answer:** O(log n)

**Solution:** The search follows the tree's height: O(log_m n).

**Q37.** Trace this Python tuple sort. What's the result: `x = [(1, 'a'), (2, 'b'), (1, 'c')]; x.sort(); print(x)`?

- A) [(1, 'a'), (2, 'b'), (1, 'c')]
- B) [(1, 'c'), (1, 'a'), (2, 'b')]
- C) [(2, 'b'), (1, 'a'), (1, 'c')]
- D) [(1, 'a'), (1, 'c'), (2, 'b')]

**Answer:** [(1, 'a'), (1, 'c'), (2, 'b')]

**Solution:** Tuples sort lexicographically, by first element and then second: `[(1, 'a'), (1, 'c'), (2, 'b')]`.

**Q38.** What's the time complexity of Kosaraju's algorithm for finding strongly connected components?

- A) O(V + E)
- B) O(V * E)
- C) O((V + E) log V)
- D) O(V log V)

**Answer:** O(V + E)

**Solution:** It runs two DFS passes plus a graph transpose, all linear in size: O(V + E).

**Q39.** In a suffix tree built over a string of length n, what's the time complexity of checking whether a substring of length m exists?

- A) O(m)
- B) O(log m)
- C) O(n + m)
- D) O(n)

**Answer:** O(m)

**Solution:** Following the path matching the substring's characters takes O(m).

**Q40.** Trace this Python `OrderedDict` code. What order do the keys end up in: `from collections import OrderedDict; d = OrderedDict([(1, 'a'), (2, 'b')]); d.move_to_end(1); print(list(d.keys()))`?

- A) [2]
- B) [1, 2, 1]
- C) [2, 1]
- D) [1, 2]

**Answer:** [2, 1]

**Solution:** `move_to_end(1)` relocates key `1` to the back, giving key order `[2, 1]`.

### Algorithms

**Q41.** Using dynamic programming, what's the time complexity of the 0/1 knapsack problem for n items and capacity W?

- A) O(n log n)
- B) O(2^n)
- C) O(n + W)
- D) O(n * W)

**Answer:** O(n * W)

**Solution:** The DP table has n rows and W columns, giving O(n * W).

**Q42.** Trace this Python longest-common-subsequence function. What does it return for `"ABC"` and `"AC"`: `def lcs(s1, s2): m, n = len(s1), len(s2); dp = [[0]*(n+1) for _ in range(m+1)]; for i in range(1, m+1): for j in range(1, n+1): if s1[i-1] == s2[j-1]: dp[i][j] = dp[i-1][j-1] + 1; else: dp[i][j] = max(dp[i-1][j], dp[i][j-1]); return dp[m][n]; print(lcs("ABC", "AC"))`?

- A) 3
- B) 1
- C) 2
- D) 0

**Answer:** 2

**Solution:** The longest common subsequence of `"ABC"` and `"AC"` is `"AC"`, length `2`.

**Q43.** Using dynamic programming, what's the time complexity of matrix chain multiplication over n matrices?

- A) O(2^n)
- B) O(n³)
- C) O(n log n)
- D) O(n²)

**Answer:** O(n³)

**Solution:** The DP considers every possible split point across all subproblems: O(n³).

**Q44.** Trace this C++ sliding-window-maximum code. What's the final answer: `vector<int> v = {3, 1, 4, 1, 5}; int k = 2; multiset<int> s(v.begin(), v.begin()+k); int ans = *s.rbegin(); for(int i = k; i < v.size(); i++) { s.erase(s.find(v[i-k])); s.insert(v[i]); ans = max(ans, *s.rbegin()); } cout << ans;`?

- A) 1
- B) 3
- C) 4
- D) 5

**Answer:** 4

**Solution:** Sliding a window of size 2 across the array gives windows `[3,1]`, `[1,4]`, `[4,1]`, `[1,5]`, whose maxima top out at `4`.

**Q45.** For an all-pairs shortest-path computation via Floyd-Warshall on a graph with V vertices, what's the time complexity?

- A) O(V²)
- B) O(V * E)
- C) O(V² log V)
- D) O(V³)

**Answer:** O(V³)

**Solution:** Three nested loops over the vertices give O(V³).

**Q46.** Trace this Python Kadane's-algorithm function. What does it return for `[-2, 1, -3, 4, -1, 2, 1]`: `def kadane(arr): max_so_far = max_ending_here = arr[0]; for x in arr[1:]: max_ending_here = max(x, max_ending_here + x); max_so_far = max(max_so_far, max_ending_here); return max_so_far; print(kadane([-2, 1, -3, 4, -1, 2, 1]))`?

- A) 6
- B) 2
- C) 4
- D) 7

**Answer:** 6

**Solution:** The best contiguous subarray here is `[4, -1, 2, 1]`, summing to `6`.

**Q47.** Given two sorted arrays of size n each, what's the time complexity of finding their combined median?

- A) O(log n)
- B) O(n log n)
- C) O(n)
- D) O(n²)

**Answer:** O(log n)

**Solution:** A binary search over the partition point gets this down to O(log n).

**Q48.** Trace this C KMP-prefix-table code. What value ends up at `lps[5]`: `void computeLPS(char *pat, int m, int *lps) { int len = 0, i = 1; lps[0] = 0; while(i < m) { if(pat[i] == pat[len]) { len++; lps[i++] = len; } else if(len > 0) len = lps[len-1]; else lps[i++] = 0; } } int lps[6]; computeLPS("AABAAC", 6, lps); printf("%d", lps[5]);`?

- A) 2
- B) 3
- C) 0
- D) 1

**Answer:** 0

**Solution:** The full LPS array computed for `"AABAAC"` is `[0, 1, 0, 1, 2, 0]`, so `lps[5]` is `0`.

**Q49.** What's the time complexity of A* search on a graph, in terms of branching factor b and search depth d?

- A) O(b*d)
- B) O(b^d)
- C) O(d^b)
- D) O(d log b)

**Answer:** O(b^d)

**Solution:** It depends heavily on the heuristic, but in the general case it's O(b^d).

**Q50.** Trace this Python edit-distance function. What does it return for `"cat"` to `"cut"`: `def edit_distance(s1, s2): m, n = len(s1), len(s2); dp = [[0]*(n+1) for _ in range(m+1)]; for i in range(m+1): dp[i][0] = i; for j in range(n+1): dp[0][j] = j; for i in range(1, m+1): for j in range(1, n+1): if s1[i-1] == s2[j-1]: dp[i][j] = dp[i-1][j-1]; else: dp[i][j] = min(dp[i-1][j], dp[i][j-1], dp[i-1][j-1]) + 1; return dp[m][n]; print(edit_distance("cat", "cut"))`?

- A) 1
- B) 2
- C) 0
- D) 3

**Answer:** 1

**Solution:** Only one substitution (swapping `a` for `u`) is needed to turn `"cat"` into `"cut"`, so the edit distance is `1`.

**Q51.** Using dynamic programming, what's the time complexity of finding the longest palindromic substring?

- A) O(n)
- B) O(n³)
- C) O(2^n)
- D) O(n²)

**Answer:** O(n²)

**Solution:** The DP fills a table over all substrings: O(n²).

**Q52.** Trace this C++ grid-paths DP code. What's the final value: `int n = 5; vector<vector<int>> dp(n+1, vector<int>(n+1)); for(int i = 0; i <= n; i++) dp[i][0] = dp[0][i] = 1; for(int i = 1; i <= n; i++) for(int j = 1; j <= n; j++) dp[i][j] = dp[i-1][j] + dp[i][j-1]; cout << dp[n][n];`?

- A) 210
- B) 252
- C) 120
- D) 126

**Answer:** 252

**Solution:** This DP counts lattice paths in a 5x5 grid, which works out to the binomial coefficient `dp[5][5] = 252`.

**Q53.** What's the space complexity of the Rabin-Karp string-matching algorithm?

- A) O(m)
- B) O(1)
- C) O(n)
- D) O(n*m)

**Answer:** O(1)

**Solution:** Beyond the rolling hash and pattern itself, it needs no extra structures that grow with input size: O(1).

**Q54.** Trace this Python max-profit DP function. What does it return for `[7, 1, 5, 3, 6, 4]`: `def max_profit(prices): n = len(prices); if n < 2: return 0; dp = [0]*n; min_price = prices[0]; for i in range(1, n): min_price = min(min_price, prices[i]); dp[i] = max(dp[i-1], prices[i] - min_price); return dp[n-1]; print(max_profit([7, 1, 5, 3, 6, 4]))`?

- A) 6
- B) 5
- C) 1
- D) 3

**Answer:** 5

**Solution:** Buying at the low of `1` and selling at the later high of `6` gives the best profit: `5`.

**Q55.** Using Graham's scan, what's the time complexity of computing the convex hull of n points?

- A) O(n log n)
- B) O(n)
- C) O(n log h)
- D) O(n²)

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

**Solution:** Sorting the points costs O(n log n), and the scan itself is O(n), so the total is O(n log n).

**Q56.** Trace this C Catalan-number DP code. What's the final value: `int n = 4; int dp[5]; dp[0] = 1; for(int i = 1; i <= n; i++) { dp[i] = 0; for(int j = 0; j < i; j++) dp[i] += dp[j] * dp[i-j-1]; } printf("%d", dp[n]);`?

- A) 5
- B) 16
- C) 14
- D) 42

**Answer:** 14

**Solution:** This is the Catalan-number recurrence; for `n = 4` it works out to `dp[4] = 14` (the count of distinct BSTs on 4 nodes).

**Q57.** For bipartite matching with n vertices, what's the time complexity of the Hungarian algorithm?

- A) O(n³)
- B) O(n²)
- C) O(n² log n)
- D) O(2^n)

**Answer:** O(n³)

**Solution:** Framed as a max-flow problem, it runs in O(n³).

**Q58.** Trace this Python inversion-counting code (merge-sort based). How many inversions does it find in `[3, 1, 2]`: `def count_inversions(arr): def merge_and_count(l, r): inv = 0; res = []; i = j = 0; while i < len(l) and j < len(r): if l[i] <= r[j]: res.append(l[i]); i += 1; else: res.append(r[j]); inv += len(l)-i; j += 1; res.extend(l[i:]); res.extend(r[j:]); return res, inv; def sort_and_count(arr): if len(arr) <= 1: return arr, 0; mid = len(arr)//2; l, inv_l = sort_and_count(arr[:mid]); r, inv_r = sort_and_count(arr[mid:]); merged, inv_m = merge_and_count(l, r); return merged, inv_l + inv_r + inv_m; _, inv = sort_and_count([3, 1, 2]); print(inv)`?

- A) 1
- B) 0
- C) 3
- D) 2

**Answer:** 2

**Solution:** The out-of-order pairs in `[3, 1, 2]` are `(3,1)` and `(3,2)`: two inversions total.

**Q59.** Given two sorted arrays of sizes m and n, what's the time complexity of finding the k-th smallest element across both?

- A) O(log(m + n))
- B) O(m + n)
- C) O(log(min(m, n)))
- D) O(log m * log n)

**Answer:** O(log(min(m, n)))

**Solution:** Binary searching over the partition point gives O(log(min(m, n))).

**Q60.** Trace this C++ partition-counting DP code. What's the final value: `int n = 3; vector<int> dp(n+1); dp[0] = 1; for(int i = 1; i <= n; i++) for(int j = 1; j <= i; j++) dp[i] += dp[i-j]; cout << dp[n];`?

- A) 4
- B) 3
- C) 2
- D) 8

**Answer:** 4

**Solution:** This counts ways to write `n` as an ordered sum of positive integers; for `n = 3` that comes out to `4` (1+1+1, 1+2, 2+1, 3).

### Database Basics

**Q61.** What does this joined/grouped/filtered SQL query return: `SELECT d.department_name, AVG(e.salary) FROM employees e JOIN departments d ON e.department_id = d.id GROUP BY d.department_name HAVING COUNT(e.id) > 5 ORDER BY AVG(e.salary) DESC;`?

- A) Department names and average salaries for departments with >5 employees, sorted low to high
- B) Department names and total salaries for departments with >5 employees
- C) Department names and average salaries for departments with >5 employees, sorted high to low
- D) Department names and average salaries for all departments, sorted high to low

**Answer:** Department names and average salaries for departments with >5 employees, sorted high to low

**Solution:** It joins employees to their departments, computes each department's average salary, keeps only departments with more than 5 employees, and sorts by average salary from highest to lowest.

**Q62.** What does this left-joined, grouped query return: `SELECT c.customer_name, COUNT(o.order_id) FROM customers c LEFT JOIN orders o ON c.id = o.customer_id GROUP BY c.customer_name;`?

- A) Customer names and their order counts, excluding customers with zero orders
- B) Customer names and their total order amounts
- C) Customer names and their order counts
- D) Order IDs grouped by customer

**Answer:** Customer names and their order counts

**Solution:** It counts each customer's orders, including customers who have placed none, thanks to the left join.

**Q63.** What does this correlated subquery return: `SELECT product_name, price FROM products WHERE price > (SELECT AVG(price) FROM products WHERE category = products.category);`?

- A) Products above the overall average price across all categories
- B) All products along with their category's average price
- C) Products below category average price
- D) Products above category average price

**Answer:** Products above category average price

**Solution:** It returns products priced above the average price within their own category.

**Q64.** What does this trigger do: `CREATE TRIGGER update_stock AFTER INSERT ON orders FOR EACH ROW UPDATE products SET stock = stock - NEW.quantity WHERE id = NEW.product_id;`?

- A) Increases product stock on order insertion
- B) Updates product stock on order deletion
- C) Updates product stock on order insertion
- D) Validates stock availability before an order insertion

**Answer:** Updates product stock on order insertion

**Solution:** Whenever a new order row is inserted, it automatically decrements that product's `stock` by the ordered `quantity`.

**Q65.** What does this self-referencing subquery return: `SELECT e1.name FROM employees e1 WHERE e1.salary > (SELECT AVG(e2.salary) FROM employees e2 WHERE e2.manager_id = e1.id);`?

- A) Employees earning above their team’s average
- B) Employees earning below their team's average
- C) Managers earning above the company-wide average salary
- D) All employees along with their team's average salary

**Answer:** Employees earning above their team’s average

**Solution:** It returns managers whose own salary exceeds the average salary of the people reporting to them.

**Q66.** What does `EXPLAIN SELECT * FROM orders WHERE customer_id = 100;` give you?

- A) Validates the SQL syntax only
- B) Returns the number of matching rows
- C) Shows query plan
- D) Returns all matching order rows

**Answer:** Shows query plan

**Solution:** It shows the database's execution plan for that query: how it intends to fetch the data, not the data itself.

**Q67.** What does this UNION query return: `SELECT category, MAX(price) FROM products GROUP BY category UNION SELECT 'Total', MAX(price) FROM products;`?

- A) Category max prices and overall max price
- B) Category max prices only, without an overall total
- C) All products' prices grouped by category
- D) Category min and max prices

**Answer:** Category max prices and overall max price

**Solution:** It lists each category's highest price, plus one extra row for the overall highest price labeled `'Total'`.

**Q68.** What does `ALTER TABLE employees ADD CONSTRAINT unique_email UNIQUE (email);` enforce?

- A) Creates an index on email for faster lookups
- B) Requires the email column to be non-null
- C) Enforces unique emails
- D) Sets email as the primary key

**Answer:** Enforces unique emails

**Solution:** It adds a uniqueness constraint on `email`, blocking any duplicate values going forward.

**Q69.** What does this `EXISTS` query return: `SELECT name FROM students s WHERE EXISTS (SELECT 1 FROM courses c WHERE c.student_id = s.id AND c.grade = 'A');`?

- A) Students with A-grade courses
- B) Students with all A-grade courses
- C) Courses that have at least one A-grade student
- D) Students with no A-grade courses

**Answer:** Students with A-grade courses

**Solution:** It returns students who have at least one course graded `'A'`.

**Q70.** What does `CREATE VIEW high_salary AS SELECT name, salary FROM employees WHERE salary > 100000;` set up?

- A) Creates high-salary view
- B) Deletes low-salary employee records
- C) Creates an index on employees filtered by salary
- D) Creates a high-salary table with a copy of the data

**Answer:** Creates high-salary view

**Solution:** It defines a reusable virtual table showing employees earning over 100000.

### Computer Networks

**Q71.** What is the Transport layer's job in the OSI model?

- A) Routing packets between networks
- B) Establishing physical connections
- C) Physical addressing and framing
- D) Reliable data transfer

**Answer:** Reliable data transfer

**Solution:** It's responsible for reliable end-to-end delivery, including flow control and error correction.

**Q72.** What does IPSec provide for network security?

- A) Assigns secure dynamic IP addresses
- B) Secures IP communication
- C) Secures only application-layer traffic
- D) Encrypts DNS queries only

**Answer:** Secures IP communication

**Solution:** It encrypts and authenticates traffic at the IP layer.

**Q73.** How does SCTP differ from TCP?

- A) TCP: single stream, SCTP: multi-stream
- B) TCP: multi-homing, SCTP: single-homing
- C) TCP: multi-stream, SCTP: single stream
- D) TCP: connectionless, SCTP: connection-oriented

**Answer:** TCP: single stream, SCTP: multi-stream

**Solution:** TCP is a single reliable stream; SCTP supports multiple streams and multi-homing.

**Q74.** What is DHCP responsible for?

- A) Domain name resolution
- B) IP address assignment
- C) Encrypting network traffic
- D) Routing table management

**Answer:** IP address assignment

**Solution:** It dynamically hands out IP addresses to devices as they join the network.

**Q75.** What is the TTL field in an IP header for?

- A) Tracks packet arrival order
- B) Encrypts packet payloads
- C) Prevents routing loops
- D) Specifies the packet's priority level

**Answer:** Prevents routing loops

**Solution:** It caps how long a packet can keep hopping through the network, getting decremented at each hop to prevent infinite loops.

**Q76.** How do stateful and stateless firewalls differ?

- A) Stateful and stateless firewalls both track connections identically
- B) Stateful: connection-aware, Stateless: rule-based
- C) Stateful: rule-based, Stateless: connection-aware
- D) Stateful: application-layer only, Stateless: network-layer only

**Answer:** Stateful: connection-aware, Stateless: rule-based

**Solution:** A stateful firewall tracks ongoing connections; a stateless one just filters packets against fixed rules.

**Q77.** What triggers the TCP RST flag?

- A) Connection reset
- B) Acknowledgment of received data
- C) Graceful connection close
- D) Start of a new connection handshake

**Answer:** Connection reset

**Solution:** It resets a connection, typically in response to an error or an invalid segment.

**Q78.** What does SNMP do for network management?

- A) Secure remote login to devices
- B) File transfer between network devices
- C) Automatic IP address assignment
- D) Network monitoring

**Answer:** Network monitoring

**Solution:** It lets administrators monitor and manage devices across the network.

**Q79.** With 100 Mbps of bandwidth, a 10 ms RTT, and a TCP window of 64 KB, what's the maximum achievable throughput?

- A) 100 Mbps
- B) 52.4 Mbps
- C) 51.2 Mbps
- D) 6.4 Mbps

**Answer:** 51.2 Mbps

**Solution:** Throughput works out to window size divided by RTT: `(64 * 1024 * 8) / (10 / 1000) = 51.2 Mbps`.

**Q80.** Why use VLAN tagging on Ethernet networks?

- A) Separates VLAN traffic
- B) Assigns IP addresses to switch ports
- C) Increases raw link bandwidth
- D) Encrypts traffic between switches

**Answer:** Separates VLAN traffic

**Solution:** It marks frames with an identifier so traffic on different virtual LANs stays logically separated.

### Operating Systems

**Q81.** How does a spinlock differ from a semaphore?

- A) Spinlock and semaphore are functionally identical
- B) Spinlock: kernel-only, Semaphore: user-only
- C) Spinlock: busy-wait, Semaphore: blocking
- D) Spinlock: blocking, Semaphore: busy-wait

**Answer:** Spinlock: busy-wait, Semaphore: blocking

**Solution:** A spinlock busy-waits in a loop until it can proceed; a semaphore blocks the waiting thread and can count multiple permits.

**Q82.** What does the TLB (Translation Lookaside Buffer) do in virtual memory?

- A) Prevents unauthorized memory access
- B) Speeds address translation
- C) Allocates physical memory frames
- D) Stores the entire page table in cache

**Answer:** Speeds address translation

**Solution:** It caches recently-used virtual-to-physical address translations so they don't need recomputing every time.

**Q83.** What is the Banker's algorithm for?

- A) Deadlock recovery via process termination
- B) Deadlock detection after it occurs
- C) CPU scheduling optimization
- D) Deadlock avoidance

**Answer:** Deadlock avoidance

**Solution:** It's a deadlock-avoidance strategy that only grants resource requests if the system stays in a safe state afterward.

**Q84.** How do user-level and kernel-level threads differ?

- A) User-level: OS-managed, Kernel-level: app-managed
- B) User-level and kernel-level threads are scheduled identically by the OS
- C) User-level: app-managed, Kernel-level: OS-managed
- D) User-level threads can run in true parallel, kernel-level cannot

**Answer:** User-level: app-managed, Kernel-level: OS-managed

**Solution:** User-level threads are scheduled entirely by the application with no kernel involvement; kernel-level threads are managed by the OS itself and can run in true parallel.

**Q85.** What is copy-on-write used for in memory management?

- A) Guarantees data consistency across threads
- B) Optimizes memory usage
- C) Compresses rarely used memory pages
- D) Immediately duplicates memory pages on process fork

**Answer:** Optimizes memory usage

**Solution:** It postpones actually copying shared memory pages until one side tries to write to them, saving work when writes never happen.

**Q86.** What does an inverted page table do?

- A) Efficient page mapping
- B) Stores one entry per virtual page regardless of physical memory size
- C) Speeds up virtual-to-physical translation via caching
- D) Eliminates the need for page faults

**Answer:** Efficient page mapping

**Solution:** It maps physical frames back to the virtual pages using them, cutting down on the memory a page table itself needs.

**Q87.** How do hard and soft real-time systems differ?

- A) Hard: critical, Soft: non-critical
- B) Hard real-time systems allow occasional missed deadlines for lower-priority tasks
- C) Hard: non-critical, Soft: critical
- D) Both hard and soft real-time systems treat missed deadlines identically

**Answer:** Hard: critical, Soft: non-critical

**Solution:** In a hard real-time system, missing a deadline is a critical failure; in a soft one, deadlines matter but aren't catastrophic to miss.

**Q88.** What does a monitor provide for process synchronization?

- A) Synchronization construct
- B) Process scheduling construct
- C) Deadlock detection mechanism
- D) Memory allocation construct

**Answer:** Synchronization construct

**Solution:** It bundles mutual exclusion with condition variables, giving processes a structured way to coordinate.

**Q89.** What does an I/O scheduler do?

- A) Encrypts data during disk access
- B) Compresses data before writing to disk
- C) Allocates memory for I/O buffers
- D) Optimizes disk I/O

**Answer:** Optimizes disk I/O

**Solution:** It reorders pending I/O requests to make disk access more efficient.

**Q90.** How do demand paging and prepaging differ?

- A) Demand: anticipatory, Prepaging: on-demand
- B) Demand: on-demand, Prepaging: anticipatory
- C) Prepaging only activates after a page fault occurs
- D) Demand paging loads all pages at process start

**Answer:** Demand: on-demand, Prepaging: anticipatory

**Solution:** Demand paging loads pages only when they're actually needed; prepaging loads pages ahead of time to try to avoid faults later.

### AI/ML Foundations

**Q91.** How do L1 and L2 regularization differ?

- A) L1 and L2 both penalize weights identically
- B) L1: increases model complexity, L2: reduces it to zero weights
- C) L1: sparsity, L2: smoothness
- D) L1: smoothness, L2: sparsity

**Answer:** L1: sparsity, L2: smoothness

**Solution:** L1 penalizes the absolute value of weights, encouraging sparsity; L2 penalizes squared weights, encouraging smoother, smaller values overall.

**Q92.** Why use early stopping when training a neural network?

- A) Prevents overfitting
- B) Speeds up each training epoch
- C) Guarantees convergence to the global minimum
- D) Reduces the number of model parameters

**Answer:** Prevents overfitting

**Solution:** Halting training once validation performance plateaus helps avoid overfitting to the training set.

**Q93.** What does batch normalization do in deep learning?

- A) Normalizes only the final output layer
- B) Directly reduces the final test error to zero
- C) Stabilizes training
- D) Reduces the number of layers needed

**Answer:** Stabilizes training

**Solution:** It normalizes each layer's inputs, which helps stabilize and speed up training.

**Q94.** How do precision and recall differ as evaluation metrics?

- A) Precision: overall model accuracy, Recall: training speed
- B) Precision and recall measure the same thing
- C) Precision: coverage, Recall: accuracy
- D) Precision: accuracy, Recall: coverage

**Answer:** Precision: accuracy, Recall: coverage

**Solution:** Precision measures how many predicted positives were actually correct (TP/(TP+FP)); recall measures how many actual positives were caught (TP/(TP+FN)).

**Q95.** Why use dropout in a neural network?

- A) Speeds up convergence during training
- B) Increases model capacity
- C) Guarantees a higher training accuracy
- D) Reduces overfitting

**Answer:** Reduces overfitting

**Solution:** Randomly disabling neurons during training discourages over-reliance on any one path, reducing overfitting.

**Q96.** How do CNNs and RNNs differ architecturally?

- A) CNN: sequential, RNN: spatial
- B) CNN and RNN are architecturally identical, differing only in name
- C) CNN: designed for time series, RNN: designed for images
- D) CNN: spatial, RNN: sequential

**Answer:** CNN: spatial, RNN: sequential

**Solution:** CNNs are built for spatial data like images; RNNs are built for sequential data like time series.

**Q97.** What does the attention mechanism do inside a transformer?

- A) Compresses the input sequence into a fixed-length vector
- B) Focuses on relevant inputs
- C) Randomly drops tokens during training
- D) Reduces the model's total parameter count

**Answer:** Focuses on relevant inputs

**Solution:** It lets the model weigh different input elements by relevance, sharpening its grasp of context.

**Q98.** What is the F1 score meant to capture?

- A) Measures raw classification accuracy
- B) Measures only false positive rate
- C) Is the arithmetic mean of precision and recall
- D) Balances precision and recall

**Answer:** Balances precision and recall

**Solution:** It's the harmonic mean of precision and recall, balancing both into a single number.

**Q99.** How do generative and discriminative models differ?

- A) Generative: conditional, Discriminative: joint
- B) Generative: joint, Discriminative: conditional
- C) Generative and discriminative models both learn P(y|x) directly
- D) Generative models only classify, discriminative models only generate

**Answer:** Generative: joint, Discriminative: conditional

**Solution:** Generative models learn the joint distribution P(x,y); discriminative models learn the conditional P(y|x) directly.

**Q100.** What is transfer learning used for?

- A) Compresses a large model into a smaller one
- B) Combines predictions from multiple independently trained models
- C) Trains a model entirely from scratch on new data
- D) Leverages pre-trained models

**Answer:** Leverages pre-trained models

**Solution:** It reuses a model already trained on one task as a starting point for a new one, needing far less new data to get good results.

## Frequently asked questions

### What does the Technical Aptitude practice set cover?

300 questions across 3 difficulty levels (100 each of Basic, Intermediate, and Advanced), spanning Programming Fundamentals, Data Structures, Algorithms, and 4 more topics.

### Are the answers and solutions shown?

Yes. Every question has a full worked solution and final answer, hidden behind a "Show Answer" toggle so you can genuinely self-test before checking.

### Is it free to use?

Yes. Browsing every problem on this page is completely free, with no account required. Creating a free DevsUnite account lets you save your checked-off progress, star favorites, and add personal notes that sync across devices.

### Do I need an account to track my progress?

You can read and solve every problem without logging in. An account is only required to mark a problem as done, star it, or add a note. Those actions save to your account instead of resetting on refresh.

## Related

- [Quantitative Aptitude](https://devsunite.com/resources/aptitude-prep/quantitative-aptitude)
- [Logical Reasoning](https://devsunite.com/resources/aptitude-prep/logical-reasoning)
- [Verbal Ability](https://devsunite.com/resources/aptitude-prep/verbal-ability)
- [Data Interpretation](https://devsunite.com/resources/aptitude-prep/data-interpretation)
- [Abstract Reasoning](https://devsunite.com/resources/aptitude-prep/abstract-reasoning)
- [Aptitude Test Prep](https://devsunite.com/resources/aptitude-prep)
