DSA2 Quizzes 3 & 4 RUNTIMES

0.0(0)
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/8

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.

9 Terms

1
New cards

Prim's MST Algorithm

E number of edges.
O(|E| log|V|) = extractMin() + decreaseKey() = O(|V| log|V| + |E| log|V|)

2
New cards

Kruskol’s MST Algorithm

O(|E| log|E|)

E number of edges.

Factor of E from sorting all edges.

O(log|E|) from Union-Find.

3
New cards

Log Cutting

O(n2)

n is the length of the log.

Nested for loops. Outer loop iterating through log size, inner loop iterating through last cut size.

4
New cards

Matrix Chaining

Θ(n3) = Θ(n2) * Θ(n)

n number of matrices

Θ(n2) subproblems to solve, corresponding to number of ways to divide the chain of matrices into two subchains.

Θ(n), each problem can be solved in Θ(n) time.

5
New cards

Making Change (DP)

O(kn)
k number of coins, n is the amount to make change for.
There are k * n subproblems, each solved in constant time.

6
New cards

Seam Carving

Θ(n*m)

n number of rows and m number of columns.

Θ(1) to calculate energy of each pixel, total of Θ(nm). Θ(nm) using DP to find minimum energy seam.

7
New cards

Largest Common Subsequence

Θ(n*m)

|X| = n and |Y| = m, where n and m are the lengths of the two strings.

m*n subproblems, each solved in constant time by looking up solution in table.

8
New cards

Gerrymandering

Θ(n4m2)
n number of precincts and m number of votes.

4 nested for loops. Outer-most iterates first j precincts until n total precincts, then iterates k precincts until min(j, n/2), then iterates x voters for a party in D1 until j*m, inner-most iterates y voters for a party in D2 until j*m.

9
New cards

Interval Scheduling (w/o sorting)

Θ(n)