Graphs Flashcards

1
Q

Which is more general, tree or graph?

A

A graph which can have any combinations of nodes & edges

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

What two classes of graphs are there?

A

Undirected and directed. Directed graphs have arrow lines as opposed to plane lines.

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

What is the terminology for adjacent nodes for both types of graphs?

A

Neighbor nodes

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

Which node does the target and source of a directed edge lie, respectively?

A

predecessor, successor

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

What is an example of a cyclic path and acyclic path?

A

1→2→3→1 : cyclic
1→2→3→4: acyclic
1→1: cyclic

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

What does DAG stand for?

A

Directed acyclic graph

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

What is the name of a undirected/directed graph where all nodes neighbor every other node

A

A complete graph

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

What is an edge called if it is assigned a number?

A

A weighted edge, which could represent length

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

When is a graph strongly connected?

A

If every node is reachable with direction

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

When is a graph weakly connected?

A

If every node is reachable regardless of direction

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

If all nodes can be reached from a set of nodes how is this represented in java?

A

This can be represented as an array or list of root nodes

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

What condition must bee satisfied in topological numbering?

A

If the order is u,v then u must always occur before v in any path

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

What nodes are always in the first positions in topological ordering?

A

nodes with an in-number of zero

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

What is the difference between in-degree, out-degree and degree?

A

in-deg: edges going in
out-deg: edges going out
deg: all in & out edges

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

What two data structures are best suited for a dfs & bfs respectively?

A

dfs: stack
bfs: queue, which holds the nodes to be visited at each level

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

What is the distance of a graph?

A

The number of edges from node A to node B

17
Q

How does an adjacency list represent the graph?

A

It lists each vertices on the left and all of it’s adjacent nodes on the right

18
Q

What is the complexity to look for weather a node is adjacent?

A

O(V), because the vertex could be neighbors with every other node, unless the graph is sparse (doesn’t have many edges)

19
Q

How does the adjacency list differ from the adjacency matrix?

A

The list of neighboring vertices is replaced by a list of 1 & 0 creating a 2x2 matrix

20
Q

Why is an adjacency list more efficient for sparse graphs, while an adjacency matrix is not?

A

Because the size of the matrix is O(V^2), which is unnecessary since a list wouldn’t have to include the 0’s

21
Q

For an 2D array implementation of an adjacency matrix what is the complexity for a an edge lookup?

A

O(1)

22
Q

What is the size of a graph?

A

O(V+E)

23
Q

What is a method where all nodes are visited in an arbitrary order?

A

graph traversal

24
Q

What is the general idea of a breadth-first-search?

A

traversal that visits a starting vertex, then all vertices of distance 1 from that vertex, then of distance 2, and so on, without revisiting a vertex

25
Q

Is a BFS always unique?

A

No, if there are vertices the same distance from the root node, then there are multiple cases

26
Q

What is the maximum amount of times a vertex is visited in a BFS?

A

1

27
Q

How are vertexes at any given level kept track of during the traversal?

A

1.) vertex is added to frontier queue
2.)vertex is added to discovered stack
3.)front of frontier queue is visited
4.)continues until frontier queue is empty
ie.
While the queue is not empty, the algorithm pops a vertex from the queue and visits the popped vertex, pushes that vertex’s adjacent vertices (if not already discovered), and repeats.

28
Q

What is the general idea of the depth-first-search?

A

To pick a adjacent node from the root and continue to the greatest distance away, then backtrack to an unvisited node and repeat

29
Q

What is the procedure to do a dfs programmatically?

A
  1. ) Put the first node visited on the stack
  2. )put all adjacent nodes on the stack
  3. )visit the topmost unvisited node
  4. )pop it from the stack along with all other visited nodes and repeat
30
Q

Can a dfs be implemented recursively?

A

yes

31
Q

What is the terminating side of the edge?

A

The target edge

32
Q

In a weighted graph what algorithm can find the shortest path from one vertex to another?

A

Dijkstra’s algorithm

33
Q

What is the algorithm for Dijkstra’s method?

A
  1. ) set cost at initial node to 0 and the rest to infinity
  2. ) set cost to neighboring nodes to the weight of each respective edge
  3. ) choose lesser cost and repeat the process for that node
34
Q

How are the costs to every node for every iteration represented?

A

A (5), C (∞), E (∞), D (1); infinity is the cost for non-adjacent nodes

35
Q

Does Dijkstra’s method work for unweighted graphs?

A

Yes, each edge gets a weight of 1 or c

36
Q

Does Dijkstra’s method work for weighted graphs with negative edges?

A

No

37
Q

What is topological ordering for?

A

DAGs, otherwise it’s not possible

38
Q

What methods can be used to create a topological ordering?

A

A recursive/iterative modified dfs algorithm