Velocer › 单词卡 › University of Wisconsin–Madison › COMP SCI 240 Midterm 3
COMP SCI 240 Midterm 3
Recurrences, big-o/asymptotic analysis, relations + functions, graphs + trees. · 作者:sunset_point_notes · 160 张卡片
- ComplexityA count of elementary operations as a function of input size n.
- Examples of elementary operationsInteger addition, bit shift, recursive call, comparison.
- What can n represent in complexity?An integer value, an array length, or the bit-length of a number.
- RecurrenceAn inductive definition of a sequence: first terms given, then each term from earlier ones.
- Solving a recurrenceFinding a closed form in n only, with no recursive terms like M().
- Recursive plan for Towers of HanoiMove n−1 disks to B, move the largest A→C, then move n−1 disks B→C.
- Moves recurrence for Towers of HanoiM(n) = 2M(n−1) + 1 for n ≥ 1, with M(0) = 0.
- Closed form for Towers of Hanoi movesM(n) = 2ⁿ − 1.
- Induction step for M(n) = 2ⁿ − 1Assume M(n) = 2ⁿ − 1; then 2(2ⁿ − 1) + 1 = 2ⁿ⁺¹ − 1.
- Three steps to analyze a recursive algorithmDerive a recurrence, compute first terms and conjecture, then prove by induction.
- Iterative multiplication loop count L(a, b)L(a, b) = ⌊log₂ b⌋ + 1 for b ≥ 1, and L = 0 when b = 0.
- What happens each pass of iterative multiplication?Halve y (floor), double x, and add x to p if y is odd.
- If 2ᵏ ≤ b < 2ᵏ⁺¹, what is L(a, b)?L = k + 1.
- Recursive multiplication MULT(a, b) when b is evenMULT(a, b) = 2 · MULT(a, ⌊b/2⌋).
- Recursive multiplication MULT(a, b) when b is oddMULT(a, b) = 2 · MULT(a, ⌊b/2⌋) + a.
- Complexity measure for recursive multiplicationThe number of shifts, since multiplying by 2 is a left shift.
- Shift recurrence for recursive multiplicationS(a, b) = S(a, ⌊b/2⌋) + 1, with S(a, 0) = 0.
- What does S(a, b) depend on?Only on b, not on a.
- Closed form for S(a, b) when 2ᵏ ≤ b < 2ᵏ⁺¹S(a, b) = k + 1.
- Key bound in the strong induction proof for SIf 2ᵏ ≤ B+1 < 2ᵏ⁺¹, then 2ᵏ⁻¹ ≤ ⌊(B+1)/2⌋ < 2ᵏ.
- GCD recursive rule when a = bGCD(a, b) = a.
- 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.
- 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).
- R(a, b) for the GCD algorithmThe number of recursive calls; it is symmetric in a and b.
- R₀(n) definitionThe maximum number of recursive calls over all inputs a, b ≤ n.
- Relation between R(a, b) and R₀R(a, b) ≤ R₀(max(a, b)).
- Recurrence for R₀(n)R₀(n) ≤ 1 + R₀(n−1).
- Closed form for R₀(n)R₀(n) = n − 1.
- Worst-case input for the GCD algorithm(n, 1), which gives the chain (n−1,1), …, (1,1) and n−1 calls.
- How is R₀(n) = n − 1 proved?Show ≥ n−1 using the worst-case input, and ≤ n−1 by strong induction.
- Does a termination proof also prove efficiency?No; efficiency needs a count of operations.
- Is M(n) about 2ⁿ or 2ⁿ⁻¹?About 2ⁿ; 2ⁿ⁻¹ comes from a variant with M′(1) = 1.
- Why must you use floor division in these recurrences?Because halving an integer gives ⌊b/2⌋, not b/2.
- Which arguments does GCD complexity depend on?Both arguments, unlike multiplication which depends only on b.
- Asymptotic equivalence f ~ gThe ratio f(n)/g(n) → 1 as n → ∞.
- Formal definition of f ~ gFor every ε > 0 there is N so that 1−ε ≤ f/g ≤ 1+ε for all n ≥ N.
- Does ~ keep constant factors?Yes: 12n² ~ 12n², not ~ n².
- Big Theta f = Θ(g)The ratio f/g is squeezed between constants c and d for large n.
- Does Θ absorb constant factors?Yes: 12n² + 10⁹n + 1/n = Θ(n²).
- If f ~ g, what follows for Θ?f = Θ(g); take c = 1/2 and d = 3/2.
- What kind of bound is Θ?The tight two-sided bound.
- Big Oh f = O(g)f/g ≤ d for large n; an upper bound only.
- Big Omega f = Ω(g)f/g ≥ c for large n; a lower bound only.
- Θ in terms of O and Ωf = Θ(g) ⇔ f = O(g) and f = Ω(g).
- When do you use O?For 'runs within at most'.
- When do you use Ω?For 'takes at least'.
- If lim f/g = c > 0 finite, what follows?f = Θ(g).
- If lim f/g = 0, what follows?f = O(g), but not Ω(g).
- If lim f/g = ∞, what follows?f = Ω(g), but not O(g).
- Must the limit f/g exist for O, Ω or Θ to hold?No; the limit need not exist.
- Closed form for Fibonacci numbersFₙ = (φⁿ − (1−φ)ⁿ)/√5, with φ = (1+√5)/2.
- Asymptotic growth of FₙFₙ ~ φⁿ/√5, so Fₙ = Θ(φⁿ).
- Compare Fₙ with n²Fₙ ≠ O(n²), but n² = O(Fₙ); exponential beats any polynomial.
- Growth of log(n!)log(n!) = Θ(n log n).
- Upper bound for log(n!)Each of n terms is ≤ log n, so log(n!) ≤ n log n.
- Lower bound for log(n!)About n/2 largest terms are each ≥ log(n) − 1, so log(n!) ≥ (n/2)(log n − 1).
- Which is stricter, ~ or Θ?~ is stricter; Θ allows any constant ratio, ~ demands ratio → 1.
- Does f = O(g) imply f = Θ(g)?No; O is only an upper bound.
- Do constants vanish inside Θ?Yes, they vanish inside Θ.
- Do constants vanish under ~?No; they do not vanish under ~.
- What inputs do asymptotic claims concern?Only large n; small-n behavior is irrelevant.
- Binary relationA set of ordered pairs (x, y) satisfying a predicate P(x, y), with x ∈ D₁ and y ∈ D₂.
- Cartesian product A × BThe set {(a, b) | a ∈ A and b ∈ B}; order matters.
- When does (a₁, b₁) = (a₂, b₂)?Exactly when a₁ = a₂ and b₁ = b₂.
- Relation R from A to BA subset of A × B; A is the domain and B is the codomain.
- Relation on a set AA relation from A to A, i.e. a subset of A × A.
- What does xRy mean?That the ordered pair (x, y) is in the relation R.
- How do you draw a relation on one set?As a digraph: an arrow a → b means aRb; two arrows if both directions hold.
- Bipartite graph of a relation from A to BA on one side, B on the other, with an edge for each pair aRb.
- FunctionA relation where each a ∈ A has at most one b ∈ B.
- Total functionEvery a ∈ A has exactly one b ∈ B.
- 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.
- Inverse relation R⁻¹aRb ⇔ bR⁻¹a; it always exists, unlike an inverse function.
- Is the mother relation a function?No, because a person can have more than one child.
- Is the spouse relation total?No; it's a function but not total, since not everyone is married.
- Injective (one-to-one) functionf(a₁) = f(a₂) ⇒ a₁ = a₂; equivalently, f⁻¹ is a function.
- Surjective (onto) functionEvery b ∈ B has some a ∈ A with f(a) = b.
- Bijective functionA function that is both injective and surjective.
- Injective total f: A → B tells you what about sizes?|A| ≤ |B|.
- Surjective f: A → B tells you what about sizes?|A| ≥ |B|.
- Bijective total f: A → B tells you what about sizes?|A| = |B|.
- How do you prove |A| ≤ |B|?Build an injective total map from A to B.
- Reflexive relation on AFor every a, aRa.
- Antireflexive relation on AFor every a, ¬aRa.
- Symmetric relationaRb ⇔ bRa.
- Antisymmetric relation(aRb ∧ bRa) ⇒ a = b.
- Transitive relation(aRb ∧ bRc) ⇒ aRc.
- Is ⊆ reflexive, antisymmetric, transitive?Yes, all three.
- Is < reflexive?No, it's antireflexive; it is antisymmetric and transitive.
- Is ≤ a total order?Yes; it's reflexive, antisymmetric, transitive, and total.
- Is divisibility | an order relation on the positives?Yes: reflexive, antisymmetric, transitive, but not total.
- Why is divisibility transitive?If b = ka and c = lb, then c = (lk)a.
- Equivalence relationA relation that is reflexive, symmetric, and transitive.
- Is ≠ an equivalence relation?No; it's symmetric but not reflexive or transitive.
- Partition of a set AA collection of nonempty subsets whose union is A and which are pairwise disjoint.
- Equivalence class [a]The set {b | aRb}.
- When is [a] = [b]?Exactly when aRb.
- If ¬aRb, what about [a] ∩ [b]?It's empty; the classes are disjoint.
- How does an equivalence relation give a partition?The equivalence classes [a] form the partition of A.
- How does a partition give an equivalence relation?Define aRb when a and b are in the same class.
- Order relationA relation that is antisymmetric and transitive.
- Strict order relationAn order relation that is also antireflexive.
- Total orderFor any x ≠ y, either xRy or yRx.
- Is | a total order on the positives?No; 3 ∤ 7 and 7 ∤ 3, so they're incomparable.
- Extension R̃ of an order RA total order with xRy ⇒ xR̃y; ≤ extends | on the positives.
- Ternary relation example{(x, y, z) | x² + y² + z² = 1}, the unit sphere in ℝ³.
- DigraphA directed graph G = (V, E): V is vertices, E is a multiset of ordered pairs from V×V.
- Simple graphA graph where E is a set, so no duplicate edges; E is a binary relation on V.
- 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.
- Length of a pathThe number of edges in the path.
- Empty pathA path of length 0 whose start and end vertex are the same.
- CycleA path with at least one edge that begins and ends at the same vertex. Example: v_1 → v_2 → v_3 → v_1.
- Transitive closure relation uRvuRv holds exactly when a path exists from u to v.
- Why is the transitive closure of a digraph reflexive?A length-0 path always exists from any vertex to itself, even with no edges.
- Is the transitive closure of a digraph symmetric?Not in general: an edge (u,v) gives no path from v back to u.
- DAGA directed acyclic graph: a digraph that contains no cycles.
- Why can't a DAG have a self-loop (v,v)?A self-loop is a cycle of length 1.
- What do DAGs model?Prerequisites, software dependencies, and task ordering; cycles make completion impossible.
- Topological orderingA total order ≤ on V such that every edge (u,v) has u ≤ v for u ≠ v.
- Does every DAG have a topological ordering?Yes, every DAG has one.
- Does every finite nonempty DAG have an in-degree-0 vertex?Yes; otherwise following incoming edges would revisit a vertex and form a cycle.
- In-degree and out-degreeIn-degree counts edges ending at v; out-degree counts edges starting at v.
- In a topological order, which way do arrows point?Left to right.
- Incident edge and vertexAn edge e and vertex v are incident when v is an endpoint of e.
- Bipartite graphA graph whose vertices split into V_left and V_right with no edge inside either part.
- Connected componentThe subgraph on one equivalence class of the transitive closure.
- Connected graphA graph with at most one connected component.
- Degree deg(v)The number of edges containing v; a self-loop counts twice.
- Handshake formulaΣ deg(v) = 2|E|, because each edge contributes 2 to the degree sum.
- How many odd-degree vertices can a graph have?An even number.
- Simple pathA path with no repeated edge; only the start vertex may repeat, and only at the end.
- Simple cycleA non-empty simple path whose start vertex equals its end vertex.
- TreeA connected graph with no simple cycles.
- LeafA vertex of degree 1; in a single-vertex tree, that vertex is a leaf.
- Rooted treeA tree with all edges directed away from a chosen root; the root is the only in-degree-0 vertex.
- Does a tree with at least 2 vertices have at least two leaves?Yes, any tree with |V| ≥ 2 has at least two leaves.
- How many simple paths connect two vertices in a tree?Exactly one; this is also an equivalent definition of a tree.
- Vertex-edge formula for a treeIf V is nonempty, |V| = |E| + 1.
- Do two leaves alone guarantee a graph is a tree?No; the graph may still have a cycle or be disconnected.
- If a path u→v exists, does a simple path u→v exist?Yes; you can remove cycles from the path.
- Spanning treeA tree subgraph that contains all vertices of a connected graph.
- Does every connected graph have a spanning tree?Yes, every connected graph has a spanning tree.
- 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.
- 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.
- Does a disconnected graph have a spanning tree?No; some pair has no path, and no subgraph can fix that.
- Spanning forestOne spanning tree for each connected component of a graph.
- k-coloringAssigning k colors so that the endpoints of every edge get different colors.
- Chromatic number χ(G)The smallest k for which a k-coloring of G exists.
- When is χ(G) = 0?Only for the empty graph, which has no vertices.
- What does χ(G) ≤ 1 mean?The graph has no edges at all.
- 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).
- When is χ(G) ≤ 2?Exactly when G is bipartite: one side red, the other green.
- Planar graphA graph that can be drawn in the plane with no edge crossings.
- Four color theoremEvery planar graph has χ(G) ≤ 4.
- 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.
- Register allocation as graph coloringVertices are variables, edges join overlapping lifetimes, and colors are registers.
- What happens with a bad register allocation?Variables get copied between RAM and registers, making the program slower.
- Does χ = 2 limit the number of edges or maximum degree?No; 2-colorable graphs can have many edges and high degree.
- Does sharing only a corner point create an edge in a map graph?No; countries must share a border segment.
- Does a spanning tree keep all vertices?Yes; only edges are removed, never vertices.
Velocer 免费:间隔重复,还能从任何文档创建你自己的卡片。
PDF to flashcards · Lecture to flashcards · Practice exam · Syllabus study plan · Anki import
University of Wisconsin–Madison 的更多牌组
- comp sci 240 midterm 1
- comp sci 240 midterm 2
- COMP SCI 240 Final
- comp sci 300 full course review
- CS 639: Introduction to Reinforcement Learning · UW-Madison
- CS 839: Reinforcement Learning · UW-Madison
- CS 544: Intro to Big Data Systems · UW-Madison
- CS 580: Intelligent Robotics · UW-Madison
- CS 784: Foundations of Data Management · UW-Madison
- CS 880: Quantum Algorithms · UW-Madison
- CS 765: Data Visualization · UW-Madison
- CS 639: AI Coding · UW-Madison