ILOMRAHomeStudy topicsFree toolsTest zoneSearch any topic
Computer Science · University Level

Algorithms & Data Structures

Computer science notes on Big-O, arrays, stacks, queues, trees and sorting algorithms with examples.

Last updated: 23 November 2026

Key points

Worked example

Worked example: binary search for 23 in [2, 5, 8, 12, 16, 23, 38]

The middle element is 12 and 23 > 12, so search the right half [16, 23, 38]. Its middle element is 23, which is found. Only 2 comparisons were needed instead of 6.

Practice MCQs

Q1. Which data structure works on a Last-In-First-Out basis?

  1. Queue
  2. Stack
  3. Array
  4. Graph
Show answer

Answer: B. Stack. A stack removes the most recently added item first.

Q2. What is the time complexity of binary search?

  1. O(n)
  2. O(log n)
  3. O(n²)
  4. O(1)
Show answer

Answer: B. O(log n). Binary search halves the search range each step, so it takes O(log n).

Q3. Which data structure is First-In-First-Out?

  1. Stack
  2. Queue
  3. Tree
  4. Array
Show answer

Answer: B. Queue. A queue serves items in the order they arrived.

Q4. What is the worst-case time complexity of bubble sort?

  1. O(n)
  2. O(n log n)
  3. O(n²)
  4. O(log n)
Show answer

Answer: C. O(n²). Bubble sort compares pairs repeatedly, which takes O(n²) in the worst case.

Q5. Which operation is usually O(1)?

  1. Accessing an array element by index
  2. Linear search
  3. Bubble sort
  4. Merge sort
Show answer

Answer: A. Accessing an array element by index. Indexing jumps straight to the position, so the time does not depend on n.

Q6. Which data structure is natural for an undo feature?

  1. Queue
  2. Stack
  3. Tree
  4. Hash table
Show answer

Answer: B. Stack. Undo reverses the most recent action first: Last-In-First-Out.

Q7. Which sorting algorithm is O(n log n) on average but O(n²) in the worst case?

  1. Merge sort
  2. Quicksort
  3. Bubble sort
  4. Heap sort
Show answer

Answer: B. Quicksort. A bad pivot choice can make quicksort O(n²).

Q8. Binary search requires the data to be:

  1. Sorted
  2. Unique
  3. Numeric only
  4. In a linked list
Show answer

Answer: A. Sorted. Halving the range only works when the data is in order.

Q9. What is the average time for a hash table lookup?

  1. O(n)
  2. O(log n)
  3. O(1)
  4. O(n²)
Show answer

Answer: C. O(1). A good hash function finds the slot directly.

Q10. Which structure stores each item with a pointer to the next item?

  1. Array
  2. Linked list
  3. Matrix
  4. Bitmap
Show answer

Answer: B. Linked list. Each node of a linked list holds data and a link to the next node.

Q11. Which queue operation adds an item?

  1. Push
  2. Pop
  3. Enqueue
  4. Peek
Show answer

Answer: C. Enqueue. Enqueue adds at the back, dequeue removes from the front.

Q12. In a binary search tree, values in the left subtree are ___ the node’s value.

  1. greater than
  2. less than
  3. equal to
  4. unrelated to
Show answer

Answer: B. less than. BST rule: left < node < right.

Q13. Which running time grows fastest as n becomes large?

  1. O(n)
  2. O(log n)
  3. O(n²)
  4. O(n log n)
Show answer

Answer: C. O(n²). n² grows faster than n log n, n or log n.

Q14. An algorithm must be:

  1. Infinite
  2. Finite and well-defined
  3. Random
  4. Written in Python
Show answer

Answer: B. Finite and well-defined. An algorithm is a finite list of well-defined steps.

Helpful tools

Want to study something else?

ILOMRA can open full notes and practice MCQs for almost any study topic. Search any topic on ILOMRA.

Take the timed MCQ test for this topic.

Related topics