VelocerOtwórz aplikację

Velocer › Fiszki › University of Wisconsin–Madison › COMP SCI 240 Midterm 3

COMP SCI 240 Midterm 3

Recurrences, big-o/asymptotic analysis, relations + functions, graphs + trees. · autor: sunset_point_notes · 160 fiszek

University of Wisconsin–Madison

Ucz się z tej talii Osadź

  1. ComplexityA count of elementary operations as a function of input size n.
  2. Examples of elementary operationsInteger addition, bit shift, recursive call, comparison.
  3. What can n represent in complexity?An integer value, an array length, or the bit-length of a number.
  4. RecurrenceAn inductive definition of a sequence: first terms given, then each term from earlier ones.
  5. Solving a recurrenceFinding a closed form in n only, with no recursive terms like M().
  6. Recursive plan for Towers of HanoiMove n−1 disks to B, move the largest A→C, then move n−1 disks B→C.
  7. Moves recurrence for Towers of HanoiM(n) = 2M(n−1) + 1 for n ≥ 1, with M(0) = 0.
  8. Closed form for Towers of Hanoi movesM(n) = 2ⁿ − 1.
  9. Induction step for M(n) = 2ⁿ − 1Assume M(n) = 2ⁿ − 1; then 2(2ⁿ − 1) + 1 = 2ⁿ⁺¹ − 1.
  10. Three steps to analyze a recursive algorithmDerive a recurrence, compute first terms and conjecture, then prove by induction.
  11. Iterative multiplication loop count L(a, b)L(a, b) = ⌊log₂ b⌋ + 1 for b ≥ 1, and L = 0 when b = 0.
  12. What happens each pass of iterative multiplication?Halve y (floor), double x, and add x to p if y is odd.
  13. If 2ᵏ ≤ b < 2ᵏ⁺¹, what is L(a, b)?L = k + 1.
  14. Recursive multiplication MULT(a, b) when b is evenMULT(a, b) = 2 · MULT(a, ⌊b/2⌋).
  15. Recursive multiplication MULT(a, b) when b is oddMULT(a, b) = 2 · MULT(a, ⌊b/2⌋) + a.
  16. Complexity measure for recursive multiplicationThe number of shifts, since multiplying by 2 is a left shift.
  17. Shift recurrence for recursive multiplicationS(a, b) = S(a, ⌊b/2⌋) + 1, with S(a, 0) = 0.
  18. What does S(a, b) depend on?Only on b, not on a.
  19. Closed form for S(a, b) when 2ᵏ ≤ b < 2ᵏ⁺¹S(a, b) = k + 1.
  20. Key bound in the strong induction proof for SIf 2ᵏ ≤ B+1 < 2ᵏ⁺¹, then 2ᵏ⁻¹ ≤ ⌊(B+1)/2⌋ < 2ᵏ.
  21. GCD recursive rule when a = bGCD(a, b) = a.
  22. How do you find GCD(a, b) when a < b?Use GCD(a, b) = GCD(a, b − a). Example: GCD(3, 10) → GCD(3, 7) → GCD(3, 4) → GCD(3, 1) → 1.
  23. How do you simplify GCD(a, b) when a > b?Subtract the smaller from the larger: GCD(a, b) = GCD(a−b, b). Example: GCD(12, 8) = GCD(4, 8).
  24. R(a, b) for the GCD algorithmThe number of recursive calls; it is symmetric in a and b.
  25. R₀(n) definitionThe maximum number of recursive calls over all inputs a, b ≤ n.
  26. Relation between R(a, b) and R₀R(a, b) ≤ R₀(max(a, b)).
  27. Recurrence for R₀(n)R₀(n) ≤ 1 + R₀(n−1).
  28. Closed form for R₀(n)R₀(n) = n − 1.
  29. Worst-case input for the GCD algorithm(n, 1), which gives the chain (n−1,1), …, (1,1) and n−1 calls.
  30. How is R₀(n) = n − 1 proved?Show ≥ n−1 using the worst-case input, and ≤ n−1 by strong induction.
  31. Does a termination proof also prove efficiency?No; efficiency needs a count of operations.
  32. Is M(n) about 2ⁿ or 2ⁿ⁻¹?About 2ⁿ; 2ⁿ⁻¹ comes from a variant with M′(1) = 1.
  33. Why must you use floor division in these recurrences?Because halving an integer gives ⌊b/2⌋, not b/2.
  34. Which arguments does GCD complexity depend on?Both arguments, unlike multiplication which depends only on b.
  35. Asymptotic equivalence f ~ gThe ratio f(n)/g(n) → 1 as n → ∞.
  36. Formal definition of f ~ gFor every ε > 0 there is N so that 1−ε ≤ f/g ≤ 1+ε for all n ≥ N.
  37. Does ~ keep constant factors?Yes: 12n² ~ 12n², not ~ n².
  38. Big Theta f = Θ(g)The ratio f/g is squeezed between constants c and d for large n.
  39. Does Θ absorb constant factors?Yes: 12n² + 10⁹n + 1/n = Θ(n²).
  40. If f ~ g, what follows for Θ?f = Θ(g); take c = 1/2 and d = 3/2.
  41. What kind of bound is Θ?The tight two-sided bound.
  42. Big Oh f = O(g)f/g ≤ d for large n; an upper bound only.
  43. Big Omega f = Ω(g)f/g ≥ c for large n; a lower bound only.
  44. Θ in terms of O and Ωf = Θ(g) ⇔ f = O(g) and f = Ω(g).
  45. When do you use O?For 'runs within at most'.
  46. When do you use Ω?For 'takes at least'.
  47. If lim f/g = c > 0 finite, what follows?f = Θ(g).
  48. If lim f/g = 0, what follows?f = O(g), but not Ω(g).
  49. If lim f/g = ∞, what follows?f = Ω(g), but not O(g).
  50. Must the limit f/g exist for O, Ω or Θ to hold?No; the limit need not exist.
  51. Closed form for Fibonacci numbersFₙ = (φⁿ − (1−φ)ⁿ)/√5, with φ = (1+√5)/2.
  52. Asymptotic growth of FₙFₙ ~ φⁿ/√5, so Fₙ = Θ(φⁿ).
  53. Compare Fₙ with n²Fₙ ≠ O(n²), but n² = O(Fₙ); exponential beats any polynomial.
  54. Growth of log(n!)log(n!) = Θ(n log n).
  55. Upper bound for log(n!)Each of n terms is ≤ log n, so log(n!) ≤ n log n.
  56. Lower bound for log(n!)About n/2 largest terms are each ≥ log(n) − 1, so log(n!) ≥ (n/2)(log n − 1).
  57. Which is stricter, ~ or Θ?~ is stricter; Θ allows any constant ratio, ~ demands ratio → 1.
  58. Does f = O(g) imply f = Θ(g)?No; O is only an upper bound.
  59. Do constants vanish inside Θ?Yes, they vanish inside Θ.
  60. Do constants vanish under ~?No; they do not vanish under ~.
  61. What inputs do asymptotic claims concern?Only large n; small-n behavior is irrelevant.
  62. Binary relationA set of ordered pairs (x, y) satisfying a predicate P(x, y), with x ∈ D₁ and y ∈ D₂.
  63. Cartesian product A × BThe set {(a, b) | a ∈ A and b ∈ B}; order matters.
  64. When does (a₁, b₁) = (a₂, b₂)?Exactly when a₁ = a₂ and b₁ = b₂.
  65. Relation R from A to BA subset of A × B; A is the domain and B is the codomain.
  66. Relation on a set AA relation from A to A, i.e. a subset of A × A.
  67. What does xRy mean?That the ordered pair (x, y) is in the relation R.
  68. How do you draw a relation on one set?As a digraph: an arrow a → b means aRb; two arrows if both directions hold.
  69. Bipartite graph of a relation from A to BA on one side, B on the other, with an edge for each pair aRb.
  70. FunctionA relation where each a ∈ A has at most one b ∈ B.
  71. Total functionEvery a ∈ A has exactly one b ∈ B.
  72. What does f: A → B mean?f maps each input in A to exactly one output in B. So f(a) = b, where b is the image of a.
  73. Inverse relation R⁻¹aRb ⇔ bR⁻¹a; it always exists, unlike an inverse function.
  74. Is the mother relation a function?No, because a person can have more than one child.
  75. Is the spouse relation total?No; it's a function but not total, since not everyone is married.
  76. Injective (one-to-one) functionf(a₁) = f(a₂) ⇒ a₁ = a₂; equivalently, f⁻¹ is a function.
  77. Surjective (onto) functionEvery b ∈ B has some a ∈ A with f(a) = b.
  78. Bijective functionA function that is both injective and surjective.
  79. Injective total f: A → B tells you what about sizes?|A| ≤ |B|.
  80. Surjective f: A → B tells you what about sizes?|A| ≥ |B|.
  81. Bijective total f: A → B tells you what about sizes?|A| = |B|.
  82. How do you prove |A| ≤ |B|?Build an injective total map from A to B.
  83. Reflexive relation on AFor every a, aRa.
  84. Antireflexive relation on AFor every a, ¬aRa.
  85. Symmetric relationaRb ⇔ bRa.
  86. Antisymmetric relation(aRb ∧ bRa) ⇒ a = b.
  87. Transitive relation(aRb ∧ bRc) ⇒ aRc.
  88. Is ⊆ reflexive, antisymmetric, transitive?Yes, all three.
  89. Is < reflexive?No, it's antireflexive; it is antisymmetric and transitive.
  90. Is ≤ a total order?Yes; it's reflexive, antisymmetric, transitive, and total.
  91. Is divisibility | an order relation on the positives?Yes: reflexive, antisymmetric, transitive, but not total.
  92. Why is divisibility transitive?If b = ka and c = lb, then c = (lk)a.
  93. Equivalence relationA relation that is reflexive, symmetric, and transitive.
  94. Is ≠ an equivalence relation?No; it's symmetric but not reflexive or transitive.
  95. Partition of a set AA collection of nonempty subsets whose union is A and which are pairwise disjoint.
  96. Equivalence class [a]The set {b | aRb}.
  97. When is [a] = [b]?Exactly when aRb.
  98. If ¬aRb, what about [a] ∩ [b]?It's empty; the classes are disjoint.
  99. How does an equivalence relation give a partition?The equivalence classes [a] form the partition of A.
  100. How does a partition give an equivalence relation?Define aRb when a and b are in the same class.
  101. Order relationA relation that is antisymmetric and transitive.
  102. Strict order relationAn order relation that is also antireflexive.
  103. Total orderFor any x ≠ y, either xRy or yRx.
  104. Is | a total order on the positives?No; 3 ∤ 7 and 7 ∤ 3, so they're incomparable.
  105. Extension R̃ of an order RA total order with xRy ⇒ xR̃y; ≤ extends | on the positives.
  106. Ternary relation example{(x, y, z) | x² + y² + z² = 1}, the unit sphere in ℝ³.
  107. DigraphA directed graph G = (V, E): V is vertices, E is a multiset of ordered pairs from V×V.
  108. Simple graphA graph where E is a set, so no duplicate edges; E is a binary relation on V.
  109. Path from u to vA sequence of edges where the first starts at u, the last ends at v, and consecutive edges share a vertex.
  110. Length of a pathThe number of edges in the path.
  111. Empty pathA path of length 0 whose start and end vertex are the same.
  112. CycleA path with at least one edge that begins and ends at the same vertex. Example: v_1 → v_2 → v_3 → v_1.
  113. Transitive closure relation uRvuRv holds exactly when a path exists from u to v.
  114. Why is the transitive closure of a digraph reflexive?A length-0 path always exists from any vertex to itself, even with no edges.
  115. Is the transitive closure of a digraph symmetric?Not in general: an edge (u,v) gives no path from v back to u.
  116. DAGA directed acyclic graph: a digraph that contains no cycles.
  117. Why can't a DAG have a self-loop (v,v)?A self-loop is a cycle of length 1.
  118. What do DAGs model?Prerequisites, software dependencies, and task ordering; cycles make completion impossible.
  119. Topological orderingA total order ≤ on V such that every edge (u,v) has u ≤ v for u ≠ v.
  120. Does every DAG have a topological ordering?Yes, every DAG has one.
  121. Does every finite nonempty DAG have an in-degree-0 vertex?Yes; otherwise following incoming edges would revisit a vertex and form a cycle.
  122. In-degree and out-degreeIn-degree counts edges ending at v; out-degree counts edges starting at v.
  123. In a topological order, which way do arrows point?Left to right.
  124. Incident edge and vertexAn edge e and vertex v are incident when v is an endpoint of e.
  125. Bipartite graphA graph whose vertices split into V_left and V_right with no edge inside either part.
  126. Connected componentThe subgraph on one equivalence class of the transitive closure.
  127. Connected graphA graph with at most one connected component.
  128. Degree deg(v)The number of edges containing v; a self-loop counts twice.
  129. Handshake formulaΣ deg(v) = 2|E|, because each edge contributes 2 to the degree sum.
  130. How many odd-degree vertices can a graph have?An even number.
  131. Simple pathA path with no repeated edge; only the start vertex may repeat, and only at the end.
  132. Simple cycleA non-empty simple path whose start vertex equals its end vertex.
  133. TreeA connected graph with no simple cycles.
  134. LeafA vertex of degree 1; in a single-vertex tree, that vertex is a leaf.
  135. Rooted treeA tree with all edges directed away from a chosen root; the root is the only in-degree-0 vertex.
  136. Does a tree with at least 2 vertices have at least two leaves?Yes, any tree with |V| ≥ 2 has at least two leaves.
  137. How many simple paths connect two vertices in a tree?Exactly one; this is also an equivalent definition of a tree.
  138. Vertex-edge formula for a treeIf V is nonempty, |V| = |E| + 1.
  139. Do two leaves alone guarantee a graph is a tree?No; the graph may still have a cycle or be disconnected.
  140. If a path u→v exists, does a simple path u→v exist?Yes; you can remove cycles from the path.
  141. Spanning treeA tree subgraph that contains all vertices of a connected graph.
  142. Does every connected graph have a spanning tree?Yes, every connected graph has a spanning tree.
  143. How do you build a spanning tree by deleting edges?Start with the graph and delete one edge from each cycle; deleting a cycle edge keeps it connected.
  144. When does the edge-deletion process stop for a spanning tree?At |V| − 1 edges; the result spans all vertices and has no simple cycles.
  145. Does a disconnected graph have a spanning tree?No; some pair has no path, and no subgraph can fix that.
  146. Spanning forestOne spanning tree for each connected component of a graph.
  147. k-coloringAssigning k colors so that the endpoints of every edge get different colors.
  148. Chromatic number χ(G)The smallest k for which a k-coloring of G exists.
  149. When is χ(G) = 0?Only for the empty graph, which has no vertices.
  150. What does χ(G) ≤ 1 mean?The graph has no edges at all.
  151. How does coloring relate to partitioning vertices?A k-coloring is a partition of V into k classes with no edge inside any class (k-partite).
  152. When is χ(G) ≤ 2?Exactly when G is bipartite: one side red, the other green.
  153. Planar graphA graph that can be drawn in the plane with no edge crossings.
  154. Four color theoremEvery planar graph has χ(G) ≤ 4.
  155. How do you turn a map into a graph for coloring?One vertex per country; an edge when countries share a border segment, not just a corner.
  156. Register allocation as graph coloringVertices are variables, edges join overlapping lifetimes, and colors are registers.
  157. What happens with a bad register allocation?Variables get copied between RAM and registers, making the program slower.
  158. Does χ = 2 limit the number of edges or maximum degree?No; 2-colorable graphs can have many edges and high degree.
  159. Does sharing only a corner point create an edge in a map graph?No; countries must share a border segment.
  160. Does a spanning tree keep all vertices?Yes; only edges are removed, never vertices.

Velocer jest darmowy: powtórki w odstępach i własne fiszki z dowolnego dokumentu.

PDF to flashcards · Lecture to flashcards · Practice exam · Syllabus study plan · Anki import

Więcej zestawów z University of Wisconsin–Madison