Graphs Adjacency list Representation complexity March 22 2019

  • Slides: 11
Download presentation
Graphs Adjacency list Representation & complexity March 22, 2019 Cinda Heeren / Will Evans

Graphs Adjacency list Representation & complexity March 22, 2019 Cinda Heeren / Will Evans / Geoffrey Tien 1

Announcements • PA 3 / PA 4 situation – PA 3 due date extended,

Announcements • PA 3 / PA 4 situation – PA 3 due date extended, with extra weight from PA 4 – So, please make an effort to complete it! • Labs – please go to your registered lab section! – Friday sections are overloaded, and there is a chance TAs might not have time to give your password credit March 22, 2019 Cinda Heeren / Will Evans / Geoffrey Tien 2

Adjacency matrix • Tom Shelly hamster popcorn Tom Shelly popcorn hamster popcorn March 22,

Adjacency matrix • Tom Shelly hamster popcorn Tom Shelly popcorn hamster popcorn March 22, 2019 Cinda Heeren / Will Evans / Geoffrey Tien 3

Adjacency matrix examples With weights and/or directed edges 5 A B C A B

Adjacency matrix examples With weights and/or directed edges 5 A B C A B 1 31 D symmetric 5 E C 1 2 D 2 E 2 4 3 F G F A B C D E F G A 1 3 5 1 B 2 0 1 C 5 1 0 0 0 D 1 0 0 0 1 E 2 3 0 0 1 F 8 1 0 1 1 0 G 2 4 A B C D E F G A 0 1 1 1 0 B 1 0 1 0 C 1 1 0 0 1 D 1 0 0 0 E 0 1 1 F 1 0 G 0 1 March 22, 2019 G 8 Cinda Heeren / Will Evans / Geoffrey Tien 4

Adjacency matrix performance • What would be the complexity of these operations? – –

Adjacency matrix performance • What would be the complexity of these operations? – – – insert. Vertex(Vertex v) remove. Vertex(Vertex v) are. Adjacent(Vertex v, Vertex u) incident. Edges(Vertex v) insert. Edge(Vertex v, Vertex u) remove. Edge(Vertex v, Vertex u) 0 1 1 0 1 0 1 0 • What is the required space usage of this representation? March 22, 2019 Cinda Heeren / Will Evans / Geoffrey Tien 5

Adjacency list • Tom … Tom Shelly … hamster … popcorn … hamster popcorn

Adjacency list • Tom … Tom Shelly … hamster … popcorn … hamster popcorn March 22, 2019 Cinda Heeren / Will Evans / Geoffrey Tien 6

Adjacency list example 5 A B C A 1 B 31 D 5 E

Adjacency list example 5 A B C A 1 B 31 D 5 E 2 D G F A B C D F A B 1 B A C E G B E 2 C A B E G C A 5 D A 1 E B C E C 2 F A G F G 8 G B C G B 2 March 22, 2019 G E F Cinda Heeren / Will Evans / Geoffrey Tien 8 2 E 2 3 F C 1 4 G D 3 F 5 B 1 G 3 C 4 7

Adjacency list performance • What would be the complexity of these operations? – –

Adjacency list performance • What would be the complexity of these operations? – – – insert. Vertex(Vertex v) remove. Vertex(Vertex v) are. Adjacent(Vertex v, Vertex u) incident. Edges(Vertex v) insert. Edge(Vertex v, Vertex u) remove. Edge(Vertex v, Vertex u) • What is the required space usage of this representation? March 22, 2019 Cinda Heeren / Will Evans / Geoffrey Tien 8

Graph performance Adjacency list Space Adjacency matrix These performance descriptions can change depending on

Graph performance Adjacency list Space Adjacency matrix These performance descriptions can change depending on your assumptions! e. g. Is there sufficient space in the array? March 22, 2019 Cinda Heeren / Will Evans / Geoffrey Tien 9

How are algorithms affected? Return to topological sort, list vs. matrix • 2 1

How are algorithms affected? Return to topological sort, list vs. matrix • 2 1 4 March 22, 2019 3 6 For the adjacency list, how many vertices/edges have been processed in total? 5 Cinda Heeren / Will Evans / Geoffrey Tien 10

Readings for this lesson • Carrano & Henry – Chapter 20. 2 (Graph ADT

Readings for this lesson • Carrano & Henry – Chapter 20. 2 (Graph ADT implementation) • Next class: – Carrano & Henry, Chapter 20. 3 (Graph traversals) March 22, 2019 Cinda Heeren / Will Evans / Geoffrey Tien 11