🌍 CS50x: Introduction to Computer Science · flashcards

CS50x: Introduction to Computer Science Algorithms Flashcards

50 question-and-answer cards covering Algorithms as it is examined in CS50x: Introduction to Computer Science. 24 of them are printed below, taken from across the deck — no signup, no paywall on the preview.

50Cards in deck
24Free preview
9Syllabus topics
~150Chars per answer
FreePrice

24 sample cards from the Algorithms deck

Sampled from the end of the deck, so these are different cards from the ones shown on the syllabus page.

  1. State merge sort in three lines of pseudocode.

    If the array has only $1$ element, it is already sorted (return). Otherwise: sort the left half, sort the right half, then merge the two sorted halves.

  2. What is the worst-case running time of merge sort?

    $O(n \log n)$ — asymptotically faster than the $O(n^{2})$ of bubble sort and selection sort.

  3. What is the best-case running time of merge sort?

    $\Omega(n \log n)$ — merge sort always splits and merges fully, so even a sorted input takes $n \log n$ time; hence merge sort is $\Theta(n \log n)$.

  4. Why does merge sort run in $O(n \log n)$ time?

    Halving the array repeatedly creates about $\log_{2} n$ levels of division, and merging at each level touches all $n$ elements, giving total work $n \times \log_{2} n$.

  5. What is the base case of merge sort?

    An array (or subarray) of size $1$: a single element is already sorted, so the recursion stops and returns immediately.

  6. How does the merge step combine two sorted halves?

    Repeatedly compare the front (smallest remaining) elements of the two halves, copy the smaller one into the output, and advance in that half; when one half is exhausted, copy over the rest of the other half.

  7. What is the main trade-off merge sort makes for its speed?

    Extra memory: it needs additional space (on the order of $O(n)$) to hold elements while merging, whereas bubble sort and selection sort sort in place.

  8. What does Big $O$ notation describe?

    An upper bound on running time — how the algorithm's time grows with input size $n$ in the worst case (e.g. linear search is $O(n)$).

  9. What does Big $\Omega$ (Omega) notation describe?

    A lower bound on running time — the best case for the algorithm (e.g. linear search is $\Omega(1)$, since the target might be found immediately).

  10. What does Big $\Theta$ (Theta) notation describe, and when does it apply?

    A tight bound: when an algorithm's upper and lower bounds coincide, i.e. $O$ and $\Omega$ are the same, we write $\Theta$ (e.g. selection sort is $\Theta(n^{2})$, merge sort is $\Theta(n \log n)$).

  11. Order these common running times from fastest to slowest: $O(n^{2})$, $O(1)$, $O(n \log n)$, $O(n)$, $O(\log n)$.

    $$O(1) < O(\log n) < O(n) < O(n \log n) < O(n^{2})$$

  12. Why is an algorithm taking $\frac{n^{2}}{2} - \frac{n}{2}$ steps still classified as $O(n^{2})$?

    Asymptotic notation ignores constant factors and lower-order terms because, as $n \to \infty$, the $n^{2}$ term dominates growth; only the dominant term matters.

  13. What does a running time of $O(1)$ mean? Give an example.

    Constant time: the number of steps does not grow with input size $n$. Example: accessing an array element by index, or checking the first element of a list.

  14. Give the worst-case ($O$) and best-case ($\Omega$) running times of linear search and binary search.

    Linear search: $O(n)$ and $\Omega(1)$. Binary search: $O(\log n)$ and $\Omega(1)$. Binary search is faster in the worst case but requires sorted data.

  15. Give the worst-case ($O$) and best-case ($\Omega$) running times of bubble sort, selection sort, and merge sort.

    Bubble sort: $O(n^{2})$, $\Omega(n)$. Selection sort: $O(n^{2})$, $\Omega(n^{2})$. Merge sort: $O(n \log n)$, $\Omega(n \log n)$.

  16. If you double the input size $n$ of an $O(n^{2})$ algorithm, roughly how much longer does it take?

    About $4$ times longer, since $(2n)^{2} = 4n^{2}$.

  17. When is it worth sorting an array first ($O(n \log n)$ with merge sort) rather than using linear search directly?

    When you will search the data many times: sorting once costs $O(n \log n)$, but then every search is only $O(\log n)$ with binary search instead of $O(n)$ each time.

  18. What is a recursive function?

    A function that calls itself, solving a problem by reducing it to one or more smaller instances of the same problem until a trivially solvable case is reached.

  19. What two essential parts must every correct recursive function have?

    1) A base case: a condition where the function stops calling itself and returns directly. 2) A recursive case: a call to itself on a smaller version of the problem that moves toward the base case.

  20. What is a base case in recursion, and what is its purpose?

    The simplest input for which the answer is returned directly without further recursive calls. It terminates the recursion, guaranteeing the chain of self-calls eventually stops.

  21. What happens if a recursive function has no (reachable) base case?

    It calls itself forever: each call adds a new frame to the call stack until memory is exhausted, causing a stack overflow and crashing the program (e.g. a segmentation fault in C).

  22. Define the factorial function recursively, including its base case.

    $$n! = n \cdot (n-1)! \quad \text{for } n \geq 1, \qquad 0! = 1.$$ The base case $0! = 1$ (equivalently $1! = 1$) stops the recursion.

  23. Describe binary search as a recursive function, naming its base cases.

    Recursive case: compare the target to the middle element and recurse on the left or right half. Base cases: the middle element equals the target (found), or the search range is empty (not found).

  24. Which of the algorithms covered in CS50 is naturally recursive, and what makes it so?

    Merge sort: it solves the problem by calling itself on the left half and the right half of the array (recursive cases), stopping when a subarray has one element (base case), then merging results.

What this deck covers

The Algorithms deck follows the CS50x: Introduction to Computer Science Algorithms syllabus — 4 chapters and 9 topics — so questions land on material that is genuinely examinable rather than trivia around it. That works out to roughly 12.5 cards per chapter.

Answers are written to be recallable, not just readable — averaging about 150 characters, which is long enough to carry the reasoning and short enough to say out loud.

A deck like this earns its keep on the second and third pass. Read the syllabus first so you know the shape of the subject, then use the cards to find the specific facts that have not stuck.

Algorithms flashcards FAQ

How many Algorithms flashcards are in this CS50x: Introduction to Computer Science deck?

50 cards. This page previews 24 of them, sampled evenly across the deck so you can judge the difficulty before installing anything.

Are these CS50x: Introduction to Computer Science flashcards free?

Yes. The preview here is free to read with no signup, and the full 50-card deck is free inside the Examius app.

What do the Algorithms cards cover?

They follow the CS50x: Introduction to Computer Science Algorithms syllabus — 4 chapters and 9 topics — so the questions track what is actually examinable.

How should I use these flashcards?

Read the syllabus first so you know the shape of the subject, then drill the deck. Examius schedules each card with spaced repetition, so cards you keep missing come back sooner and ones you know drift further apart.