Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 10

Discrete Structures

Project (Graphs)

Submitted by:
Sadain Sikandar
BIT-23S-091
Program: BS IT
Section: 3B

Submitted to:
Sir Abdul Hannan Sheikh
Project Task:

Write a program in language of your preference for instance C, C++ and/or


Python. Program should check if graph is
(a) Connected
(b) Has cycles
(c) Trees
Program should take adjacency matrix of graph as input and return if graph
corresponding to adjacency matrix is (a) connected, (b) has cycles and (c) trees.
Test your program for two example one for connected and one for not connected,
and two examples one has cycles and one does not have cycles and two examples
of trees and not trees.
Submit in form of report (MS word file), which should include:
(i) Program
(ii) 6 different examples of graphs; their adjacency matrices and their graphs
(iii) Output of program for 6 examples
(iv) Your comments (would add value to project)

Report:

This program checks if a graph is:


(a) Connected (b) Has cycles (c) Is a tree
The program takes the adjacency matrix of the graph as input and returns the
corresponding properties.

Program (C++):

Example 1: Connected Graph (4 vertices)


Adjacency Matrix:

0110
1011
1101
0110

OUTPUT:

Example 2: Not Connected Graph (5 vertices)


Adjacency Matrix:

01000
10000
00010
00100
00000

OUTPUT:

Example 3: Graph with Cycles (6 vertices)


Adjacency Matrix:

011000
101000
110100
001010
000101
000010

OUTPUT:

Example 4: Graph without Cycles (5 vertices)


Adjacency Matrix:

01000
10100
01011
00100
00100

OUPUT:

Example 5: Tree Graph (7 vertices)


Adjacency Matrix:

0100000
1010000
0101000
0010100
0001010
0000101
0000010

OUTPUT:

Example 6: Not a Tree Graph (6 vertices)


Adjacency Matrix:

011000
101100
110010
010001
001000
000100

OUPUT:

Conclusion:

In conclusion, this project was an educational journey that


enhanced my understanding of graph theory concepts, sharpened
my programming skills in C++, and improved my problem-
solving abilities. Through implementing algorithms to analyze
graph properties like connectivity, cycles, and trees, I gained
practical insights into graph behavior. Thorough testing and
documentation ensured the correctness and clarity of the project.
Overall, this experience has prepared me for further exploration
of graph theory and its applications in various domains.

You might also like