VelocerApri l'app

Velocer › Flashcard › University of Illinois Urbana-Champaign › CS 374: Intro to Algorithms and Models of Computation · UIUC

CS 374: Intro to Algorithms and Models of Computation · UIUC

Cards i use for CS 374. lmk if something looks off. · di altgeld_owl · 86 carte

University of Illinois Urbana-Champaign

Studia questo mazzo Incorpora

  1. What is the recursive definition of a string?A string is either the empty string ε, or has the form ax where a is a symbol and x is a string.
  2. How is the length of a string defined recursively?|ε| = 0 and |ax| = 1 + |x|.
  3. How is concatenation of strings defined recursively?ε • z = z and (ax) • z = a · (x • z).
  4. How is string reversal defined recursively?ε^R = ε and (ax)^R = x^R • a.
  5. What is the Iverson bracket [P]?It equals 1 if proposition P is true and 0 otherwise.
  6. How is the symbol count #(a, w) defined recursively?#(a, ε) = 0 and #(a, bx) = #(a, x) + [a = b].
  7. What lemma states the additive property of length under concatenation?|w • z| = |w| + |z|.
  8. Is concatenation of strings associative?Yes: concatenation is associative, so (u • v) • w = u • (v • w).
  9. What is the identity property of the empty string for concatenation?w • ε = w (the empty string is a right identity for concatenation).
  10. What proof pattern is used for strong induction on string length?Let w be arbitrary; assume the claim for every shorter string x, then split into cases w = ε and w = ax, using definitions and the induction hypothesis.
  11. When proving properties of w • z, on which argument should you induct and why?Induct on w with z fixed, because the recursive definition of concatenation recurses on w and leaves z alone.
  12. What alternative measure can be used for induction on concatenation?Induct on |w| + |z|.
  13. What result relates the length of a string to the length of its reversal?|w^R| = |w|.
  14. What is the reversal rule for concatenation?(w • z)^R = z^R • w^R.
  15. What result gives the symbol count over a concatenation?#(a, w • z) = #(a, w) + #(a, z).
  16. Why do inductive proofs on strings follow the recursive definition?Because the recursive definition provides the base case (ε) and step case (ax) that the induction must mirror.
  17. What regular expression matches all binary strings?\((0+1)^*\)
  18. What regular expression matches all binary strings that contain the substring 000?\((0+1)^*000(0+1)^*\)
  19. What regular expression matches binary strings with no substring 000?\((1+01+001)^*(\epsilon+0+00)\) — each 1 is preceded by at most two 0s.
  20. What regular expression matches binary strings where every run of 0s has length at least 3?\((1+0000^*)^*\) — whenever you write a 0, write at least three.
  21. What technique often simplifies writing a regular expression for strings with required symbols in certain orders?Case analysis on the order of required symbols (e.g., a 1 before, between, or after two 0s), giving a union of simple expressions.
  22. What four components define a DFA?A DFA is (Q, s, A, δ): a set of states Q, a start state s, a set of accepting states A, and a transition function δ.
  23. Why should DFA states be named mnemonically?Mnemonic names should explain what each state remembers about the input read so far, making the automaton's purpose clear.
  24. How do you build a DFA that accepts strings containing the substring 000?Track how many consecutive 0s have just been read (none, one, two), plus an accepting state once 000 has appeared.
  25. What is a dump (fail) state in a DFA?A state that absorbs strings which can never be accepted; it may be omitted if you state that all unspecified transitions lead to a dump state.
  26. How do you handle run-length conditions in a DFA?Track the parity or length of the current run and whether every previous run satisfied the rule.
  27. What is the product construction for DFAs?Run two DFAs in parallel using state pairs (p, q); the accepting set determines the boolean combination (and, or, implies, iff).
  28. What must always be stated explicitly when using the product construction?The accepting states.
  29. How many states does a DFA need for 'number of 0s even and number of 1s not divisible by 3'?6 states, from the product of 0s mod 2 and 1s mod 3.
  30. What does the accepting set of a product construction determine?The boolean combination of the two DFAs' acceptance conditions, such as and, or, implies, or iff.
  31. In a DFA for substring 000, what do the non-accepting states represent?They track whether none, one, or two consecutive 0s have just been read.
  32. What are the key features that distinguish an NFA from a DFA?An NFA may have multiple (or zero) start states, multiple transitions on the same symbol, and epsilon-transitions. It accepts a string if some sequence of guesses reaches an accepting state.
  33. How does an NFA typically handle problems like finding a suffix or substring?It guesses where the important substring begins, then verifies that the guess was correct.
  34. Why might an NFA use multiple start states?Multiple start states let the NFA guess which of several patterns it is looking for, such as which length-4 palindrome appears.
  35. For the language of strings whose 7th symbol from the end is 1, how do NFA and DFA sizes compare?A small NFA guesses the position, while the equivalent DFA needs 255 states (one per nonempty subset), showing subset blow-up.
  36. What does an NFA with no accepting states accept?It accepts nothing (the empty language).
  37. What does an NFA with no states at all accept?It accepts nothing.
  38. When does an NFA accept a string?When some sequence of guesses (nondeterministic choices) reaches an accepting state.
  39. What is an epsilon-transition in an NFA?A transition that consumes no input symbol, allowing the NFA to change state without reading a character.
  40. What does subset blow-up refer to in the NFA-to-DFA conversion?The exponential growth in the number of DFA states, since each DFA state corresponds to a subset of NFA states; e.g., 255 states for the 7th-from-end language.
  41. What is a fooling set for a language L?A set F of strings such that every pair of distinct strings x, y in F has a distinguishing suffix z, where xz ∈ L but yz ∉ L (or vice versa).
  42. How does an infinite fooling set prove a language is not regular?If L has an infinite fooling set, then L is not regular.
  43. In the fooling set proof template, what do you do after picking arbitrary distinct x and y from F?Exhibit a distinguishing suffix z and check that exactly one of xz, yz is in L.
  44. Give an example of a non-regular language provable with a fooling set involving powers of two.The language {0^(2^n)} of strings of 0s whose length is a power of two.
  45. What non-regular language involves strings with exactly twice as many 0s as 1s?The language of strings with exactly twice as many 0s as 1s, which can be shown non-regular via a fooling set.
  46. Name a non-regular language about matching halves of a string.The language {w#w}, where the string before # equals the string after #.
  47. What is a closure argument for proving a language is not regular?Assume L is regular; use closure properties (complement, intersection, renaming) to derive that a known non-regular language would be regular, giving a contradiction.
  48. In a closure argument, if L were regular and L ∩ R is known non-regular, what can you conclude?That L is not regular, since regularity of L would make L ∩ R regular by closure under intersection.
  49. How many fooling sets do you need to prove a language is not regular?Just one infinite fooling set.
  50. Must a fooling set argument account for every string in the language?No; the argument may ignore most strings in the language, as long as one infinite fooling set is exhibited.
  51. What role does the distinguishing suffix z play in a fooling set?For each pair x, y, z separates them: one of xz, yz is in L and the other is not.
  52. Give an example of a non-regular language involving nested brackets.The language of properly nested brackets, which can be shown non-regular with a fooling set.
  53. In the fooling set template, what is the final conclusion after showing F is an infinite fooling set?Since F is infinite, L is not regular.
  54. What is Cycled(L) in terms of strings?The set of strings yx such that xy ∈ L for some x, y.
  55. What is a context-free grammar for palindromes over {0,1}?S → ε | 0 | 1 | 0S0 | 1S1
  56. What general strategy is recommended for building CFGs that involve multiple cases?Use separate nonterminals for each case (case analysis), e.g., palindromes by length mod 3 or palindromes starting and ending with 1.
  57. How do you build a CFG for {0^m 1^n | m ≠ 2n}?Split into two cases, m < 2n and m > 2n, and generate each case with its own nonterminals.
  58. What does the grammar S → ε | 0 | 1 | 0S0 | 1S1 generate?All palindromes over the alphabet {0,1}.
  59. Why use separate nonterminals for different cases in a CFG?It keeps each case's generation rules independent and makes the grammar easier to construct and verify.
  60. How can you find an index i such that A[i] = i in a sorted array of distinct integers in O(log n) time?Define Δ[i] = A[i] - i, which is sorted because A is sorted and distinct. Binary search for Δ[i] = 0, computing Δ on the fly. If A[1] > 1, no such index exists, checkable in O(1).
  61. What is the recursion-tree method for analyzing divide-and-conquer recurrences?Sum the work at each level of the recursion tree. If the sums decrease geometrically, the root dominates; if they increase, the leaves dominate.
  62. Why is Δ[i] = A[i] - i sorted when A is a sorted array of distinct integers?Because A[i] is strictly increasing and i increases by 1 each step, so Δ[i+1] - Δ[i] = (A[i+1] - A[i]) - 1 ≥ 0 since A[i+1] - A[i] ≥ 1.
  63. What is the time complexity of finding an index i with A[i] = i using the Δ[i] binary search approach?O(log n), because binary search on Δ takes O(log n) time, computing Δ on the fly in O(1) per step.
  64. What is Piṅgala's recurrence for computing 2^n?It computes 2^n by repeated squaring: 2^n = (2^{n/2})^2 for even n, with appropriate handling for odd n.
  65. In the recursion-tree method, what does it mean if the level sums form a decreasing geometric series?The total work is dominated by the root level, so the complexity is proportional to the work at the root.
  66. In the recursion-tree method, what does it mean if the level sums form an increasing geometric series?The total work is dominated by the leaves, so the complexity is proportional to the work at the leaves.
  67. What is the general recipe for designing a dynamic programming solution?Define a recursive function in words (what it returns, in terms of its parameters), give the recurrence with base cases, say which call answers the problem, then memoize into an array, choose an evaluation order that respects dependencies, and analyze time.
  68. In the two-parameter longest decreasing subsequence (LDS) DP, what does LDS(i,j) represent?LDS(i,j) is the longest decreasing subsequence of A[j..n] with all elements below A[i].
  69. How can you compute a longest decreasing subsequence by reusing a longest increasing subsequence algorithm?Reverse the array or negate all elements, then compute the longest increasing subsequence on the transformed array.
  70. What is the purpose of a sentinel in dynamic programming, and give an example from LDS?Sentinels simplify boundary cases. For example, set A[0]=∞ so that every element is below the sentinel, then subtract 1 from the answer to remove the sentinel.
  71. Why does longest alternating subsequence require two mutually recursive functions?Because an alternating subsequence can start by going down or by going up, so you need one function for subsequences that go down first and another for those that go up first.
  72. What is the time complexity of the DP for longest alternating subsequence, and what greedy alternative exists?The DP is O(n^2). A greedy O(n) algorithm counts local minima and maxima, but greedy algorithms always need a correctness proof.
  73. In the ramp jumping problem, what does Next(i) represent and how is it computed?Next(i) is the first ramp past the landing point of ramp i. It is found by binary search in the sorted array of ramps.
  74. What is the time complexity of the ramp jumping DP, and how does it change with at most k jumps?Without a jump limit it is O(n log n). With at most k jumps, add a parameter for jumps used, giving O(n log n + nk).
  75. What is the recurrence for the minimum number of 1s needed to write n using +, ×, and 1s?Min1s(n) = min over sums Min1s(m) + Min1s(n−m) and over products Min1s(m) + Min1s(n/m) for divisors m of n. Base case Min1s(1)=1.
  76. Why must the best parenthesization DP for a ± expression track both Max(i,k) and Min(i,k)?Because subtracting a minimum subexpression can yield a maximum, so to find the maximum value you also need the minimum values of subexpressions.
  77. What is the time complexity of the best parenthesization DP for a ± expression, and how does it work?It tries every split point for each subexpression, tracking both max and min values. The time complexity is O(n^3).
  78. Why might you need to build a new graph instead of searching the graph given in a problem?The given graph may not be the one to search; many problems become standard graph searches once you build the right graph.
  79. In the number maze problem, what are the vertices and edges?Vertices are cells, and edges are legal moves with length M[i,j].
  80. How is the number maze solved, and what is its running time?It is solved by BFS shortest path from (1,1) to (n,n), running in O(n^2) since |V| = n^2 and |E| ≤ 4n^2.
  81. What is a product graph used for?It encodes extra constraints by combining copies of the original graph, such as tracking orientation or move count, then running BFS on the product graph.
  82. How do you model the constraint that moves must alternate horizontal and vertical?Use a product graph with two copies of each cell, one for each possible orientation of the next move.
  83. How do you model the constraint that the number of moves must be a multiple of 5?Use a product graph with five copies of each cell, representing the number of moves so far modulo 5.
  84. What should a write-up checklist for reducing a problem to a graph algorithm include?What the vertices and edges are (directed? a dag?), any vertex/edge values, how paths relate to the problem, which standard algorithm is called and how its output is used, and total running time including building the graph.
  85. When does an overall ranking consistent with every game's ranking exist?Exactly when the "ranked above" graph is acyclic; a topological order then gives the ranking.
  86. What graph structure represents rankings from games, and what algorithm produces a consistent overall ranking?A directed graph of "ranked above" relations; a topological order gives a consistent overall ranking if the graph is acyclic.

Velocer è gratis: ripetizione dilazionata e le tue carte da qualsiasi documento.

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

Altri mazzi di University of Illinois Urbana-Champaign