Graph Algorithms Flashcards
Week 2.12 (30 cards)
5 typical operations of graphs as ADT
- determine whether there is an edge between 2 given vertices
- identify all edges
- find all vertices adjacent to a given vertex
- insert/delete a vertex
- insert/delete an edge by 2 vertices of the graph
3 data structures graphs can be based on
- adjacency lists
- adjacency matrix
- incidence matrix
describe adjacency matrix implementation
- for every vertex, there is a singly linked list of its neighbours
- lists are accessed using an array of vertices
how are the matrixes implemented
2-d arrays
space efficiency of adjacency lists
theta(n + m)
space efficiency of adjacency matrix
theta(n^2)
space efficiency of incidence lists
theta(nm)
big theta of determining whether there is an edge between 2 given vertices for adjacency lists
deg(v)
big theta of determining whether there is an edge between 2 given vertices for adjacency matrix
1
big theta of determining whether there is an edge between 2 given vertices for incidence matrix
m
big theta to identify all edges in an adjacency list
n + m
big theta to identify all edges in an adjacency matrix
n^2
big theta to identify all edges in an incidence matrix
nm
big theta to find all vertices adjacent to a given vertex in an adjacency list
deg(v)
big theta to find all vertices adjacent to a given vertex in an adjacency matrix
n
big theta to find all vertices adjacent to a given vertex in an incidence list
m + ndeg(v)
2 types of graph traversal algorithms
- depth-first search (DFS)
- breadth-first search (BFS)
describe DFS
- algorthim selects a start vertex and marks it as visited
- goes as far down one path until it reaches the leaf node before starting to explore alternative paths
- visited nodes stored in a stack
outputs of DFS
- vertices printed in order of visit
- depth-first numbering
- DFS forest
big theta of depth-first search
n + m
big theta of DFS on an adjacency matrix
n^2
describe BFS
- visits all neighbours of the start vertex and only after explores the vertices further away
- visited vertices kept in a queue
big theta of BFS
n + m
big theta of BFS as an adjacency matrix
n^2