CS 310 graphs

0.0(0)
studied byStudied by 0 people
0.0(0)
full-widthCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/42

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

43 Terms

1
New cards

What is a graph?

A set of nodes joined by a set of edges

2
New cards

What is a weighted graph?

Graph for which each edge has an associated weight

3
New cards

What is a directed graph?

Graph where each edge points from one vertex to another

4
New cards

What is an undirected graph?

Graph where edges are unordered pairs of vertices

5
New cards

What is a path?

A sequence of vertices such that there is an edge from each vertex to its successor

6
New cards

When is a path simple?

If all the vertices on it are distinct

7
New cards

What is the path length in a weighted graph?

Sum of the edge weights in the path

8
New cards

What is the degree of a vertex?

Number of edges incident on a vertex

9
New cards

For directed graphs, what is the out-degree of a vertex?

Number of edges leaving a vertex

10
New cards

For directed graphs, what is the in-degree of a vertex?

Number of edges entering a vertex

11
New cards

What is a simple graph?

Graph without multiple edges, directed in the same direction or undirected, connecting a single pair of vertices or self-loops

12
New cards

When is an undirected graph connected?

If any two nodes are connected by a path

13
New cards

When is a directed graph strongly connected?

If there is a directed path from any node to any other node

14
New cards

When is a graph sparse?

If the number of edges is about equal to the number of vertices

15
New cards

When is a graph dense?

When the number of edges is about equal to the number of vertices squared

16
New cards

What is a complete graph?

A graph in which every pair of vertices is adjacent

17
New cards

Given |V| nodes, how many edges are there in a complete, undirected graph?

|V|*(|V| - 1)/2 edges

18
New cards

Given |V| nodes, how many edges are there in a complete, directed graph?

|V|*(|V| - 1) edges

19
New cards

Given |V| nodes, how many edges are there in a complete, undirected graph with self-edges?

(|V|²)/2 edges

20
New cards

Given |V| nodes, how many edges are there in a complete, directed graph with self-edges?

|V|² edges

21
New cards

How does an adjacency list representation of a graph work?

There is a linked list for every vertex, where each linked list contains a vertex’s adjacent vertices

22
New cards

What is the extra space complexity for an adjacency list representation of a graph? Why?

O(|V| + |E|), as the linked list includes list heads for each vertex, and the representation will include all the edges

23
New cards

What are the advantages of an adjacency list representation of a graph?

Saves space for sparse graphs, O(degree(v)) time to visit edges that start at v

24
New cards

What are the disadvantages of an adjacency list representation of a graph?

Must traverse entire linked list of v to check for existence of an edge starting at v, which O(degree(v)) time

25
New cards

How does an adjacency matrix representation of a graph work?

|V| x |V| matrix, where if two vertices share an edge, their matrix element is 1, and is 0 otherwise

26
New cards

What are the advantages of the adjacency matrix representation of a graph?

Saves space on pointers for dense graphs, can check for the existence of an edge in O(1) time

27
New cards

What is the disadvantage of the adjacency matrix representation of a graph?

O(|V|) time to visit at the edges that start at v, as the whole row must be traversed

28
New cards

What is breadth-first search?

Traversal that visits a starting vertex, then discovers all vertices at distance k from s before discovering any vertices at distance k + 1 from s

29
New cards

How does breadth-first search implement the frontier?

Using a FIFO queue

30
New cards

Other than traversing a graph, what can breadth-first search do?

Compute the shortest distance from s to any reachable node

31
New cards

What is the runtime complexity of breadth-first search using an adjacency list representation of a graph?

O(|V| + |E|)

32
New cards

What is the runtime complexity of breadth-first search using an adjacency matrix representation of a graph?

O(|V|²)

33
New cards

What is the coloring method for breadth- and depth-first search?

Nodes are colored white, gray, and black to indicate undiscovered, frontier, and fully explored nodes, respectively

34
New cards

What is a key limitation of breadth-first search that depth-first search does not have?

May fail to reach all nodes for directed or unconnected graphs

35
New cards

What is depth-first search?

Traversal method that visits a starting vertex, then visits every vertex along each path starting from that vertex to the path’s end before backtracking

36
New cards

What is the runtime complexity of depth-first search using an adjacency list representation of a graph?

O(|V| + |E|)

37
New cards

What is the runtime complexity of depth-first search using an adjacency matrix representation of a graph?

O(|V|²)

38
New cards

What does Dijkstra’s Algorithm do?

Determines the shortest path from a start vertex to each vertex in a graph

39
New cards

What is the runtime complexity of Dijkstra’s Algorithm when the number of edges dominate the number of vertices?

O(|E|log|V|)

40
New cards

What is the runtime complexity of Dijkstra’s Algorithm when the number of edges are less than/similar to the number of vertices?

O((|V| + |E|)(log|V|))

41
New cards

What does Kruskal’s Algorithm do?

Determines the subset of a graph’s edges that connect all the graph’s vertices with the minimum possible sum of edge weights

42
New cards

What is the space complexity of Kruskal’s Algorithm?

O(|E| + |V|)

43
New cards

What is the runtime complexity of Kruskal’s Algorithm?

O(|E|log|E|)