IIT Bombay Data Structures and Algorithms Prof Ajit
IIT Bombay Data Structures and Algorithms Prof. Ajit A. Diwan Prof. Ganesh Ramakrishnan Prof. Deepak B. Phatak Department of Computer Science and Engineering IIT Bombay Session: Graphs Ajit A. Diwan, Ganesh Ramakrishnan, and Deepak B. Phatak, IIT Bombay 1
Graphs IIT Bombay • Useful to represent many real life situations • Family relationships • Road or rail network • Optimization problems • Minimize transportation costs and/or time • Shortest path problem Ajit A. Diwan, Ganesh Ramakrishnan, and Deepak B. Phatak, IIT Bombay 2
Graphs IIT Bombay • Vertex • Each element / node in the graph • A, B, C, D, E are vertices of graph • Edge • Connection between two vertices • e. g. There is an edge between • A and B • A and C • B and D etc. • But, there is no edge for vertex E Ajit A. Diwan, Ganesh Ramakrishnan, and Deepak B. Phatak, IIT Bombay A C E B V E R T E X E D G E D V E R T E X 3
Undirected Graphs IIT Bombay • Undirected edges • There is an edge from • A to B and B to A • A to C and C to A • B to D and D to B • … Ajit A. Diwan, Ganesh Ramakrishnan, and Deepak B. Phatak, IIT Bombay A C E B D 4
Directed Graphs IIT Bombay • Directed edges • There is an edge from • A to B, but, • not from B to A • A to C and also from C to A • C to D, but • not from D to C Ajit A. Diwan, Ganesh Ramakrishnan, and Deepak B. Phatak, IIT Bombay A C E B D 5
Directed Graphs IIT Bombay • Outgoing Edge • Directed edge from Source Vertex • A to C, C to D (but not from D to C) • Outgoing Degree • Number of edges from a Source Vertex • e. g. • A has 2 (B and C) • B has 0 • C has 3 (A, B, and D) Ajit A. Diwan, Ganesh Ramakrishnan, and Deepak B. Phatak, IIT Bombay A C E B D 6
Directed Graphs IIT Bombay • Incoming Edge • Directed edge to the Destination vertex • A to B, C to B, D to B • Indegree • Number of edges pointing to the Destination Vertex • e. g. • A has 1 (from C) • B has 3 (from A, C, and D) Ajit A. Diwan, Ganesh Ramakrishnan, and Deepak B. Phatak, IIT Bombay A C E B D 7
IIT Bombay Thank you Ajit A. Diwan, Ganesh Ramakrishnan, and Deepak B. Phatak, IIT Bombay 8
- Slides: 8