How do you implement Dijkstra's algorithm in c language?

1 Answer

Answer :

/* Dijkstra's Algorithm in C *//* Source: w w w . c o d e w i t h c . c o m / d i j k s t r a s- a l g o r i t h m - i n - c#include<stdio.h>#include<conio.h>#include<process.h>#include<string.h>#include<math.h>#define IN 99#define N 6int dijkstra(int cost[][N], int source, int target);int main(){int cost[N][N],i,j,w,ch,co;int source, target,x,y;printf("\t The Shortest Path Algorithm ( DIJKSTRA'S ALGORITHM inC \n\n");for(i=1;i< N;i++)for(j=1;j< N;j++)cost[i][j] = IN;for(x=1;x< N;x++){for(y=x+1;y< N;y++){printf("Enter the weight of the path between nodes %d and %d:",x,y);scanf("%d",&w);cost [x][y] = cost[y][x] = w;}printf("\n");}printf("\nEnter the source:");scanf("%d", &source);printf("\nEnter the target");scanf("%d", &target);co = dijsktra(cost,source,target);printf("\nThe Shortest Path: %d",co);}int dijsktra(int cost[][N],int source,int target){int dist[N],prev[N],selected[N]={0},i,m,min,start,d,j;char path[N];for(i=1;i< N;i++){dist[i] = IN;prev[i] = -1;}start = source;selected[start]=1;dist[start] = 0;while(selected[target] ==0){min = IN;m = 0;for(i=1;i< N;i++){d = dist[start] +cost[start][i];if(d< dist[i]&&selected[i]==0){dist[i] = d;prev[i] = start;}if(min>dist[i] && selected[i]==0){min = dist[i];m = i;}}start = m;selected[start] = 1;}start = target;j = 0;while(start != -1){path[j++] = start+65;start = prev[start];}path[j]='\0';strrev(path);printf("%s", path);return dist[target];}

Related questions

Description : Algorihtm used for path planning is A : Dijkstra's Algorithm B : DFS Algorithm C : BFS Algorithm D : Searching Algorithm

Last Answer : A : Dijkstra's Algorithm

Description : Dijkstra’s algorithm is based on (1) Divide and conquer paradigm (2) Dynamic Programming (3) Greedy Approach (4) Backtracking paradigm

Last Answer : 3

Description : In link state routing algorithm after construction of link state packets, new routes are computed using: (1) DES algorithm (2) Dijkstra's algorithm (3) RSA algorithm (4) Packets 

Last Answer : Answer: 2

Description : Message can be sent more securely using DES by a. encrypting plain text by a different randomly selected key for each transmission b. encrypting plain text by a different random key for each ... instead of using hardware d. designing DES with high security and not publicizing algorithm used by it  

Last Answer : b. encrypting plain text by a different random key for each message transmission and sending the key to the receiver using a public key system

Description : Assume a systems development project effort calculation determines that the system  will require 240 function points. If the developers choose to implement this system in the  C programming language, approximately ... without more information  c. exactly the same  d. much greater  e. much less

Last Answer : e. much less

Description : A _____ contains specific rules and words that express the logical steps of an algorithm. 1) Syntax 2) Programming structure 3) Programming language 4) Logic chart 5) None of these

Last Answer : Answer :3

Description : When an algorithm is written in the form of a programming language, it becomes a _________ a) Flowchart b) Program c) Pseudo code d) Syntax

Last Answer : Answer: b Explanation: An algorithm becomes a program when it is written in the form of a programming language. Thus, any program is an algorithm

Description : A ______ contains specific rules and words t hat express the logical steps of an algorithm a) Programming language b) Syntax error c) Programming structure d) Logic chart e) None of these

Last Answer : a) Programming language

Description : A compiler translates a program written in a high-level language into a) Machine language b) An algorithm c) A debugged program d) Java e) None of these

Last Answer : a) Machine language

Description : A compiler translates a program written in a high level language into 1) Machine Language 2) An algorithm 3) A debugged program 4) None of these

Last Answer : 1) Machine Language

Description : A ...... contains specific rules and words that express the logical steps of an algorithm. 1) Programming Language 2) Programming Structure 3) Syntax 4) Logic chart

Last Answer : 3) Syntax

Description : Which one of the following converts assembly language into machine language ? (1) Algorithm (2) Interpreter (3) Compiler (4) Assembler

Last Answer : Assembler

Description : How could we implement vegetarian listings on menus?

Last Answer : I’ve seen a “V” or a code symbol on some restaurant menus; also a heart for heart healthy dishes.

Description : What is this lawn care implement called?

Last Answer : A weedeater or string timmer.

Description : How will they implement new cost for obese people?

Last Answer : GQ. Many just ask height and weight, while most are requiring medical examination. Although the actual guidelines vary from insurance company to insurance company, most use a patient’s BMI to determine whether or not they are to be considered obese.

Description : If you could take any element from a video game and implement it into real life, how would you do so?

Last Answer : Super Mario Bros. I wish I could jump into a pipe and teleport to another location when I’m in an embarrassing situation.

Description : How to implement a JavaScript code that doing "Set as my Home Page" in Google Chrome?

Last Answer : So, you’re saying the JavaScript code for doing this works in IE and Firefox, but not Chrome? That’s weird. Let me see if I can find a script for you.

Description : When will Canada and The U.S. have to implement Austerity measures?

Last Answer : Luckily we waste so much money on the military we can slash the fuck out of that for a long time before people will care. No need to cut social programs while the Pentagon bankrupts the country.

Description : How can I implement in my small web site company how many members are observing each page right now?

Last Answer : I've seem people use the window.onbeforeunload event to do this. A common problem with this method is a script not finishing in time. You can use the event to open a new web page that runs a ... , but never sends display information. That way you don't have to worry about your function being killed.

Description : When the stresses of your personal life affect your work performance, what tactics do you implement to prevent productivity from taking a complete nose dive?

Last Answer : The more stressed I am then the more regimented I get with my food and exercises which makes my moods optimum even (for me) and helps me sleep more often to offset the dregs of what stress leaches ... or all giddy for some reason that I'll go lax with food, forego sleep and neglect my exercises.

Description : How can one implement a successful strategy process?

Last Answer : Yes they can through careful planning and strong follow through.

Description : Have you ever wanted the authority to create and implement a legal punishment for an act you felt was offensive to society?

Last Answer : I hate that trend myself. I wouldn’t go so far as police brutality, but I would advocate tripping them. ^_^

Description : Is Obama to the point in his administration where he can finally implement his own policies, instead of constantly cleaning up after Bush?

Last Answer : I think it’s going to be a long time before we’re done cleaning up after Bush’s mess. Really, it’s normal for a president’s policies during his term to have long-lingering effects. In many ways we’re still dealing with Ronald Reagan’s messes.

Description : How can I implement a Seinfeldian Chain on my website?

Last Answer : Never heard of the Seinfeldian Chain until now, even though have been practicing it all my life. Want my honest opinion? It sounds to me like the whole I don't use paper, I want it online argument is simply a ploy ... ) works is 1) it's simple, 2) it's easy, and 3) it's visible. Just do it.

Description : Embarking on millennia-long journeys - What are the main obstacles to implement embryo space colonization missions?

Last Answer : Lack of embryo concent.

Description : It will be a tough year of transition for the Tampa Bay Buccaneers with the loss of a coach, many key players & two star running backs doubtful. What strategies do they need to implement to have a successful 2009 season in the NFC South?

Last Answer : They need to find a franchise quarterback. They’ve been having quarterback carousels/controversies for as long as I can remember.

Description : Which rule implement for axes Nomenclature? a.Left-hand rule b.Right-Hand Rule c.Thumb Rule d.None of the above

Last Answer : b.Right-Hand Rule

Description : A recently purchased implement for brushing away floor dirt invariably effaces the dirt most efficiently. What is the proverb? -Riddles

Last Answer : A new broom sweeps clean.

Description : Who refuse to implement the Interim Government Plan as proposed in the Cabinet Mission Plan? -SST 10th

Last Answer : The Viceroy refused to implement the Interim Government Plan as proposed in the Cabinet Mission Plan.

Description : First company to implement full-time work from home -Do You Know?

Last Answer : Twitter was the first company to implement full time work form home

Description : Binance Support Number 1**866308**O156 more instant Resolution with Binance Tech-Support Number +1-866-308-0156 to implement them?

Last Answer : Binance Support Number 1866308O156 more instant Resolution with Binance Tech-Support Number +1-866-308-0156 to implement them. Binance Support Number 1866308O156 more instant Resolution with Binance Tech- ... -Support Number +1-866-308-0156 to implement them.Binance Support Number 1866308O156 more

Description : How to implement pay per view access restrictions for ppv video hosting platform?

Last Answer : For this purpose you will have to use a software like StreamingVideoProvider. With this pay per view video streaming platform, you can easily implement access restrictions and set a rate plan. I have ... Provider for the last 2 years and believe that it is the easiest platform for video hosting.

Description : What smartphone feature would you be excited for a company to implement ?

Last Answer : Common apps to leverage work for a technology company are EmailAnalytics: team's email activity, for productivity KPIs, emails sent, emails received and average email response time and reports. ... online, get online invoicing, checkout, card reader on the go transactions and tracking payments

Description : How do you implement binary search code in visual basic?

Last Answer : The optimal binary search algorithm uses a sorted array as thedata container. Define the range to be searched using a half-closedrange of indices [begin:end). Initially, this will be thehalf- ... range is either empty or invalid(begin>=end), so the value does not existReturn not_foundEnd Function

Description : What would happen if each state could implement the bill of rights as they see fit?

Last Answer : Each state can’t because we have a federal government with theconstitution and Bill of Rights.

Description : What did the song dynasty implement to create a meritocracy?

Last Answer : Changes that the Song dynasty implement to create a meritocracywere that they brought religion into the civil service examinationsthat were to be taken in order to work for the government such asquestions on Confusious' teachings, Daoism, and Buddhism

Description : How do you implement symbol tables in c?

Last Answer : Symbol tables are implemented as a hierarchical tree of scopes,with the global scope serving as the root. All names declared atglobal scope are listed in the root. Global function names areimplemented as child ... isn't found, the name was not declared so the compilation hasto fail at that point.

Description : What is the best way to implement changes to the house policy?

Last Answer : Write a letter to congress men.

Description : Is it important that ideas at work include practical ways to implement them.?

Last Answer : Yes it is. Not only do you come up with important ideas at workbut you need to have a way to execute or make them work

Description : What is the dictionary meaning or denotation of the word implement?

Last Answer : What is the answer ?

Description : Did Calvin and his supporters implement his ideas?

Last Answer : Need answer

Description : Why is it necessary to develop and implement performance plans in accordance with organisation and goals and objectives?

Last Answer : Need answer

Description : What color war policy did president Truman implement to carry out this pledge?

Last Answer : Need answer

Description : How do you implement controls risk managment?

Last Answer : Need answer

Description : Is it important that ideas at work include practical ways to implement them.?

Last Answer : Yes it is. Not only do you come up with important ideas at workbut you need to have a way to execute or make them work

Description : Who decides implement split MOPP?

Last Answer : Installation Commander

Description : What are the best vocabulary strategies to implement?

Last Answer : You may find vocabulary strategies to help improve your vocabulary at the following site...www.benchmarkeducation.com/...leader/.../vocabulary-instruction.ht..

Description : What are the best grammar exercises to implement?

Last Answer : You may find some grammar exercises at the following websites...www.ginaabudi.com/tips-for-implement-best-practice-initiatives/ or www.ishn.com/.../managing-best-practices-how-to-implement-best-pr...

Description : How can I implement better cloud computing management?

Last Answer : Cloud computing management can be done most effectively through a personal I.T. consultant. There are various businesses that will supply your needs.