0% found this document useful (0 votes)
310 views13 pages

Tour Operations Problem Using Kruskal's Algorithm Daa Mini Project Report

This document describes using Kruskal's algorithm to solve a tour operations problem of planning an efficient itinerary to visit important sites in Venice within a limited time. It provides an example problem by modeling Venice's map as a graph and applying Kruskal's algorithm. Kruskal's algorithm finds a minimum spanning tree by sorting edges by weight and connecting components without forming cycles, ensuring the lowest total cost. Pseudocode and C++ code are provided to implement Kruskal's algorithm, with overall time complexity of O(E log E) where E is the number of edges.

Uploaded by

Sai Rohit Paturi
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)
310 views13 pages

Tour Operations Problem Using Kruskal's Algorithm Daa Mini Project Report

This document describes using Kruskal's algorithm to solve a tour operations problem of planning an efficient itinerary to visit important sites in Venice within a limited time. It provides an example problem by modeling Venice's map as a graph and applying Kruskal's algorithm. Kruskal's algorithm finds a minimum spanning tree by sorting edges by weight and connecting components without forming cycles, ensuring the lowest total cost. Pseudocode and C++ code are provided to implement Kruskal's algorithm, with overall time complexity of O(E log E) where E is the number of edges.

Uploaded by

Sai Rohit Paturi
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/ 13

Tour Operations Problem Using Kruskal’s Algorithm

DAA MINI PROJECT REPORT

TEAM MEMBERS:
Paturi Sai Rohit(200)
Koushiki Ray(199)
Hemanth(238)
CONTENTS:

1. CONTRIBUTION TABLE
2 ◦ INTRODUCTION ----------------------------------------------------------
1. OVERVIEW ----------------------------------------------------------------------
2. BACKGROUND-----------------------------------------------------------------
3. PROBLEM STATEMENT------------------------------------------------------
4. PROBLEM EXPLANATION -------------------------------------------------
3 ◦ METHODOLOGY ---------------------------------------------------------
1. DESIGN TECHNIQUE --------------------------------------------------------
2. ALGORITHIM -------------------------------------------------------------------
3. EXAMPLE ------------------------------------------------------------------------
4 ◦ COMPLEXITY ANALYSIS --------------------------------------------------------
----
1. TIME COMPLEXITY ----------------------------------------------------------
2. SPACE COMPLEXITY
5 ◦ CODE -------------------------------------------------------------------------------
-------
6 ◦ CONCLUSION ---------------------------------------------------------------------
------
7. REFERENCES
Problem statement
The tourism industry faces a great challenge in the age of
information technology development. The traditional tourism
distribution channel faces a threat from the emerging IT
environment. Throughout the years, the tourism industry depended
on intermediaries, who enabled the interaction between suppliers
and customers. Nowadays, however, the suppliers can reach the
customer directly via the internet having the geographical distance
barriers and costs associated with them, disappeared. The internet
age changed the complexity of tourism distribution, enabling the
entry of the new virtual intermediaries characterized by a strong
competitive advantage over other players in the sector .

Example
On your trip to Venice, you plan to visit all the important world
heritage sites but are short on time. To make your itinerary work,
you decide to use Kruskal’s algorithm using disjoint sets. Here is a
map of Venice
What is Kruskal’s algorithm?

Kruskal's Algorithm is used to find the minimum spanning tree for a


connected weighted graph. The main target of the algorithm is to
find the subset of edges by using which we can traverse every vertex
of the graph. It follows the greedy approach that finds an optimum
solution at every stage instead of focusing on a global optimum.
Spanning tree –
A spanning tree is the subgraph of an undirected connected graph.
Minimum Spanning tree –
Minimum spanning tree can be defined as the spanning tree in which
the sum of the weights of the edge is minimum. The weight of the
spanning tree is the sum of the weights given to the edges of the
spanning tree.

Approach to Solve the Problem:


Let’s simplify the map by converting it into a graph as below and
naming important locations on the map with letters and distance in
meters (x 100).
Cannaregio A
Ponte Scalzi B
Santa Croce C

Dell ‘Orto D
Ferrovia E
Piazzale Roma F
San Polo G

Dorso Duro H
San Marco I
St. Mark Basilica J
Castello K

Arsenale L

1. Remove all loops and parallel edges So for the given map, we
have a parallel edge running between Madonna dell Orto (D) to
St. Mark Basilica (J), which is of length 2.4kms(2400mts). We
will remove the parallel road and keep the 1.8km (1800m)
length for representation.
2. Arrange all the edges on the graph in ascending order. Kruskal’s
algorithm considers each group as a tree and applies disjoint
sets to check how many of the vertices are part of other trees.

3. Add edges with the least weight; we begin with the edges with
the least weight/cost. Hence, B, and C are connected first
considering their edge cost only
I, J has cost 1; it is the edge connected next.
Then, we connect edges with weight = 2.
Similarly, we connect node K, L which has an edge with weight = 3.

As given in the table above, all the edges are connected in ascending
order, ensuring no loop or cycle is formed between 2 vertices. This
gives us the following graph, which is the minimum spanning tree for
the given problem.
Final Output

How does Kruskal's algorithm work?


In Kruskal's algorithm, we start with edges with the lowest weight
and keep adding the edges until the goal is reached.

The steps to implement Kruskal’s algorithm are listed as


follows –
-First, sort all the edges from low weight to high.
-Now, take the edge with the lowest weight and add it to the
spanning tree. If the edge is added creates a cycle, then reject the
edge.
-Continue to add the edges until we reach all vertices, and a
minimum spanning tree is created .
Step to Kruskal’s algorithm :
Sort the graph edges with respect to their weights.
Start adding edges to the minimum spanning tree from the edge with
the smallest weight until the edge of the largest weight.
Only add edges that don’t form a cycle—edges that connect only
disconnected components. Or as a simpler explanation,
Step 1 – Remove all loops and parallel edges
Step 2 – Arrange all the edges in ascending order of cost
Step 3 – Add edges with the least weight.

Algorithm:
Begin
create set for each vertices in graph g
for each set of vertex u do add u in the vertexSet[u]
done
sort the edge list.
count := 0
while count <= V – 1 do //as tree must have V – 1 edges
ed := edgeList[count] //take an edge from edge list
if the starting vertex and ending vertex of ed are in the same set then
merge vertexSet[start] and vertexSet[end]
add the ed into tree t
count:= count +1
done
End
Implementation of Kruskal’s algorithm
Now, let's see the implementation of Kruskal’s algorithm

Code:
#include <iostream>
#include <vector>
#include <utility>
#include <algorithim>
using namespace std;
const int MAX = 1e4 + 5;
int id[MAX], nodes, edges ;
pair<long long,pair<int int> p[MAX];
void initialize()
{
for(int i = 0;i < MAX;++I )
id[i] = i;
}
int root(int x)
{
while(id[x] != x)
{
id[x] = id[id[x]]; x = id[x];
}
return x;
}
void union1(int x, int y) { int p = root(x);
int q = root(y);
id[p] = id[q];
}
long long kruskal(pair > p[])
{
{
int x, y; long long cost, minimumCost = 0;
for(int i = 0;i < edges;++i)
{
// Selecting edges one by one in increasing order from the beginning
x = p[ i].second.first;
y = p[i].second.second;
cost = p[i].first;
if(root(x) != root(y))
// Check if the selected edge is creating a cycle or not
{
minimumCost += cost; union1(x, y);
}
}
return minimum cost;
}
int main()
{
int x, y;
long long weight, cost, minimumCost;
initialize();
cin >> nodes >> edges;
for(int i = 0;i < edges;++i)
{
cin >> x >> y >> weight;
p[i] = make_pair(weight, make_pair(x, y));
}
// Sort the edges in the ascending order
sort(p, p + edges);
minimumCost = kruskal(p);
cout << minimumCost << endl ;
return 0;
}

OUTPUT:
Complexity of Kruskal’s algorithm:
Let’s see the time complexity of Kruskal’s algorithm.
Time Complexity:
The time complexity of Kruskal’s algorithm is O(E logE) or O(E log V),
where E is the no. of edges, and V is the no. of vertices.
The complexity of our problem statement is O(11 log 12).
Space Complexity:
The space complexity is O(log(E))

Conclusion
Kruskal's algorithm to find the minimum cost spanning tree uses the
greedy approach. This algorithm treats the graph as a forest and
every node it has as an individual tree. A tree connects to another
only and only if, it has the least cost among all available options and
does not violate MST properties.
Kruskal's Algorithm is used to find the minimum spanning tree for a
connected weighted graph. The main target of the algorithm is to
find the subset of edges by using which we can traverse every vertex
of the graph.

REFERENCES
GeeksForGeeks
YouTube

You might also like