15 GRAPHS Flashcards

1
Q

What is a graph in computer science?

A

A fundamental data structure composed of a set of nodes and a set of edges.

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

How do graphs differ from other data structures?

A

Graphs arise naturally from the data itself, mirroring the data they represent.

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

What are the two main components of a graph?

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

What do undirected edges represent?

A

Two-way relationships, such as roads or friendships.

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

What do directed edges indicate?

A

A flow in a single direction, like one-way streets.

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

What is an example of using directed edges in a task?

A

Modeling task dependencies, such as the order of brewing coffee.

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

What are weighted edges used for in graphs?

A

To capture the cost of the link between nodes.

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

What are the two common representations of graphs in memory?

A
  • Adjacency matrices
  • Adjacency lists
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How does an adjacency list represent a graph?

A

Stores a separate list of neighbors for each node.

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

What does an adjacency matrix consist of?

A

A matrix with one row and one column for each node, representing edge weights.

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

What is the purpose of searching graphs?

A

To explore nodes and find specific information or paths.

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

What is a depth-first search?

A

A graph search method that explores paths deeply before backtracking.

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

What is a breadth-first search?

A

A graph search method that explores nodes closer to the starting point first.

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

What is Dijkstra’s algorithm used for?

A

Finding the shortest path from a starting node to all other nodes in a graph.

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

What is a key constraint for Dijkstra’s algorithm?

A

All edge weights must be non-negative.

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

What data structures does Dijkstra’s algorithm maintain?

A
  • Array of distances
  • Array indicating the last node visited
  • Set of unvisited nodes
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What happens in each iteration of Dijkstra’s algorithm?

A

The closest unvisited node is visited and distances to its unvisited neighbors are updated.

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

True or False: Dijkstra’s algorithm can work on graphs with negative edge weights.

A

False

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

What is the initial distance setup in Dijkstra’s algorithm?

A

All distances are set to infinity except for the starting node, which is set to zero.

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

Fill in the blank: Dijkstra’s algorithm uses a ______ to improve efficiency.

A

min-heap

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

What does the adjacency list representation provide?

A

A localized view of neighbor relationships.

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

What type of relationships do weighted edges allow us to model?

A

Complex interrelations among nodes.

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

What is an example of a real-world system modeled as a graph?

A

Social networks, transportation networks, and computer networks.

24
Q

What is the initial configuration of distances in Dijkstra’s algorithm?

A

All distances at infinity except for node A, which is set to zero.

25
What does the last column in Dijkstra's algorithm indicate?
The preceding node for each node in the search.
26
What is the main purpose of maintaining a back pointer in Dijkstra's algorithm?
To reconstruct the path from the starting node to the target node.
27
How does Dijkstra's algorithm determine the next node to visit?
By selecting the unvisited node with the smallest distance.
28
What happens when a shorter path to a neighbor is found in Dijkstra's algorithm?
The distance to that neighbor is updated, along with the back pointer.
29
True or False: Dijkstra's algorithm can be used for graphs with negative edge weights.
False.
30
What is the minimum spanning tree of a graph?
The smallest set of edges such that all nodes are connected.
31
Who independently proposed Prim's algorithm?
R. C. Prim and Vojtěch Jarník.
32
How does Prim's algorithm operate?
It builds up a minimum spanning tree one node at a time from an unvisited set.
33
What is the key question Prim's algorithm asks at each iteration?
Which unvisited node is closest to the currently visited set?
34
What data does Prim's algorithm maintain at each step?
The best edge (including weight) to each node.
35
Fill in the blank: Prim's algorithm focuses on minimizing the cost of _______.
[adding new nodes to the connected set].
36
True or False: The final spanning tree produced by Prim's algorithm is always unique.
False.
37
What type of graph does Kahn's algorithm work on?
Directed acyclic graph (DAG).
38
What is the purpose of topological sorting?
To order nodes based on their dependencies in a directed acyclic graph.
39
How does Kahn's algorithm identify nodes to add to the sorted list?
By finding nodes with no incoming edges.
40
What do we track in Kahn's algorithm instead of actually removing edges?
An auxiliary array counting the number of incoming edges to each node.
41
What does a directed edge from A to B indicate in a DAG?
Node A must come before node B.
42
What is the significance of cycles in real-world road networks?
They allow for return paths, which are absent in acyclic graphs.
43
How does the algorithm terminate in Kahn's algorithm?
When all nodes have been added to the sorted list.
44
What is Kahn’s algorithm used for?
Topological sorting of a directed acyclic graph ## Footnote Kahn's algorithm is particularly useful for ordering tasks or nodes where dependencies exist.
45
What auxiliary data structures does Kahn's algorithm utilize?
An array for sorted nodes, an array for counting incoming edges, and a stack for next nodes ## Footnote These structures help manage the nodes and their relationships during the sorting process.
46
What does the count array represent in Kahn's algorithm?
The number of incoming edges for each node ## Footnote This helps in identifying nodes that can be processed next during the topological sort.
47
How does Kahn’s algorithm identify initial nodes for processing?
It finds nodes with zero incoming edges and adds them to the stack ## Footnote This step is crucial as it starts the sorting process with nodes that have no dependencies.
48
What happens in the WHILE loop of Kahn's algorithm?
It processes nodes from the stack and updates the count of incoming edges for their neighbors ## Footnote Nodes with zero incoming edges are added to the stack for further processing.
49
What is a potential issue if the graph contains cycles?
The sorted list will be incomplete ## Footnote In such cases, an additional check is needed to ensure all nodes are processed.
50
What is the significance of directed edges in Kahn's algorithm?
They constrain how nodes are explored and processed ## Footnote This directionality is essential for accurately representing dependencies.
51
What real-world phenomena can graphs represent?
Streets, social networks, computer networks, complex tasks ## Footnote Graphs provide a versatile framework for modeling various systems and relationships.
52
What tasks can graphs be useful for in computer science?
Path planning, program compilation order, searching, minimum spanning tree, maximum flow determination ## Footnote These tasks highlight the practical applications of graph algorithms.
53
True or False: Kahn's algorithm removes edges from the graph during execution.
False ## Footnote It modifies counts rather than actually removing edges.
54
Fill in the blank: In Kahn's algorithm, after processing a node, its outgoing edges' counts are _______.
decreased
55
What is the end goal of Kahn's algorithm?
To return a sorted array of nodes ## Footnote This sorted array represents a valid topological ordering of the nodes.
56
What is the relationship between data structure and algorithms in the context of graphs?
The structure of the data drives new problems and algorithms ## Footnote Understanding data structure is vital for defining problems and finding solutions.