Graph Flashcards

1
Q

Graph : Types of edge

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

Graph : Weight & Unweighted

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

Graph : Simple Graph

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

Graph : Multi Graph

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

Graph : Complete Graph

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

Graph : Pseudo Graph

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

Graph : Acyclic Graph

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

Graph : Basic Properties of Graph

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

Graph : Walk & Path & Trail

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

Graph : Connected & Strongly Connected

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

Graph : Adjency Matrix & Adjency List

A

In summary, the choice between adjacency matrix and adjacency list depends on the characteristics of the graph and the operations to be performed on it.
If the graph is dense or operations like checking for the existence of edges between vertices are frequent, an adjacency matrix might be more suitable.
If the graph is sparse or memory efficiency is important, an adjacency list is usually preferred.

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

Undirected Graph : Def Structure (AdjList)

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

Undirected Graph : newListNode (AdjList)

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

Undirected Graph : CreateGraph (AdjList)

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

Undirected Graph : addEdge (AdjList)

1️⃣[src]head
2️⃣[dst]head

{
1.newnode
2.link :
From src to dst
From dst to src
}

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

Undirected Graph : DeleteEdge (AdjList)

Hints:
1.prev
2.current
3.find dst in array[src]
4.link
5.delete
6. Delete (in array [ dst ]) :
redo 3-5 procedures

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

Undirected Graph : addVertice (AdjList)

Hint :
1.newV
2.realloc
3.intialize array [newV -1]
4.for : link new vertices to each previous vertices
5. update V in Graph

A

In undirected graph, add a new vertice means it is connected to each previous vertices.

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

Undirected Graph : deleteVertice (AdjList)

Hint :
1.current (in array [vertex])
2.next
3.while : delete every node in the array [vertext]
4.delete from dst to src :
for:
1️⃣current
2️⃣while: find related node
3️⃣link
4️⃣free

We can add the codes below to make it more precise.
5.move all the AdjNodes in each head forward
6.resize array

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

Graph : PrintGraph (AdjList)

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

Directed Graph : addEdge (AdjList)

Hints :
1.newnode
2.link

A

对比无向图,少了增加从dst到src的边的步骤

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

Directed Graph : DeleteEdge (AdjList)

Hints:
1.prev
2.current (array [src].head )
3.while : find the node
4.link
5. free

A

对比无向图,少了删除从dst到src的边的步骤

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

Directed Graph : addVetice (AdjList)

Hint :
1.newV
2.realloc
3.intialize array [newV -1]
4.for : link new vertices to vertices mentioned in the input value
5. update V in Graph

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

Directed Graph : deleteVetice (AdjList)

Hint :
1.current (in array [vertex])
2.next
3.while : delete every node in the array [vertext]
4.delete from dst to src :
for:
{
if:
1️⃣current
2️⃣while: find related node
3️⃣link
4️⃣free
}
5.move all the AdjNodes in each head forward
6.resize array

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

Graph : addition in deleteVetice (AdjList)

How to implement the following instructions?

1.move all the AdjNodes in each head forward
2.resize array

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

Graph: Difference between Basic Operations ( AjdList)

A

The code for adding or deleting edges may appear similar at first glance, but the final impact differs due to the fundamental differences between directed and undirected graphs.

In a directed graph, edges have a specific direction, meaning each edge goes from one vertex to another. Therefore, when adding or deleting an edge, you must consider this directionality, and operations such as deleting a vertex may involve searching for and removing both incoming and outgoing edges.In an undirected graph, edges do not have a direction, and each edge represents a bidirectional connection between two vertices. Thus, when adding or deleting an edge, you don’t need to consider directionality, and operations such as deleting a vertex involve only removing edges directly connected to that vertex.

So, even though the code may look similar, the final impact varies because of the underlying definitions and properties of directed and undirected graphs, which dictate how edges are added, deleted, and represented within the graph structure.

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

Graph : def structure (Adj Matrix)

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

Graph : iniEdge (Adj Matrix)

Hint :
1.vertice
2.edge
3.initialise

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

Graph : addEdge (Adj Matrix)

Hints
1.if :
1️⃣from src to dst
2️⃣from dst to src (remove in directed graph)
3️⃣edge ++

else : invalid

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

Graph : deleteEdge (Adj Matrix)

Hints
1.if :
1️⃣from src to dst
2️⃣from dst to src (remove in directed graph)
3️⃣edge –
(4️⃣ Edge didn’t exist)

else : invalid

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

Graph : addVertex (Adj Matrix)

Hints
1.if :
1️⃣ Vertex ++
2️⃣for :
1. ini last row
2.ini last column

else : full

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

Graph : deleteVertex (Adj Matrix)

Hints :
1.if :
1️⃣for:
delete edges from vertex
2️⃣for :
delete edges to vertex
3️⃣for:
cover deleted vertex
4️⃣ vertices –

else: Invalid

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

Graph : PrintGraph (Adj Matrix)

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

Directed graph & Undirected graph : BFS algorithm (AdjMatrix)

Hints :
1.visited
2.queue & enqueue (s)
(mark as visited before enqueue)
3.while :
{
1️⃣ dequeue
————-
2️⃣Enqueue :
for ()
(
if :(s from dequeue ‘s neighbours unvisted)
1.mark as visited
2.enqueue
)
4.free (queue & visited)

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

Disconnected graph: BFS algorithm (AdjMatrix)

1.visited
2.for :
if :
BFS

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

Directed graph & Undirected graph : BFS algorithm (AdjList)

Hints :
1.visited
2.queue & enqueue (s)
(mark as visited after enqueue)
3.while :
{
1️⃣ dequeue
————-
2️⃣Enqueue :
1.temp
2.while :
1.adjvertex
2.if (unvisted
(
visited
enqueue
)
}
4.free (queue & visited)

A
36
Q

Disconnect graph : BFS algorithm (AdjList)

Hints:
1.visited [ ]
2.call BFS

A
37
Q

BFS :

A
38
Q

Graph : an easy way to create graph (Adj Matrix)

A
39
Q

Graph : DFS (Adj Matrix)

Hints :
1. mark as visited
2.printf
3.for :
{
if :
}
DFS every unvisted nodes of the chosen vertex

A

It also works in directed graph, undirected graph and disconnected graph.

40
Q

Graph : DFS Traversal (Adj Matrix)

Hints :
for : (view each vertex as independent graph)

A

It also works in directed graph, undirected graph and disconnected graph.

41
Q

Graph : DFS (Adj List)

Hints :
1. mark
2.printf
3.while :
{
if:
}
DFS every unvisted nodes of the chosen vertex

A

It also works in directed graph, undirected graph and disconnected graph.

42
Q

Graph : DFS Traversal (Adj List)

Hints :
for : (view each vertex as independent graph)

A

It also works in directed graph, undirected graph and disconnected graph.

43
Q

Graph :Prim Algorithm

Hints:
1.又叫加点法
2.一开始的集合 V只有一个点

A
44
Q

Graph :Kruskal Algorithm

Hints:
1.又叫加边法
2.一开始的集合 V有所有的点

A
45
Q

Graph : Kruakal Algorithm 特殊情况

A
46
Q

例题 :最小生成树

A
47
Q

例题 :Prim & Kruakal Algorithm

A
48
Q

Grpah : def structure concisely (AdjList)

A
49
Q

Graph : See BFS explicitly

A
50
Q

Graph : detail in BFS Algorithm

A

因为要先展开 A的邻接点 (图中的b、c)

51
Q

Graph : See DFS explicitly

A

Hints :we can use a stack to simulate the process

52
Q

例题 :已知 图 AdjList ,求BFS 、DFS结果

A
53
Q

Graph : Adj Matrix

A

In weighted graph :

54
Q

Graph : What’s Spanning Tree?

A
55
Q

Graph : Dijkstra Algorithm - Priority Queue

A
56
Q

Dijkstra Algorithm : how the first vertice is added

A
57
Q

Dijkstra Algorithm : how the n th vertice is added (n >1)

A
58
Q

Dijkstra Algorithm : Print list

A
59
Q

Dijkstra Algorithm : minDistance

Hint :(To find the vertex in list with min distance from source)

1.INT_MAX ,min_index
2.for
{
if ( unvisted & <min)
{

}
}
3.return

A
60
Q

Dijkstra Algorithm : Dijkstra

Hints :
1.dist,prev
2.visited
3.initialize
4.for :
{
1.minDistance
2.update dist & prev
3.mark as visited
}
5.printGraph

A
61
Q

Graph : Prim Algorithm

Hints:
1.parent,key,mstSet
2.intialize
3.choose original node
4.for (all vertices)
{1️⃣for : find smallest key isn’t in mstSet
2️⃣insert u into mstSet
3️⃣check u ‘s neighbours :
1. if u -> v < key [v]
2.up date parent & key
}
5.printf : the smallest distance between each pair of vertex.

A
62
Q

Graph : a simple way to def graph (AdjList)

For the implementation of Kruskal Algorithm

A
63
Q

Graph : 最小生成树 (Minimum Cost Spanning Tree) & 最短路径(Shortest Path )的不同

A
64
Q

Graph : difference of Prim Algorithm & Kruakal Algorithm

A

Both of them can find Minimum Cost Spanning Tree.But Kruskal’s algorithm is often preferred when the graph is sparse (i.e., few edges), while Prim’s algorithm tends to perform better on dense graphs.

65
Q

Graph : Floyd Algorithm

Hints :
1.intialise
2.for ( k matrix)
{
for :
find smallest distance from i to j
}
3.print

A
66
Q

Graph : How to calculate the matrix in Floyd Algorithm

A
67
Q

Graph : 关键路径 - AOE网

A
68
Q

Graph : 关键路径例题 - 求分别求 事件 、活动 的最早、最迟时间 & 关键活动

A
69
Q

Graph : 关键路径例题 :运用关键路径最本质的性质

A
70
Q

Graph : 什么是拓扑排序?

A
71
Q

Graph : 拓扑排序例题

Hint :看第二个图就可以了

A
72
Q

Disjoint Set : how Parents array works?

A
73
Q

Disjoint Set : Root Algorithm

Impact : to check if it has circle

A
74
Q

Disjoint Set : unionSet (without considering rank)

A
75
Q

Disjoint Set : explanation for why we need to consider rank in unionSet function

A
76
Q

Disjoint Set : unionSet ( consider rank)

A
77
Q

Graph : SortEdge function for Kruskal Algorithm

A
78
Q

Graph : Kruskal Algorithm

Hints :
1.parent
2.ini parent
3.sortEdge
4.result
5.while
{
if ( no circle ) :
1.enqueue result
2.union
}
6.print

A

You have to know each edge contains weight,src and dst.

79
Q

Critical Path : ES EL LS LF

A
80
Q

Critical Path : What’s Critical Activity?

A
81
Q

Critical Path : Details for determining EF & LS

A
82
Q

Critical Path : Def

Hints :
1.task
2.dependency

A
83
Q

Critical Path : calculateEarliest

Hints :
1.for :
{
1️⃣ini
2️⃣for
(
if ()
(
update i .ES
)
3️⃣update i.EF
}

A
84
Q

Critical Path : calculateLatest

Hints :
for :
{
1️⃣ini
2️⃣for
(
if ()
(
update i .LF
)
3️⃣update i.LS
}

A
85
Q

Critical Path : FindCriticalPath

A
86
Q

Critical Path : in main function

A