Practical 08
Practical 08
PRACTICAL 08
TO DEMONSTRATE & EXECUTE SEARCHING PROBLEMS IN GRAPHS
----------------------------------------------------------
OBJECTIVES
• Fundamentals of graphs
• Applications of graphs
• Creation of graphs using dictionaries
• Generating edges
• Find isolated nodes
• Finding path between two vertex/ node
• Finding all paths in graphs
• Finding shortest path between nodes
• Determine cycles in graphs
• Add an edge
REQUIREMENTS
• PC with windows
• Anaconda environment/Online python compiler
8.1 FUNDAMENTALS OF GRAPHS
• Vertex
It is a point where multiple lines meet. It’s also known as the node. A
vertex is generally denoted by an alphabet as shown below.
• Edge
It is a line that connects two vertices.
• Graph
Graph is a combination of vertices (nodes) and edges.
G = (V, E) where V represents the set of all vertices and E represents the set of all
edges of the graph.
• Directed Graph
Directed graphs have edges with direction. The edges indicate a one-way
relationship, in that each edge can only be traversed in a single direction.
• Un-Directed Graph
Un-directed graph have edges that do not have a direction. The edges indicate a
twoway relationship, in that each edge can be traversed in both directions.
CODE
OUTPUT
EXAMPLE 2
Implement the graph of example 1 by creating a function of edges.
8.4 Isolated Node
Any node which is not associated with any edge is called isolated node.
ISOLATED NODE