CS 231 Module 4: Greedy Approach

0.0(0)
Studied by 0 people
call kaiCall Kai
Locked
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/37

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 2:08 AM on 7/23/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai
Chat

No analytics yet

Send a link to your students to track their progress

38 Terms

1
New cards

Greedy Algorithm

An algorithm that builds up a solution step by step, often uses an ordering to make a decision

2
New cards

Greedy Algorithm Sketch

Process Data

Loop to build up solution step by step

Use information to make a decision

Make updates to information

3
New cards

Greedy Algorithm Checklist

Process for preprocessing data

Definition of steps needed to build a solution

Definition of info to be used for a decision

Definition of criteria for a decision

Process for making updates to information

4
New cards

Arbitary

A method that chooses any 1 option from a set of options, without providing details of what the method is

5
New cards

Random

Using randomization (e.g. throwing dice, flipping coins) to make a choice

6
New cards

How to break ties?

We can add a second, third, fourth criterion based on our first criterion

7
New cards

predicate

an expression that refers to at least one variable

8
New cards

Existential Statement

A statement that says something exists;

there exist a x in the set S such that P(x) is true

9
New cards

Universal Statement

a claim that a predicate is universally true,

for every x in set S, P(x) is true

10
New cards

How to use universal and existential statements for algorithm proof?

Use universal statement for correct proofs,

use existential statement for incorrect proofs

11
New cards

Negations

The opposite meaning of the original statement

12
New cards

How to negate an existential statement

for every x in set S, P(x) is false

13
New cards

How to negate a universal statement

there exist a x in the set S such that P(x) is false

14
New cards

Implication

A implies B = If A is true, then B is true

15
New cards

How to negate implications?

A is true and B is false

16
New cards

Converse

Swapping implication statements relationship

e.g. A implies B -> B implies A

17
New cards

Contrapositive

not B implies not A

always equivalent with implication (both false and both true)

18
New cards

How to proof a statement is true?

Showing that its negation is false

19
New cards

How to proof a statement is false?

Showing that its negation is true

20
New cards

Modus ponens

If statements "A", and "A implies B" are true,

statement "B" is true

21
New cards

Contradiction

if we can show a statement is false

22
New cards

Proof by contradiction recipe

Suppose that X (which we wish to prove) is false.

Choose a statement Y that we know to be true.

Use the assumption that X is false to show that is Y false.

Since Y being both true and false is a contradiction, we know that X is true.

23
New cards

Recipe for proving a universal statement using a generic element

Identify properties of a generic x in S.

Show that P(x) is true.

24
New cards

Recipe for proving an existential statement

Choose an x.

Show that is x in S.

Show that is P(x) true.

25
New cards

Recipe for proving an algorithm is not correct

Choose an instance x.

Show that x is an instance of the problem the algorithm is supposed to solve.

Show that the algorithm produces y.

Show that the correct solution to the problem on x is z, where z is better than y.

26
New cards

Counterexample

an example that proves that a statement is false

27
New cards

How to create counterexamples?

Start with something small and simple;

If your counterexample fails, learn from how to fails to determine how to modify it.

28
New cards

What is a spanning tree?

A tree connecting all vertices in a connected graph, formed of a subset of the edges in the graph.

29
New cards

What is a minimum spanning tree?

A spanning tree such that the sum of the weights of the edges is minimized.

30
New cards

Kruskal's Algorithm

Start with an empty set of edges;

add the lowest weight edge that doesn't form a cycle

31
New cards

Prim's Algorithm

Start with one vertex as the tree,

adds the lowest weight edge that joins a vertex outside of the tree

32
New cards

What is the worst-case running time for Kruskal's Algorithm?

Θ(mlogm)

m = # of edges

33
New cards

What is the worst-case running time for Prim's Algorithm?

Θ(mlogn)

m = # of edges

n = # of vertices

34
New cards

Special Path (Dijkstra's Algorithm)

Given K is a set of vertices where the cheapest paths from origin vertex s is known,

special path only uses vertices in K as intermediate vertices

35
New cards

Dijkstra's Algorithm

Finds the shortest paths between vertices by repeatedly choosing the cheapest special path to a vertex in U, and adding that vertex to K

K = set of vertices where cheapest path from origin vertex s is know

U = set of vertices that doesn't belong in K

36
New cards

What are the 2 properties to prove correctness of a greedy algorithm?

Optimal Substructure Property and Greedy Choice Property

37
New cards

Optimal Substructure Property

A problem satisfies this property when the optimal solution to an instance of a problem can be formed from optimal solutions to one or more smaller instances formed from the original instance.

38
New cards

Greedy Choice Property

A greedy algorithm satisfies this property when there is an optimal solution consistent with each greedy choice made by the algorithm.