Graphs and Graph Algorithms: A Comprehensive Study - Prof. Nelson Padua-Perez, Study notes of Computer Science

An overview of graphs and graph algorithms, including graph implementation using adjacency matrix, list, and set, spanning trees, minimum spanning trees using prim's and kruskal's algorithms, and dijkstra's algorithm for shortest paths. It covers the basics of graph theory, data structures, and algorithms.

Typology: Study notes

Pre 2010

Uploaded on 02/13/2009

koofers-user-io8-1
koofers-user-io8-1 🇺🇸

9 documents

1 / 30

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1
Graphs & Graph Algorithms 3
CMSC 132
Department of Computer Science
University of Maryland, College Park
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e

Partial preview of the text

Download Graphs and Graph Algorithms: A Comprehensive Study - Prof. Nelson Padua-Perez and more Study notes Computer Science in PDF only on Docsity!

Graphs & Graph Algorithms 3

CMSC 132

Department of Computer ScienceUniversity of Maryland, College Park

Overview

Graph implementation^ Adjacency list / matrix / set Spanning trees Minimum spanning tree^ Prim’s algorithm^ Kruskal’s algorithm

Adjacency Matrix

Representation^ 2D array^ Position j, k

⇒⇒⇒⇒^ edge between nodes n

, njk

Unweighted graph^ Matrix elements

⇒⇒⇒⇒^ boolean Weighted graph^ Matrix elements

⇒⇒⇒⇒^ weight

Adjacency Matrix

Example

Adjacency List

Representation^ Linked or array list for each node ofneighbors/successors^ for directed graph, may need predecessors aswell^ Unweighted graph^ store neighbor^ Weighted graph^ store neighbor, weight

Adjacency List

Example^ Unweighted graph^ Weighted graph

Graph Space Requirements Adjacency matrix^2 ½ Nentries (for graph with N nodes, E edges) Many empty entries for large graphs Adjacency list E entries Adjacency Set/Map E entries Space overhead per entry higher than for adjacencylist

Graph Time Requirements

Average Complexity of operations^ For graph with N nodes, E edges

Adj Set/Map O(1)O(1)O(1) O(E/N) O(E/N) O(1) Find edge

O(E/N)

O(N)

Enumerateedges

O(E/N)

O(1)

Delete edge

O(E/N)

O(1)

Insert edge

Adj List Adj Matrix Operation

Recursive Spanning Tree

Construction

Known = { start }explore ( start );void explore (Node X) {^ for each successor Y of X

if (Y is not in Known)^ Parent[Y] = XAdd Y to Knownexplore(Y)

Spanning Tree Construction

Known = { start }Discovered = { start }while ( Discovered

≠≠≠≠ ∅∅∅∅^ )

take node X out of Discoveredfor each successor Y of X^ if (Y is not in Known)

Parent[Y] = XAdd Y to DiscoveredAdd Y to Known

Depth-First Spanning Tree Example

Breadth-First Spanning Tree Example

Minimum Spanning Tree (MST) Spanning tree with minimum total edge weight Multiple MSTs possible (with same weight)

Algorithms for MST

Two well known algorithms for minimumspanning tree^ developed independently Prim’s algorithm^ described in book Kruskal’s algorithm^ Not Clyde Kruskal (prof in our department, but hisuncle)