Graphs Flashcards
examples of brute sorting algorithms for graphs
depth first search
breadth first search
examples of decrease and conquer algorithms for graphs
topological sort
which graphing algorithm can deal with cycles
topological sort
what is a path
sequence of vertices connected by edges
what is a cyccle
path whose first and last vertices are the same
what is an adjacency list
an array with each element containing a vertex
vertex has a linked list of all the nodes that it has a link to
does depth first search work for noth directed and undirected graphs
yes
what data structure is used when implementing depth first seatch
stack
how does depth first search algorithm work
follow edges as far as possible
if we encounter a node that has already been visited, retrace steps
time complexity of dfs
O(V+E)
vertices for the seen for loop
edges for the adjacency for loop
space complexity of dfs
O(V)
seen boolean array
what is dfs useful for
seeing if there is a path that exists between two nodes
what data structure is used for breadth first search
queue
what is bfs used for
to find shortest path between two nodes
time complexity of bf s
O(V+E)
how does bfs work
start at a node
visit all its neighbours
visit all their neighbours and so on