0% found this document useful (0 votes)
50 views10 pages

Name: MD Rakibul Islam ID: 20183290424: Data Structure Homework

1. The document describes steps to create a graph using an adjacency matrix and perform DFS on the graph. It includes defining node and edge variables, populating the adjacency matrix, and using colors to mark nodes as visited. 2. Steps are then provided to find the minimum spanning tree using Kruskal's algorithm. This involves sorting edges by weight and adding edges without creating cycles. 3. The result shows the adjacency matrix for the sample graph and the output of applying DFS and finding the minimum spanning tree on it.

Uploaded by

Rakibul Islam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views10 pages

Name: MD Rakibul Islam ID: 20183290424: Data Structure Homework

1. The document describes steps to create a graph using an adjacency matrix and perform DFS on the graph. It includes defining node and edge variables, populating the adjacency matrix, and using colors to mark nodes as visited. 2. Steps are then provided to find the minimum spanning tree using Kruskal's algorithm. This involves sorting edges by weight and adding edges without creating cycles. 3. The result shows the adjacency matrix for the sample graph and the output of applying DFS and finding the minimum spanning tree on it.

Uploaded by

Rakibul Islam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Name: MD RAKIBUL ISLAM

ID: 20183290424
Data structure Homework
Experiment Part

Final project graph

Problem:
➢ write a program to create the graph using adjacency matrix/list
➢DFS/BFS
➢Find the Minimum Spanning Tree

Steps :( for adjacency matrix and DFS)

1. Tooke some variable for node and edge and a array.


2. Run a for loop to take the value of nodes.
3. For every node connection we assign value 1.
4. Then print the matrix.
5. For DFS we just define 3 colors white, gray and black.
6. For white=1 we can work on it.
7. For Gray=2 we are working (traverse) this node.
8. For Black=3 work/traverse finished.
9. Create a function called dfs for traverse.
10. Create another function called dfsvisit with parameter.
11. In dfs function first we mark every node as White.
12. Apply dfs in every node and start dfsvisit () in every
white node.
13. In dfsvisit function we make gray that node where we
are working.
14. After work we go the neighbor of that node if it’s white
we start work on that node.
15. After finished work we make that node as black.
Result:
Output will be
Here is the table for matrix for that graph.

1 2 3 4 5 6
1 0 1 1 1 0 0
2 1 0 1 0 1 0
3 1 1 0 1 1 1
4 1 0 1 0 0 1

5 0 1 1 0 0 1
6 0 0 1 1 1 0

Here is the input for that graph.

Node edge
6 10
1 3
6 4
5 2
6 3
2 3
4 1
5 3
5 6
1 2
4 3

Steps: (for finding minimum spanning tree)


1. First we made 2 structure for edge and edge list.
2. Then we take 2D array and some variable.
3. Then create some function for apply Krushkal
Algorithm, find the node, apply unite, short the
graph and print the graph.
4. In KrushkalAlgo() function first we Start with a
weighted graph.
5. Choose the edge with the least weight, if there are
more then 1, choose anyone.
6. Choose the next shortest edge and add it.
7. Choose the next shortest edge that doesn’t creat a
cycle and add it.
8. Repeat until we get a spanning tree.
9. In find function we get the vertax no.
10. In applyUnion we put the value.
11. In short function we short the graph accroding
its waight.
12. In print function we just print it.
13. And in main function we put the value for that
graph.
1

2 3 4

5 6

2 3 4

5 6

2 3 4

5 6
1

2 3 4

5 6
1

2 3 4

5 6

Result:
Output will be.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy