Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> การเขียนโปรแกรม

Weighted Graph Representation in Data Structure (การแสดงกราฟมีน้ำหนัก)

กราฟแบ่งได้: Directed/Undirected, Weighted/Unweighted ここでは Weighted Graph ใน Memory การแสดง

พิจารณากราฟตัวอย่าง:

Weighted Graph Representation in Data Structure (การแสดงกราฟมีน้ำหนัก)

Adjacency Matrix Representation (Cost Matrix)

เก็บ Weighted Graph ด้วย Adjacency Matrix เรียกว่า Cost Matrix ตำแหน่ง M[i,j] เก็บ Weight จาก Edge i→j ถ้าไม่มี Edge = ∞ โหนดเดียวกัน = 0

0∞63∞
30∞∞∞
∞∞02∞
∞110∞
∞4∞20

Adjacency List Representation

ใน Adjacency List แต่ละ Element มี 2 ค่า: Destination Node และ Weight ระหว่าง 2 โหนด

Weighted Graph Representation in Data Structure (การแสดงกราฟมีน้ำหนัก)