FreeExam
A closed notebook, a blank card, and a pencil on a wooden desk.

Algorithms

50 cards

Cost, the structure you pick, and why that method fits the input.

Card 1 of 50

Front. Big-o. What does big O describe?

These cards are original study material. They are not questions from a named employer or a live hiring loop.

All 50 cards in this deck

  1. 1.Big-o

    What does big O describe?

    An upper bound on how the step count grows as the input gets larger. Constant factors and smaller terms are left out.

  2. 2.Big-theta

    What does big Theta describe?

    A tight bound. The running time grows at that rate from above and from below, so it is sharper than a plain upper bound.

  3. 3.Space

    What is space complexity?

    How much extra memory the algorithm uses as the input grows. Count the structures you allocate and the call stack.

  4. 4.Amortized

    What is amortized time?

    The average cost of one operation over a long run. A single call may be expensive if those calls are rare enough.

  5. 5.Worst-case

    What is worst-case time?

    The most steps the algorithm takes on any input of that size. Average time can look better and still hide this input.

  6. 6.Dynamic-array

    What does a dynamic array give you?

    Indexed access in constant time, and appends that are usually cheap. When the buffer fills, it allocates a larger one and copies.

  7. 7.Linked-list

    What is a linked list good at?

    Inserting or deleting at a node you already hold, without shifting the rest. Reaching the nth node means walking there.

  8. 8.Stack

    What is a stack?

    A collection that returns the most recently added item first. Function calls and undo history are the usual picture.

  9. 9.Queue

    What is a queue?

    A collection that returns the oldest item first. Breadth-first search uses one to visit nodes in the order they were found.

  10. 10.Deque

    What is a deque?

    A double-ended queue. Items can be added or removed at either end in constant time.

  11. 11.Hash-table

    What does a hash table give you?

    Expected constant-time lookup, insert, and delete by key, when the hash spreads keys across the slots.

  12. 12.Collision

    What is a hash collision?

    Two keys landing in the same slot. The table keeps both, usually in a short chain or by probing other slots.

  13. 13.Load-factor

    What does load factor measure?

    How full a hash table is, as items divided by slots. A high load factor means more collisions and slower operations.

  14. 14.Binary-heap

    What is a binary heap?

    A tree, usually stored in an array, where each parent is ordered ahead of its children. The root is the minimum or the maximum.

  15. 15.Priority-queue

    What is a priority queue?

    A collection that returns the highest-priority item next. A binary heap is the usual way to build one.

  16. 16.Bst

    What is a binary search tree?

    Each node is greater than everything in its left subtree and smaller than everything in its right subtree.

  17. 17.Balance

    Why balance a search tree?

    So the height stays logarithmic. A tree that leans to one side turns each lookup into a walk down a list.

  18. 18.Trie

    What is a trie?

    A tree of characters, one step per character, for strings that share prefixes. Lookup follows the letters of the word.

  19. 19.Graph

    What is a graph?

    A set of nodes connected by edges. An edge may have a direction, a weight, or both.

  20. 20.Adjacency-list

    What is an adjacency list?

    For each node, the list of nodes it connects to. It stays small when most pairs of nodes have no edge.

  21. 21.Bfs

    What does breadth-first search guarantee?

    On an unweighted graph, the first time it reaches a node is along a shortest path, counted in edges.

  22. 22.Dfs

    What does depth-first search do?

    It follows one path as far as it can, then backtracks. That is the usual way to explore every path or to notice a cycle.

  23. 23.Topo

    What is a topological order?

    An order of the nodes of a directed graph so every edge points forward. It exists only when the graph has no cycle.

  24. 24.Dijkstra

    What does Dijkstra's algorithm require?

    Non-negative edge weights. It then finds shortest paths from one source. A negative edge makes it the wrong tool.

  25. 25.Union-find

    What is a union-find structure?

    It answers whether two items are in the same group, and it merges two groups. With the usual tricks, each call is nearly constant time.

  26. 26.Binary-search

    When does binary search apply?

    When the space is sorted, or a yes-or-no property flips only once, so each check can throw away half of what remains.

  27. 27.Two-pointers

    What is the two-pointers pattern?

    Two indexes moving across a line or a sorted array, usually to find a pair or a span in one pass.

  28. 28.Sliding-window

    What is a sliding window?

    A contiguous span whose answer you update as the span moves, instead of recomputing the span from scratch each time.

  29. 29.Recursion

    What must a recursive function have?

    A base case that stops, and each call must move toward that case. Otherwise the calls never end.

  30. 30.Backtracking

    What is backtracking?

    Building a candidate one choice at a time, and undoing a choice when it cannot lead to a valid answer.

  31. 31.Dp

    What is dynamic programming?

    Solving a problem by saving the answers to overlapping smaller problems and reusing those answers.

  32. 32.Memo

    What is memoization?

    A top-down cache. The recursive function stores each subproblem's answer the first time it computes it.

  33. 33.Tabulation

    What is tabulation?

    Filling a table of subproblem answers from smaller ones toward larger ones, with no recursive calls.

  34. 34.Greedy

    When is a greedy choice safe?

    When taking the locally best option at each step is guaranteed to be part of some globally best answer.

  35. 35.Divide

    What is divide and conquer?

    Split the input, solve the pieces, and combine them. Merge sort is the standard example.

  36. 36.Stable

    What is a stable sort?

    A sort that keeps the original order of items that compare as equal.

  37. 37.Mergesort

    What does merge sort cost?

    O(n log n) comparisons, and it needs a second buffer of about n items for the merge. It is a stable sort.

  38. 38.Quicksort

    What does quicksort depend on?

    The pivot. Average time is O(n log n). A pivot that always lands at the end makes it quadratic.

  39. 39.Heapsort

    What does heapsort guarantee?

    O(n log n) time even in the worst case, using only a small amount of extra memory. It is not a stable sort.

  40. 40.Cycle

    How do you detect a cycle in a linked list?

    Advance one pointer by one step and another by two. If there is a cycle, the faster pointer meets the slower one.

  41. 41.Invariant

    What is a loop invariant?

    A fact you can show is true before every iteration and still true after. It is how you argue the loop does what you claim.

  42. 42.In-place

    What does in-place mean?

    The algorithm reuses the input's storage and only a small, fixed amount of extra memory that does not grow with the input.

  43. 43.Locality

    Why does walking an array beat jumping around?

    The CPU loads memory in chunks. Neighboring items are often already in cache. Scattered nodes usually are not.

  44. 44.Monotonic

    What is a monotonic stack?

    A stack kept in sorted order by dropping entries that can never be the next answer, such as the previous greater element.

  45. 45.Intervals

    How do you merge overlapping intervals?

    Sort by start time. Extend the current interval while the next one begins before the current one ends.

  46. 46.Prefix

    What is a prefix-sum array?

    Each entry holds the total of everything before that index, so the sum of any span is a subtraction of two entries.

  47. 47.Bitmask

    What is a bit mask?

    An integer used as a small set, one bit per item. Subsets can be stored and updated with bitwise operations.

  48. 48.Stack-depth

    What limits recursion on a long chain?

    The call stack. A chain of length n can overflow it. An explicit stack, or a loop, uses memory you control.

  49. 49.Sort-bound

    Why is comparison sorting stuck at n log n?

    There are n factorial possible orders, and each comparison has two outcomes, so some inputs need about n log n comparisons.

  50. 50.Negative

    When is Bellman-Ford the right shortest path?

    When an edge weight may be negative. It also reports a negative cycle. Dijkstra does not handle negative edges.