Algorithms Final

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/46

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

47 Terms

1
New cards

f = o(g) (little o)

f(n)/g(n), analogous to <, limit = 0

2
New cards

f = ω(g) (little omega)

f(n)/g(n), analogous to >, limit = inf

3
New cards

f = O(g) (big O)

f(n)/g(n), analogous to < or equal to, limit = finite

4
New cards

f = Ω(g) (big omega)

f(n)/g(n), analogous to > or equal to, limit = positive

5
New cards

f = θ(g)

f(n)/g(n), analogous to =, limit = finite and positive

6
New cards

Asymptotic notation trick for polynomials

  • deg(f) < deg(g) → f = o(g)

  • deg(f) > deg(g) → f = ω(g)

  • deg(f) = deg(g) → f = θ(g)

7
New cards

Asymptotic notation trick for logs, exponentials, and polynomials

logs are little o of polynomials which are little o of exponentials

8
New cards

Binary search

finds a specific value in a sorted array by repeatedly dividing the search interval in half

O(log n)

9
New cards

merge sort

  • sorts a given list of numbers by first dividing them into two equal

    halves, sorting each half separately by recursion, and then combining the results of these recursive calls—in the form of the two sorted halves

  • T(n) = 2T(n/2) + O(n)

  • O(n log n)

10
New cards

quicksort

  • picks an element in the array as a pivot. Partition the array so values < pivot are to its left and values > pivot are to its right. Recursively sort the two halves

  • Best case: T(n) = 2T(n/2) = O(n) Worst case: T(n) = T(1) + T(n-1) = O(n)

  • Expected time: O(n log n) Worst time: O(n2)

11
New cards

Dselect

to find the kth smallest element in a list or array. It works by dividing the input array into smaller groups, finding the median of each group, and then recursively finding the median of those medians.

12
New cards

BFS

explores all neighbors of a node before moving to the next level, used to find shortest path

13
New cards

DFS

  • traversing or searching tree or graph data structures, exploring as far as possible along each branch before backtracking

  • mark node as visited

  • O(V+E)

14
New cards

Kosaraju’s

  • Finds all SCCs in graph

  • Compute transpose graph GT. Do DFS on GT. Do DFS on G (processing vertices in reverse order of finish time of previous step).

  • O(n+m)

15
New cards

topological sorting

Do DFS, keep track of when each visit call terminates, return vertices in reverse order of finish time

O(V+E)

16
New cards

DAG Shortest Paths

  • Create a topological order of vertices. For every vertex being processed, we update distances of its adjacent using distance of current vertex.

  • O(n+m)

17
New cards

sink

a vertex with no outgoing edges

18
New cards

source

a vertex with no ingoing edges

19
New cards

Dynamic programming

Identify a useful collection of subproblems

Find a recursive relationship between subproblem solutions

Apply it bottom-up, storing subproblem solutions as you go

20
New cards

path-MWIS

maximize total weight of an independent set
DP?

21
New cards

longest increasing subsequence

Takes an array of integers and produces the maximum length of an increasing subsequence

DP?

22
New cards

sequence alignment (edit distance)

  • replace, insert, delete

  • find DAG shortest path from (0,0) to (m,n)

  • DP?

23
New cards

knapsack

There are i items, each with a positive integer value and positive integer weight and there is a capacity W. Find a set to maximize value within the capacity.

DP?

24
New cards

Bellman-Ford

Negative cycle detection algorithm

repeatedly checks and updates distance estimates from the source node to all other nodes (spam updates)

O(VE)

25
New cards

Floyd-Warshall

find the shortest paths between all pairs of vertices in a weighted graph, whether directed or undirected, with or without negative edge weights (but without negative cycles)

It works by iteratively updating a matrix of shortest path distances, considering each vertex as a potential intermediate point in the path

O(n³) n = vertices

26
New cards

Dijkstra’s

find the shortest paths from a single source vertex to all other vertices in a graph.

It operates by iteratively exploring the graph, marking vertices as visited, and updating shortest path distances until all vertices are considered

Worst case: O(V²), normally O((V+E) log V)

DP

27
New cards

Prim’s

find the most efficient way to connect all vertices in a graph with the least total edge weight

find the minimum spanning tree (MST) of a connected, weighted, undirected graph.

It works by iteratively adding the minimum-weight edge that connects a vertex in the MST to a vertex not yet in the MST.

O(E + V log V)

28
New cards

Ford-Fulkerson

find the maximum flow in a network.

It works by repeatedly finding augmenting paths and increasing the flow along them until no more such paths exist

Its purpose is to determine the maximum amount of flow that can be sent from a source to a sink within a network, given the capacity constraints of the edges

O(|f*||E|)

29
New cards

Edmonds-Karp

a maximum flow algorithm that uses BFS to find augmenting paths in a flow network.

a variant of Ford-Fulkerson

determine the maximum amount of flow that can be sent from a source to a sink in a network

O(V * E^2)

30
New cards

capacity

the maximum amount of flow that can be transported across an edge in a given period of time

31
New cards

residual network

a representation of the remaining capacity for sending flow through a flow network.

32
New cards

augmenting path

path from the source s to the sink t in the residual network where every edge on the path has positive residual capacity. It represents a route along which additional flow can be pushed.

33
New cards

(s, t)-cut

a partition of the graph’s vertices into two disjoint sets S and T such that:

  • The source s is in set S

  • The sink t is in set

The cut refers to the set of edges going from S to T.

34
New cards

max-flow min-cut theorem

the maximum flow through a network from a source to a sink is equal to the capacity of the minimum cut in that network

35
New cards

P

A yes or no problem is in ___ if the answer can be computed in polynomial time

36
New cards

verifier

an algorithm that can quickly confirm whether a given solution to a problem is correct

37
New cards

certificate

it's a proof or solution that can be easily checked, but might be hard to find

38
New cards

NP

a class of problems where a solution, if given, can be verified in polynomial time

39
New cards

Karp reducibility (≤p)

the concept of reducing one problem in NP to another problem in NP within polynomial time.

This means that if a problem A is ___ to a problem B, then if an efficient algorithm exists for problem B, it also implies an efficient algorithm for problem A. 

40
New cards

NP-hard

used to classify problems that are, in a sense, as hard as the hardest problems in NP

41
New cards

NP-complete

if a problem is in NP and is NP-hard

problem within the complexity class NP that has the property that every other problem in NP can be reduced to it in polynomial time

42
New cards

3SAT

asks whether a given 3CNF formula is satisfiable (is it possible to assign true or false to the variables in a way that makes the formula true)

NP-complete

43
New cards

HAM-CYCLE

to determine if graph G contains a Hamiltonian cycle consisting of all the vertices belonging to V
NP-complete

44
New cards

IND-SET

asks whether graph G has an independent set of size k

NP-complete

45
New cards

VERTEX-COVER

does graph G have a vertex cover (a subset of vertices touches each edge at least once) of size k?

NP-complete

46
New cards

TSP

given a weighted complete digraph and a number b, is there a Ham. cycle of total weight <= b?

NP-complete

47
New cards

HIT

Given a set X and subsets C1, …, Cm in X and a number k, is there a subset S in X such that S = k

find the smallest subset of X, such that the smallest subset, H hits every set comprised in C.