Graph Flashcards
Graph : Types of edge
Graph : Weight & Unweighted
Graph : Simple Graph
Graph : Multi Graph
Graph : Complete Graph
Graph : Pseudo Graph
Graph : Acyclic Graph
Graph : Basic Properties of Graph
Graph : Walk & Path & Trail
Graph : Connected & Strongly Connected
Graph : Adjency Matrix & Adjency List
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.
Undirected Graph : Def Structure (AdjList)
Undirected Graph : newListNode (AdjList)
Undirected Graph : CreateGraph (AdjList)
Undirected Graph : addEdge (AdjList)
1️⃣[src]head
2️⃣[dst]head
{
1.newnode
2.link :
From src to dst
From dst to src
}
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
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
In undirected graph, add a new vertice means it is connected to each previous vertices.
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
Graph : PrintGraph (AdjList)
Directed Graph : addEdge (AdjList)
Hints :
1.newnode
2.link
对比无向图,少了增加从dst到src的边的步骤
Directed Graph : DeleteEdge (AdjList)
Hints:
1.prev
2.current (array [src].head )
3.while : find the node
4.link
5. free
对比无向图,少了删除从dst到src的边的步骤
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
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
Graph : addition in deleteVetice (AdjList)
How to implement the following instructions?
1.move all the AdjNodes in each head forward
2.resize array
Graph: Difference between Basic Operations ( AjdList)
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.
Graph : def structure (Adj Matrix)
Graph : iniEdge (Adj Matrix)
Hint :
1.vertice
2.edge
3.initialise
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
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
Graph : addVertex (Adj Matrix)
Hints
1.if :
1️⃣ Vertex ++
2️⃣for :
1. ini last row
2.ini last column
else : full
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
Graph : PrintGraph (Adj Matrix)
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)
Disconnected graph: BFS algorithm (AdjMatrix)
1.visited
2.for :
if :
BFS