2024-05-23T20:19:20+03:00[Europe/Moscow] en true <p>Aggregate amortization general formula</p>, <p>Accounting amortization analogy</p>, <p>Optimization problem definition</p>, <p>Greedy algorithms: optimal substructure definition</p>, <p>Greedy algorithms: independent subproblems definition</p>, <p>Three conditions that allow greedy algorithms to be correct</p>, <p>Greedy algorithms: non-overlapping subproblems definition</p>, <p>Huffman coding: prefix code definition</p>, <p>Huffman coding steps</p>, <p>Divide and conquer: three general steps</p>, <p>What type of algorithmic design approach does merge sort take?</p>, <p>Three methods for finding the time complexity of recursive algorithms</p>, <p>Dynamic programming general steps</p>, <p>What algorithm family does Huffman Coding belong to?</p>, <p>Master theorem: General formula for recurrence relations</p>, <p>Master theorem: what is T(n) when a &gt; b^c?</p>, <p>Master theorem: what is T(n) when a = b^c?</p>, <p>Master theorem: what is T(n) when a &lt; b^c?</p>, <p>(a×b)modc = ________</p>, <p>Modular arithmetic: additive inverse (y) formula</p>, <p>Modular arithmetic: multiplicative inverse (x^-1) formula</p>, <p>Fermat's little theorem formula</p>, <p>What is a relative prime?</p>, <p>What is ϕ(n)?</p>, <p>ϕ(pq) = ________, where p and q are two prime numbers</p>, <p>Naive fibonacci recursion equation</p>, <p>What is the complexity of naive fibonacci?</p>, <p>digraph meaning and notation</p>, <p>Transitive closure of a directed graph definition</p>, <p>Floyd-Warshall general steps</p>, <p>Acyclic graph definition</p>, <p>2 constraints for minimum spanning tree (apart from having the minimum cost/weight)</p>, <p>Cycle property of minimum spanning trees</p>, <p>Is this graph (bold lines) a cycle?</p>, <p>Partition (graph) property</p>, <p>Kruskal general steps</p>, <p>Can a flow network have negative edge weights?</p>, <p>Two key vertices in a flow network</p>, <p>Flows and cuts: what is f(e)?</p>, <p>Flows and cuts: what is E<sup>-</sup>(v)?</p>, <p>Flows and cuts: what is E<sup>+</sup>(v)?</p>, <p>Flows and cuts: What is the capacity rule?</p>, <p>Flows and cuts: What is the conservation rule?</p>, <p>The flow of a graph is equal to ________</p>, <p>Flows/cuts: Can one of the partitions of a cut contain both the source and the sink?</p>, <p>A forward edge of cut 𝜒 has its origin in ___ and destination in __, and vice versa for a backward edge</p>, <p>Does an edge need to be either forward or backward?</p>, <p>The flow across a cut is the sum of ________</p>, <p>The capacity of a cut is the sum of ______</p>, <p>True or false: the flow across a cut is the same as the flow across the network</p>, <p>Notes flows and cuts</p>, <p>Flows/cuts: Is the minimum cut (the cut with the least capacity) equal to the flow?</p>, <p>Flows/cuts: true or false: A path path π must follow the direction of the edges it traverses</p>, <p>Notes flows and cuts</p>, <p>Flows/cuts: augmenting path edge properties</p>, <p>What is a matching in a bipartite graph?</p>, <p>Notes: how the bipartite highest matching problem can be converted into a maximum flow problem</p>, <p>What is ϕ(n) when n is prime?</p>, <p>Master theorem: what is a?</p>, <p>Master theorem: what is b?</p>, <p>Master theorem: what is c?</p>, <p>the additive inverse of a (mod n) is ______</p>, <p>the multiplicative inverse of a (mod n) is a number b such that ______</p>, <p>A decision problem is one where the answer is ____</p>, <p>Every decision problem implicitly defines a ________</p>, <p>P is the class of problems that can be efficiently _________, while NP is the class of problems that can be efficiently _________</p>, <p>P vs NP: a verification algorithm B is an algorithm which takes as input a pair</p><p>of strings (x,y), where x is a problem instance and y is a ________</p>, <p>A verification algorithm B is sound if whenever 𝑥 ∉ 𝐿 (L = the set of problems for which a solution can be checked for correctness efficiently) ________________________________________</p>, <p>A verification algorithm B is complete if whenever 𝑥 ∈ 𝐿 there is a certificate which will convince B, i.e. there exists ______________________________________________</p>, <p>A language L is in NP if it has a verifier which is (1) _________,</p><p> (2) ______ and (3) _________</p>, <p>Is problem reduction (P vs NP) symmetric?</p>, <p>A problem is NP-hard if _______________</p>, <p>A problem is NP-complete if _______________</p>, <p>In metric TSP, each node is _________</p>, <p>2-approximation for metric-TSP, three steps</p>, <p>Why is it called 2-approximation?</p>, <p>Edges are incident if ____________</p>, <p>Vertices are adjacent if ___________</p>, <p>2-approximation vertex cover algorithm</p>, <p>Vertex cover definition</p>, <p>An edge is incident to a vertex if __________</p>, <p>Backtracking / branch and bound notes</p>, <p>SAT stands for ________ decision problems</p>, <p>Branch and bound key principle: What is needed is some way to stop backtracking when _________</p>, <p>Branch and bound notes</p>, <p>Standard form for linear programs: notes</p>, <p>Notes on deriving the dual lp from the primal</p>, <p>Fisher yates (random permutation generation algorithm) steps</p>, <p>(convex hulls) How to calculate the orientation of nodes</p> flashcards
Algorithmic Design

Algorithmic Design

  • Aggregate amortization general formula

    Number of steps taken / size of input

  • Accounting amortization analogy

    Simple operations are 'regular work days' and get an income of some constant amount. They pay their cost with this income and put the rest in 'savings'. Expensive operations are 'vacation days', and can use savings to pay their cost. As long as savings never goes below 0 (which you can prove by induction), we can prove a time complexity.

  • Optimization problem definition

    Problems where there is a set of configurations and an objective function, and the goal is to find a configuration that maximizes (or minimizes) the value of the objective function. eg knapsack

  • Greedy algorithms: optimal substructure definition

    A problem has it if an optimal solution can be constructed from optimal solutions of its subproblems.

  • Greedy algorithms: independent subproblems definition

    Two subproblems that don't share resources, or the solution of one doesn't affect the solution of the other

  • Three conditions that allow greedy algorithms to be correct

    Optimal substructure, independent subproblems, non-overlapping subproblems

  • Greedy algorithms: non-overlapping subproblems definition

    Two subproblems are overlapping if they are really the same subproblem that occurs as a subproblem of different problems

  • Huffman coding: prefix code definition

    No code word is a prefix of any other code word

  • Huffman coding steps

    1) Build a frequency table

    2) Sort characters from lowest to highest frequency

    3) Pull the two lowest-valued nodes/trees from the list

    4) Create a new tree with the lowest-valued node as its left subtree and the highest-value node as its right subtree

    5) Put this subtree back into the list with its value being the aggregate value of all its trees/nodes

    6) Sort the list again

    7) Repeat until there is only 1 tree, which is the final answer

  • Divide and conquer: three general steps

    1) DIVIDE the problem into subproblems

    2) Recursively solve the subproblems (CONQUER)

    3) Put the solutions together to create a solution to the big problem

  • What type of algorithmic design approach does merge sort take?

    Divide and conquer

  • Three methods for finding the time complexity of recursive algorithms

    Iterative substitution, recursion trees, master theorem

  • Dynamic programming general steps

    Start with the base case, build up to more complex cases

  • What algorithm family does Huffman Coding belong to?

    Greedy algorithms

  • Master theorem: General formula for recurrence relations

  • Master theorem: what is T(n) when a > b^c?

  • Master theorem: what is T(n) when a = b^c?

  • Master theorem: what is T(n) when a < b^c?

  • (a×b)modc = ________

    (amodc×bmodc)modc

  • Modular arithmetic: additive inverse (y) formula

    (x + y) mod n = 0

  • Modular arithmetic: multiplicative inverse (x^-1) formula

    (x * x^-1)mod n = 1

  • Fermat's little theorem formula

  • What is a relative prime?

    A number is relatively prime (or coprime) to another if their greatest common divisor is 1

  • What is ϕ(n)?

    The number of non-negative integers less than n that are relatively prime to n

  • ϕ(pq) = ________, where p and q are two prime numbers

    (p-1)(q-1)

  • Naive fibonacci recursion equation

  • What is the complexity of naive fibonacci?

    O(2^n)

  • digraph meaning and notation

    directed graph. G = (V,E)

  • Transitive closure of a directed graph definition

    A graph with the same nodes (vertices), but whenever there is an indirect path from u to v, it includes u,v as an edge

  • Floyd-Warshall general steps

    1) Populate G* (the transitive closure graph) with the same nodes and vertices as G

    2) Go through all the edges and whenever there is a pair (vi, vj) and (vj, vk), add (vi,vk).

    3) Repeat until there are no more transitive edges

  • Acyclic graph definition

    for any given vertex if you follow an edge that connects that vertex to another, there is no path in the graph to get back to that initial vertex

  • 2 constraints for minimum spanning tree (apart from having the minimum cost/weight)

    1) all vertices must be included 2)The mst must be acyclic

  • Cycle property of minimum spanning trees

    Given a cycle, the MST for that cycle can be obtained by removing the highest-weighted edge

  • Is this graph (bold lines) a cycle?

    Yes

    Yes

  • Partition (graph) property

    • Consider a partition of the vertices of G intosubsets U and V• Let e be an edge of minimum weight across thepartition• There is a minimum spanning tree of G containingedge e

  • Kruskal general steps

    • Sort the edges, lightest to heaviest• Divide all the vertices into clusters, one vertex per cluster• Start with the lightest edge, e• If e connects two clusters• Add e to the MST• Create a new cluster by merging those clusters• Else• Discard e• Keep going until there is only one cluster

  • Can a flow network have negative edge weights?

    no

  • Two key vertices in a flow network

    Source (s) and sink (t)

  • Flows and cuts: what is f(e)?

    The amount of flow over edge e

  • Flows and cuts: what is E-(v)?

    the set of incoming edges for vertex v

  • Flows and cuts: what is E+(v)?

    the set of outgoing edges for vertex v

  • Flows and cuts: What is the capacity rule?

    An edge always has at least 0 flow, and never has more flow than its capacity

  • Flows and cuts: What is the conservation rule?

    The flow entering a vertex must equal the flow going out (except for s and t)

  • The flow of a graph is equal to ________

    the sum of the outgoing flows from the source, or the incoming flows to the sink

  • Flows/cuts: Can one of the partitions of a cut contain both the source and the sink?

    No

  • A forward edge of cut 𝜒 has its origin in ___ and destination in __, and vice versa for a backward edge

    Vs, Vt

  • Does an edge need to be either forward or backward?

    No

  • The flow across a cut is the sum of ________

    the flows across the forward edges minus the sum of the flows across the backwards edges

  • The capacity of a cut is the sum of ______

    the capacities of all the forward edges

  • True or false: the flow across a cut is the same as the flow across the network

    true

  • Notes flows and cuts

    no matter how one cuts the network, the value of the capacityat that cut is an upper bound for the flow of the network as a whole

  • Flows/cuts: Is the minimum cut (the cut with the least capacity) equal to the flow?

    Yes

  • Flows/cuts: true or false: A path path π must follow the direction of the edges it traverses

    true

  • Notes flows and cuts

    If e is a forward edge, the residual capacity of e is the amount of capacity that fhas not consumed yet

  • Flows/cuts: augmenting path edge properties

    1) f(e) < c(e) if e is a forward edge (non full and forward)2) f(e) > 0 if e is a backward edge (non empty and backward)

  • What is a matching in a bipartite graph?

    a set of edges that have no endpoints in common

  • Notes: how the bipartite highest matching problem can be converted into a maximum flow problem

  • What is ϕ(n) when n is prime?

    n-1

  • Master theorem: what is a?

    a = number of pieces the problem gets divided in with each call. For mergesort A = 2

  • Master theorem: what is b?

    b = denominator of fraction of input size that each piece takes (usually the same of a, but can be different). For mergesort b = 2

  • Master theorem: what is c?

    theta (n^c) is how complex it is to put the pieces back together when you finish, so c=1 for merge sort

  • the additive inverse of a (mod n) is ______

    n-a

  • the multiplicative inverse of a (mod n) is a number b such that ______

    (a * b) mod n = 1

  • A decision problem is one where the answer is ____

    yes or no

  • Every decision problem implicitly defines a ________

    language

  • P is the class of problems that can be efficiently _________, while NP is the class of problems that can be efficiently _________

    solved, checked

  • P vs NP: a verification algorithm B is an algorithm which takes as input a pair

    of strings (x,y), where x is a problem instance and y is a ________

    certificate

  • A verification algorithm B is sound if whenever 𝑥 ∉ 𝐿 (L = the set of problems for which a solution can be checked for correctness efficiently) ________________________________________

    there is no certificate which will satisfy B, i.e. B will output 0 on input (x,y) for any y

  • A verification algorithm B is complete if whenever 𝑥 ∈ 𝐿 there is a certificate which will convince B, i.e. there exists ______________________________________________

    some y (of size bounded by a polynomial q(n)) such that B will output 1 on input (x,y)

  • A language L is in NP if it has a verifier which is (1) _________,

    (2) ______ and (3) _________

    deterministic polynomial-time, sound, complete

  • Is problem reduction (P vs NP) symmetric?

    No

  • A problem is NP-hard if _______________

    every problem in NP can be reduced to it

  • A problem is NP-complete if _______________

    it is NP-hard and an element of NP

  • In metric TSP, each node is _________

    connected to every other node; there is an edge between every two nodes.

  • 2-approximation for metric-TSP, three steps

    1. Construct a minimal spanning tree M from G2. Construct an Euler-tree traversal E of M •E starts and ends at the same vertex and traverses each edge of M exactly once in each direction 3. Construct a tour T from E by marching through the edges of E, but each time we have (u, v) and (v, w) in E, such that v has already been visited, we replace those two edges with (u, w)

  • Why is it called 2-approximation?

    Cost of the solution is at most twice of the optimal one

  • Edges are incident if ____________

    there is a vertex between them

  • Vertices are adjacent if ___________

    there is an edge between them

  • 2-approximation vertex cover algorithm

    1) Initialize the result as {}2) Consider the set of all edges in G. Let the set be E.3) Do following while E is not emptya) Pick an arbitrary edge (u, v) from set E and add 'u' and 'v' to resultb) Remove all edges from E which are either incident on u or v4) Return result

  • Vertex cover definition

    Given a graph, find a minimal subset v of vertices such that every edge in the original graph is incident to some vertex in v

  • An edge is incident to a vertex if __________

    it is an endpoint to that vertex.

  • Backtracking / branch and bound notes

  • SAT stands for ________ decision problems

    satisfiability (relating to logical formulas)

  • Branch and bound key principle: What is needed is some way to stop backtracking when _________

    a candidate solution is worse than a solution one already has(There is no need to continue working on a candidate solution that is guaranteed to be worse than a solution you already have)

  • Branch and bound notes

  • Standard form for linear programs: notes

  • Notes on deriving the dual lp from the primal

  • Fisher yates (random permutation generation algorithm) steps

    • Informally:• Given an array arr of length n• Start at the last element in the array (arr[n-1])• Roll a random number r in [0, ..., n-1]• Swap the last element with the element in arr[r]• Do this for the next-to-last element and a random number in [0, ..., n-2]• Keep doing this for all elements except arr[0]• You can do arr[0], too, it won’t hurt anything• All the elements are now in random spots

  • (convex hulls) How to calculate the orientation of nodes