BAMS

11th Grade Data Structures & Algorithms Practice: Questions, Answers and Tips

Looking for 11th grade data structures & algorithms practice? Below are worked examples, the mistakes students make most, and practice questions with an answer key.

6 min read

In this article

Looking for 11th grade data structures & algorithms practice? Below are worked examples, the mistakes students make most, and practice questions with an answer key.

Every example below comes from BAMS Academy's Data Structures & Algorithms practice, the same questions students answer on the site.

Data Structures & Algorithms in 11th grade, skill by skill

Trees, graphs, sorting, and algorithmic complexity. BAMS Academy breaks the unit into the skills below (part of all 11th grade computer science topics). Each comes with one of its practice questions.

Analyse algorithms with Big-O and choose structures by their cost

In Big-O terms, what is the cost of looking up a value by key in a hash map, on average? (Choices: O(log n); O(n log n); O(n); O(1).)

Answer: O(1). Looking up a value by key in a hash map, on average is O(1). Big-O describes how the work grows as n grows, ignoring constant factors.

What is the time complexity of a binary search over a sorted array? (Choices: O(log n); O(n log n); O(1); O(n).)

Answer: O(log n). A binary search over a sorted array is O(log n). Big-O describes how the work grows as n grows, ignoring constant factors.

Trace and compare the standard sorting algorithms

Which sorting algorithm partitions around a pivot and recurses on each side? (Choices: Insertion sort; Quicksort; Bubble sort; Selection sort.)

Answer: Quicksort. Quicksort is the algorithm that partitions around a pivot and recurses on each side.

You need a sort that repeatedly swaps adjacent out-of-order pairs. Which one fits? (Choices: Merge sort; Bubble sort; Selection sort; Insertion sort.)

Answer: Bubble sort. Bubble sort is the algorithm that repeatedly swaps adjacent out-of-order pairs.

In graph and tree terminology, what is the height of a tree? (Choices: The length of the longest path from the root to a leaf; A path that returns to the node it started from; The single node at the top of a tree with no parent; A node with no children.)

Answer: The length of the longest path from the root to a leaf. The height of a tree is the length of the longest path from the root to a leaf.

Reason about the structure. You need the shortest path in an unweighted graph. Which search do you use? (Choices: Depth-first search; Binary search; Breadth-first search; A linear scan of the node list.)

Answer: Breadth-first search. BFS explores in order of distance from the start, so the first time it reaches a node is by a shortest path.

Worked examples

Example 1

Question: An O(n^2) algorithm takes 1 second on 1,000 items. Roughly how long on 10,000 items?

  1. About 1 second
  2. About 1,000 seconds
  3. About 100 seconds
  4. About 10 seconds

How to solve it: Ten times the input means 10^2 = 100 times the work for a quadratic algorithm.

Answer: About 100 seconds

Why the other choices don't work:

  • A student who picks "About 1 second" usually assumes input size does not affect running time.
  • "About 1,000 seconds" is a tempting wrong answer — cubes the growth factor instead of squaring it.
  • "About 10 seconds" is a tempting wrong answer — scales the time linearly, ignoring the squared term.

Example 2

Question: In Big-O terms, what is the cost of scanning every element of an array once?

  1. O(1)
  2. O(log n)
  3. O(n log n)
  4. O(n)

How to solve it: Scanning every element of an array once is O(n). Big-O describes how the work grows as n grows, ignoring constant factors.

Answer: O(n)

Why the other choices don't work:

  • A student who picks "O(1)" usually classified this as O(1), which describes a different growth rate.
  • A student who picks "O(log n)" usually classified this as O(log n), which describes a different growth rate.
  • A student who picks "O(n log n)" usually classified this as O(n log n), which describes a different growth rate.

Common mistakes to watch for

  • Question: Reason about the growth rate. You need to check membership millions of times in a collection of 100,000 items. Which structure? (Choices: A linked list, because insertion is cheap; A sorted list with binary search; A hash set, for average O(1) lookup; An unsorted list, scanning it each time.)

    Answer: A hash set, for average O(1) lookup.

    "A sorted list with binary search" is a tempting wrong answer — O(log n) is good, but a hash set is better and insertion into a sorted list costs more.

  • Question: In Big-O terms, what is the cost of comparing every pair of elements with a nested loop? (Choices: O(n^2); O(log n); O(n); O(1).)

    Answer: O(n^2).

    A student who picks "O(n)" usually classified this as O(n), which describes a different growth rate.

  • Question: Which sorting algorithm partitions around a pivot and recurses on each side? (Choices: Insertion sort; Quicksort; Bubble sort; Selection sort.)

    Answer: Quicksort.

    A student who picks "Insertion sort" usually named insertion sort, which uses a different strategy.

  • Question: You need a sort that repeatedly swaps adjacent out-of-order pairs. Which one fits? (Choices: Merge sort; Bubble sort; Selection sort; Insertion sort.)

    Answer: Bubble sort.

    A student who picks "Selection sort" usually named selection sort, which uses a different strategy.

  • Question: In graph and tree terminology, what is the height of a tree? (Choices: The length of the longest path from the root to a leaf; A path that returns to the node it started from; The single node at the top of a tree with no parent; A node with no children.)

    Answer: The length of the longest path from the root to a leaf.

    A student who picks "The single node at the top of a tree with no parent" usually defined this as "the single node at the top of a tree with no parent", which describes a different part of the structure.

  • Question: Reason about the structure. You need the shortest path in an unweighted graph. Which search do you use? (Choices: Depth-first search; Binary search; Breadth-first search; A linear scan of the node list.)

    Answer: Breadth-first search.

    "Depth-first search" is a tempting wrong answer — DFS finds a path but not necessarily the shortest one.

Try these practice questions

  1. In Big-O terms, what is the cost of generating every subset of a set of n elements?

    1. O(2^n)
    2. O(n)
    3. O(1)
    4. O(log n)
  2. Reason about the growth rate. You need to check membership millions of times in a collection of 100,000 items. Which structure?

    1. A linked list, because insertion is cheap
    2. A sorted list with binary search
    3. A hash set, for average O(1) lookup
    4. An unsorted list, scanning it each time
  3. In Big-O terms, what is the cost of comparing every pair of elements with a nested loop?

    1. O(n^2)
    2. O(log n)
    3. O(n)
    4. O(1)
Answer key
  1. O(2^n) — Generating every subset of a set of n elements is O(2^n). Big-O describes how the work grows as n grows, ignoring constant factors.
  2. A hash set, for average O(1) lookup — When lookups dominate, choose the structure with the cheapest lookup. A hash set gives constant-time membership on average.
  3. O(n^2) — Comparing every pair of elements with a nested loop is O(n^2). Big-O describes how the work grows as n grows, ignoring constant factors.

Keep practicing

The fastest way to build confidence is a few questions at a time, with feedback on each answer. Start with Data Structures & Algorithms practice for grade 11, where every question comes with a step-by-step explanation.

More from BAMS Academy:

Share

Ready to practice?