Graphs Flashcards

1
Q

examples of brute sorting algorithms for graphs

A

depth first search

breadth first search

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

examples of decrease and conquer algorithms for graphs

A

topological sort

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

which graphing algorithm can deal with cycles

A

topological sort

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

what is a path

A

sequence of vertices connected by edges

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

what is a cyccle

A

path whose first and last vertices are the same

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

what is an adjacency list

A

an array with each element containing a vertex

vertex has a linked list of all the nodes that it has a link to

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

does depth first search work for noth directed and undirected graphs

A

yes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

what data structure is used when implementing depth first seatch

A

stack

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

how does depth first search algorithm work

A

follow edges as far as possible

if we encounter a node that has already been visited, retrace steps

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

time complexity of dfs

A

O(V+E)

vertices for the seen for loop
edges for the adjacency for loop

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

space complexity of dfs

A

O(V)

seen boolean array

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

what is dfs useful for

A

seeing if there is a path that exists between two nodes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

what data structure is used for breadth first search

A

queue

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

what is bfs used for

A

to find shortest path between two nodes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

time complexity of bf s

A

O(V+E)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

how does bfs work

A

start at a node
visit all its neighbours
visit all their neighbours and so on

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

in which order foes BFS examine vertices

A

in increasing distance from the source vertex

18
Q

what does it mean if a graph is directed

A

the edges flow in one direction

19
Q

examples of directed graphs irl

A

games - legal moves
web pages - hyperlinks
streets - one way

20
Q

how do adjacency lists work for directed graphs

A

edges are listed in the directions they exist

21
Q

time complexity of topological sort

22
Q

when is topological sorting useful

A

when some events have to occur before others can eg class prequisties

23
Q

what data structure has a topological order by nature

24
Q

how does topological sort algorithm work

A

pick an unvisited node
do dfs exploring only unvisited nodes
add topological ordering back in reverse order

25
what does DAG stand for
directed acyclic graph
26
how can directed cycles be detected
do dfs from every vertex keep track of whats been visited if we visit the same node twice, there is a loop
27
why does considering weights of paths matter
multiple hops could end up being cheaper than a single heavy weighted hop
28
what is edge relaxation
when distanceTo [] array is updated with a shorted value path
29
how does Dijkstra algorithm work
always expand on path with smallest weight if new, shorter path found, relax edge
30
does Dijskstra work on negative weights
no
31
how does greedy best search work
uses a heuristic to estimate how far it is away from the destination vertex Goes for minimum cost at each step, ignoring the cost of the edges
32
how does the a* algorithm work
uses the dijkstra method of finding the value of the path so far this gets added to the estimated cost of the remainder of the path (greedy) It picks the smallest of these
33
what is a heuristic in greedy algorithm
some function that tells us how close we are to the goal node
34
what does it mean for the heuristic to be admissible
NEVER overestimates the cost of a path
35
what does it mean if a heuristic is consistent
cannot overestimate the cost of any individual path in a single path: heuristic - actual weight <= next heuristic
36
why does underestimating the cost of a path in A* algorithm not lose optimality
this would just be the dijkstra algorithm
37
which algorithm can be used to most efficiently determine the presence of a cycle in a given graph ?
depth first search
38
how does an adjacency matrix work
it is a 2D array of VxV vertices, each row and column representing a vertex the value of element[i][j] is 1 if there is an edge connecting vertices i and j
39
trade off in adjacency matrix
extremely quick search can take up a lot of space
40
how does an adjacency list work
The index of the array represents a vertex and each element in its linked list represents the other vertices that form an edge with the vertex