"kruskal algorithm time complexity" Code Answer's

You're definitely familiar with the best coding language C++ that developers use to develop their projects and they get all their queries like "kruskal algorithm time complexity" answered properly. Developers are finding an appropriate answer about kruskal algorithm time complexity related to the C++ coding language. By visiting this online portal developers get answers concerning C++ codes question like kruskal algorithm time complexity. Enter your desired code related query in the search bar and get every piece of information about C++ code related question on kruskal algorithm time complexity. 

kruskal's algorithm

By Bloody BuzzardBloody Buzzard on Aug 30, 2020
#include<bits/stdc++.h>

using namespace std;

int  main()
{
	int n = 9;
	
	int mat[9][9] = {
	{100,4,100,100,100,100,100,8,100},
	{4,100,8,100,100,100,100,100,100},
	{100,8,100,7,100,4,100,100,2},
	{100,100,7,100,9,14,100,100,100},
	{100,100,100,9,100,10,100,100,100},
	{100,100,4,14,10,100,2,100,100},
	{100,100,100,100,100,2,100,1,6},
	{8,100,100,100,100,100,1,100,7},
	{100,100,2,100,100,100,6,7,100}};
	
	int parent[n];
	
	int edges[100][3];
	int count = 0;
	
	for(int i=0;i<n;i++)
		for(int j=i;j<n;j++)
		{
			if(mat[i][j] != 100)
			{
				edges[count][0] = i;
				edges[count][1] = j;
				edges[count++][2] = mat[i][j];	
			}		
		}

	for(int i=0;i<count-1;i++)
		for(int j=0;j<count-i-1;j++)
			if(edges[j][2] > edges[j+1][2])
				{
					int t1=edges[j][0], t2=edges[j][1], t3=edges[j][2];
					
					edges[j][0] = edges[j+1][0];
					edges[j][1] = edges[j+1][1];
					edges[j][2] = edges[j+1][2];
					
					edges[j+1][0] = t1;
					edges[j+1][1] = t2;
					edges[j+1][2] = t3;
				}
				
	int mst[n-1][2];
	int mstVal = 0;
	int l = 0;
	
	cout<<endl;
	
	for(int i=0;i<n;i++)
		parent[i] = -1;
	cout<<endl;
				
	for(int i=0;i<count;i++)
	{
		if((parent[edges[i][0]] == -1 && parent[edges[i][1]] == -1))
		{
			parent[edges[i][0]] = edges[i][0];
			parent[edges[i][1]] = edges[i][0];
			
			mst[l][0] = edges[i][0];
			mst[l++][1] = edges[i][1];
			
			mstVal += edges[i][2];
		}
		
		else if((parent[edges[i][0]] == -1 && parent[edges[i][1]] != -1))
		{
			parent[edges[i][0]] = parent[edges[i][1]];
			
			mst[l][0] = edges[i][1];
			mst[l++][1] = edges[i][0];
			
			mstVal += edges[i][2];
		}
		
		else if((parent[edges[i][0]] != -1 && parent[edges[i][1]] == -1))
		{
			parent[edges[i][1]] = parent[edges[i][0]];
			
			mst[l][0] = edges[i][0];
			mst[l++][1] = edges[i][1];
			
			mstVal += edges[i][2];
		}
		
		else if(parent[edges[i][0]] != -1 && parent[edges[i][1]] != -1 && parent[edges[i][0]] != parent[edges[i][1]])
		{
			int p = parent[edges[i][1]];
			for(int j=0;j<n;j++)
				if(parent[j] == p)
					parent[j] = parent[edges[i][0]];
			
			mst[l][0] = edges[i][0];
			mst[l++][1] = edges[i][1];
			
			mstVal += edges[i][2];
		}
	}
	
	for(int i=0;i<l;i++)
		cout<<mst[i][0]<<" -> "<<mst[i][1]<<endl;
	
	cout<<endl;
	cout<<mstVal<<endl;
		
	return(0);
}

Add Comment

4

kruskal algorithm time complexity

By AlgoristyAlgoristy on Apr 26, 2021
Time complexity:- O(ElogV)

Add Comment

0

All those coders who are working on the C++ based application and are stuck on kruskal algorithm time complexity can get a collection of related answers to their query. Programmers need to enter their query on kruskal algorithm time complexity related to C++ code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about kruskal algorithm time complexity for the programmers working on C++ code while coding their module. Coders are also allowed to rectify already present answers of kruskal algorithm time complexity while working on the C++ language code. Developers can add up suggestions if they deem fit any other answer relating to "kruskal algorithm time complexity". Visit this developer's friendly online web community, CodeProZone, and get your queries like kruskal algorithm time complexity resolved professionally and stay updated to the latest C++ updates. 

C++ answers related to "kruskal algorithm time complexity"

View All C++ queries

C++ queries related to "kruskal algorithm time complexity"

kruskal algorithm time complexity kruskal's algorithm kruskal's algorithm c++ hackerearth Kruskal's algorithm in C what is time complexity of min_element() c++ sort function time complexity what is time complexity of swap function c++ vector insert time complexity what is time complexity of insertion sort how to get the prime number in c++ where time complexity is 0(log n) bellman ford algorithm cp algorithm initialize a vector with another vector c++ complexity bucket sort algorithm c++ simple -vector cp algorithm articulation points z function cp algorithm naive pattern matching algorithm bresenham's line algorithm c++ all pair shortest path algorithm in c with program dijkstra algorithm c++ bellman ford algorithm naive string matching algorithm binary search algorithm stack algorithm in c++ Polycarp found a rectangular table consisting of n rows and m columns. He noticed that each cell of the table has its number, obtained by the following algorithm "by columns": codeforces solution 3d projection onto 2d plane algorithm kadane algorithm with negative numbers included as sum what algorithm does bitcoin use code implementation of krushkals algorithm Write a program to implement Liang-Bersky line clipping algorithm extended euclidean algorithm in java z algorithm dijkstra's algorithm euclid algorithm gcd algorithm dijkstra algorithm Algorithm check balanced parentheses Dijkstra's Shortest Path Algorithm c++ show time elapsed time measurement c++ c++ time nanoseconds eosio get time time function c++ how to get current time in c++ is TLE means my code is correct but taking more time to computr c++ print current time c++ compare time input time from console C++ "how we write a program for" time swap" in c plus plus only with string" TIME CLASS c++ program that calculates the distance covered by a vehicle given the speed and time. Write a program that inputs time in seconds and converts it into hh-mm-ss format run time calculator c++

Browse Other Code Languages

CodeProZone