DS Lab 12 - Graphs
DS Lab 12 - Graphs
Table of Contents
1. Introduction............................................................................................................................................................3
1.1 Types of Graphs.....................................................................................................................................................3
1.2 Modeling Problems................................................................................................................................................4
1.3 Basic Operations....................................................................................................................................................4
2. Activity Time boxing.............................................................................................................................................5
3. Objectives of the experiment.................................................................................................................................5
4. Concept Map..........................................................................................................................................................5
4.1 Representation of Graphs............................................................................................................................................5
4.2 Graph Traversals.........................................................................................................................................................5
5. Homework before Lab.........................................................................................................................................................6
5.1 Problem Solution Modeling........................................................................................................................................6
5.3 Practices from home....................................................................................................................................................6
5.3.1 Task-1......................................................................................................................................................................6
6. Procedure & Tools...............................................................................................................................................................6
6.1 Tools............................................................................................................................................................................6
6.2 Walk through Tasks [Expected time = 20 mins]......................................................................................6
1. Practice Tasks........................................................................................................................................................9
7.1 Practice Task 1 [Expected time = 30 mins].............................................................................................9
7.2 Practice Task 2 [Expected time = 40 mins]............................................................................................9
7.3 Out comes....................................................................................................................................................................9
8. Evaluation Task (Unseen) [Expected time = 60 mins for two tasks]...............................................................9
9. Evaluation criteria...............................................................................................................................................................9
10. Further Readings.............................................................................................................................................................10
10.1 Web sites related to C++ tutorials about binary search trees using arrays.............................................................10
1. Introduction
A graph is a data structure that contains of a set of vertices and a set of edges which connect
pairs of the vertices.
A vertex (or node) can be connected to any number of other vertices using edges.
An edge may be bidirectional or directed (one-way).
An edge may have a weight on it that indicates a cost for traveling over that edge in the
graph.
Unlike trees, graphs can contain cycles, In fact a tree is an acyclic graph
OR
A graph is a collection of nodes (vertices) and edges. Edges connect pairs of nodes, indicating a
relationship between them. Graphs can be directed (edges have a specific direction) or
undirected.
Directed Graph
A directed graph G is a pair of sets (V, E) where V is a set of nodes and E is a set of ordered
node pairs.
Undirected Graph
An undirected graph G is a pair of sets (V, E) where V is a set of nodes and E is a set of node
pairs
Road Networks
Social Networks
Molecules
Accessing information
Given a node or edge, access its information, e.g. edge weight, distance from other node,
etc.
Navigation
Given a node, access its outgoing edges.
This operation lies in the heart of most graph algorithms.
Sometimes we would also like easy access to the incoming edges of a node.
Edge Queries
Given 2 nodes (u, v) we would like to know if such an edge exists in the graph.
Sometimes we would like to easily find the opposite edge (v, u) of a directed edge (u, v).
Update
Add and remove nodes or edges, change the information of node or edge, etc.
4. Concept Map
This concept map will help students to understand the main concepts of topic covered in
lab.
1. Practice Tasks
This section will provide information about the practice tasks which are required to be performed
in lab session. Design solutions of problems discussed in each task and place solution code in a
folder specified by your lab instructor.
The lab instructor will give you unseen task depending upon the progress of the class.
9. Evaluation criteria
The evaluation criteria for this lab will be based on the completion of the following tasks. Each
task is assigned the marks percentage which will be evaluated by the instructor in the lab whether
the student has finished the complete/partial task(s).