Graph Representation - Introduction to Algorithms - Lecture Slides, Slides of Computer Science

These are the Lecture Slides of Introduction to Algorithms which includes Expensive Operations, Sort Edges, Running Time, Upshot, Union, Makeset, Disjoint Set, Disjoint Set Union, Naïve Implementation etc. Key important points are: Graph Representation, Adjacency List, Adjacency Matrix, Tradeoffs, Graph Dense, Graph Sparse, Planar Graphs, Breadth First Search, Depth First Search, Shortest Path Distance

Typology: Slides

2012/2013

Uploaded on 03/23/2013

dhruv
dhruv 🇮🇳

4.3

(12)

194 documents

1 / 152

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Graph Representation
Adjacency list
Adjacency matrix
Tradeoffs:
What makes a graph dense?
What makes a graph sparse?
What about planar graphs?
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54
pf55
pf56
pf57
pf58
pf59
pf5a
pf5b
pf5c
pf5d
pf5e
pf5f
pf60
pf61
pf62
pf63
pf64

Partial preview of the text

Download Graph Representation - Introduction to Algorithms - Lecture Slides and more Slides Computer Science in PDF only on Docsity!

Graph Representation

● Adjacency list

● Adjacency matrix

● Tradeoffs:

What makes a graph dense?What makes a graph sparse?What about planar graphs?

Basic Graph Algorithms

● Breadth-first search

What can we use BFS to calculate? ■ A: shortest-path distance to source vertex

● Depth-first search

■ Tree edges, back edges, cross and forward edges ■ What can we use DFS for? ■ A: finding cycles, topological sort

MST Algorithms

● Prim’s algorithm

What is the bottleneck in Prim’s algorithm? ■ A: priority queue operations

● Kruskal’s algorithm

What is the bottleneck in Kruskal’s algorithm? ■ Answer: depends on disjoint-set implementation ○ As covered in class, disjoint-set union operations ○ As described in book, sorting the edges

Single-Source Shortest Path

● Optimal substructure

● Key idea: relaxation of edges

● What does the Bellman-Ford algorithm do?

What is the running time?

● What does Dijkstra’s algorithm do?

What is the running time?When does Dijkstra’s algorithm not apply?

Amortized Analysis

● Idea: worst-case cost of an operation may

overestimate its cost over course of algorithm

● Goal: get a tighter amortized bound on its cost

■ Aggregate method: total cost of operation over course of algorithm divided by # operations ○ Example: disjoint-set union ■ Accounting method: “charge” a cost to each operation, accumulate unused cost in bank, never go negative ○ Example: dynamically-doubling arrays

Dynamic Programming

● Indications: optimal substructure, repeated

subproblems

● What is the difference between memoization

and dynamic programming?

● A: same basic idea, but:

Memoization : recursive algorithm, looking up subproblem solutions after computing once ■ Dynamic programming : build table of subproblem solutions bottom-up

Greedy Algorithms

● Indicators:

■ Optimal substructure ■ Greedy choice property : a locally optimal choice leads to a globally optimal solution

● Example problems:

■ Activity selection: Set of activities, with start and end times. Maximize compatible set of activities. ■ Fractional knapsack: sort items by $/lb, then take items in sorted order ■ MST

NP-Completeness

● What do we mean when we say a problem

is in P?

■ A: A solution can be found in polynomial time

● What do we mean when we say a problem

is in NP?

■ A: A solution can be verified in polynomial time

● What is the relation between P and NP?

■ A: PNP , but no one knows whether P = NP

Review:

Proving Problems NP-Complete

● What was the first problem shown to be

NP-Complete?

● A: Boolean satisfiability ( SAT ), by Cook

● How do we usually prove that a problem R

is NP-Complete?

● A: Show R ∈ NP , and reduce a known

NP-Complete problem Q to R

Review:

Reductions

● Review the reductions we’ve covered:

■ Directed hamiltonian cycle  undirected hamiltonian cycle ■ Undirected hamiltonian cycle  traveling salesman problem ■ 3-CNF  k -clique ■ k -clique  vertex cover ■ Homework 7

Review: Induction

● Suppose

■ S(k) is true for fixed constant k ○ Often k = 0 ■ S(n)  S(n+1) for all n >= k

● Then S(n) is true for all n >= k

Proof By Induction

● Claim:S(n) is true for all n >= k

● Basis:

■ Show formula is true when n = k

● Inductive hypothesis:

■ Assume formula is true for an arbitrary n

● Step:

■ Show that formula is then true for n+

Induction Example:

Geometric Closed Form

● Prove a 0 + a^1 + … + a n^ = (an+1^ - 1)/(a - 1) for

all a != 1

■ Basis: show that a 0 = (a 0+1^ - 1)/(a - 1) a 0 = 1 = (a 1 - 1)/(a - 1) ■ Inductive hypothesis: ○ Assume a 0 + a 1 + … + a n^ = (a n+1^ - 1)/(a - 1) ■ Step (show true for n+1): a 0 + a 1 + … + a n+1^ = a 0 + a 1 + … + a n^ + a n+ = (a n+1^ - 1)/(a - 1) + a n+1^ = (a n+1+1^ - 1)(a - 1)

Review: Analyzing Algorithms

● We are interested in asymptotic analysis :

■ Behavior of algorithms as problem size gets large ■ Constants, low-order terms don’t matter