Java @ build the dijkstra algorithm (java. util. ArrayList) and dijkstra Algorithm on an undirected graph using ArrayList
package dataStructure;import java.util.ArrayList;import java.util.Scanner;import java.io.*;class node { int to, dist; node(int t, int d) { to = t; dist = d; }}public class Gra
;11Destination:12Distance:5Path:0->2->5->12Destination:13Distance:5Path:0->3->7->8->14->13Destination:14Distance:4Path:0->3->7->8->14Destination:15Distance:5Path:0->3->7->8->14->15Destination:16Distance:5Path:0->2->5->10->11->16Destination:17Distance:6Path:0->3->7->8->14->13->17The preliminary test results are correct.At this point, the above is a personal understanding of the Dijkstra algorithm, if there is a problem, please indicate treatise.Respect
SOURCE Link: Dijkstra Algorithm for Shortest path (Java) Task description: Gets the shortest path description of the starting node to all other nodes in an no-map diagramThe Dijkstra (Dijkstra) algorithm is a typical shortest path routing algorithm used to calculate the shortest path of a node to all other nodes. The m
= Integer.MAX_VALUE; // 最大值 ...}MATRIXUDG are the corresponding structures of the adjacency matrices. Mvexs is used to save vertices, medgnum is used to hold the number of edges, and Mmatrix is a two-dimensional array to hold the matrix information. For example, mmatrix[i][j]=1 means "vertex I (i.e. mvexs[i])" and "Vertex J (i.e. Mvexs[j])" are adjacency points; mmatrix[i][j]=0, they are not adjacency points.2. Dijkstra algorithm /* *
How can we find the shortest path from V0 to V5 in the figure?The java implementation method is as follows:Step 1: Create a weight matrix based on the graph:Int [] [] W = {{0, 1, 4,-1,-1,-1 },{1, 0, 2, 7, 5,-1 },{4, 2, 0,-1, 1,-1 },{-1, 7,-1, 0, 3, 2 },{-1, 5, 1, 3, 0, 6 },{-1,-1,-1, 2, 6, 0}; (-1 indicates that the two sides are not adjacent and the weight is infinitely large)For example, W [0] [2] = 4 indicates that the weight of point V0 to point V
To find the shortest path in the program, I used the dijela algorithm, found an implementation on the Internet, and then upgraded myself to a lower level, as shown below:
Package reverse;Import java. util. ArrayList;Import java. util. HashMap;Import java. util. List;Import java. util. Map;Import
This paper introduces the Dijkstra algorithm based on Java, and believes that it is helpful for readers to study data structure domain algorithm.
Dijkstra proposes an algorithm to generate the shortest path to each vertex by increasing the order of path lengths between each vertex and the source Point v. That is to find out the shortest length of a shortest path
public class Dijkstra {private static int N = 1000;private static int[][] Graph = {{0, 1, 5, n, N, N, N, N, n}, {1, 0, 3, 7, 5, N, N, N, n},{5, 3, 0, N, 1, 7, n, N, n}, {n, 7, N, 0, 2, N, 3, N, n}, {n, 5, 1, 2, 0, 3, 6, 9, n},{N, N, 7, N, 3, 0, N, 5, n}, {n, N, N, 3, 6, N, 0, 2, 7}, {n, n, N, N, 9, 5, 2, 0, 4},{N, N, N, N, N, N, 7, 4, 0}};p ubli c static void Main (string[] args) {Dijkstra (0, Graph);} /**
The Dijkstra algorithm is a familiar one in the shortest path algorithm, and is a single-origin full-path algorithm. This algorithm is known as a successful model of "greedy algorithm". This article will then try to introduce this great algorithm in the most popular language and give Java implementation code.First, knowledge preparation1, the data structure of the representation diagramThere are many data s
Tag: Shortest path Dijkstar greedy algorithm JavaLearn Dijstar algorithm starting from Shortest pathThe following is a description of the shortest path problem:The following is a description of the Dijkstar algorithm:Here's how to solve the problem in the right graph using the Dijkstar algorithm:Here is the adjacency matrix of the graph:Here is the calculation process:Here's how to solve the shortest path:Here is the Java code implementation, which ne
Recently participated in a competition in the company, which involves a problem that can be simplified as a description: a two-dimensional matrix, each point has a weight, you need to find from the specified starting point to the end of the shortest path.
Immediately thought of the Dijkstra algorithm, so again warm up again, here give a Java implementation.
And the output of the shortest path, the online al
Task Description: Gets the shortest path description of the starting node to all other nodes in a non-direction graph
Dijkstra (Dijkstra) algorithm is a typical shortest path routing algorithm, which is used to compute the shortest path of a node to all other nodes. The main feature is to extend the starting point to the outer layer until the end is extended.
There are usually two ways to
PrefaceThe Dijkstra algorithm is a familiar one in the shortest path algorithm, and is a single-origin full-path algorithm. This algorithm is known as a successful model of "greedy algorithm". This article will then try to introduce this great algorithm in the most popular language and give Java implementation code.First, knowledge Preparation:1, the data structure of the representation diagramThere are man
, put the C point into the close collection. 3. Look again at a point closest to a (not the point in the close set, that is, the point that has not been analyzed, af=25,ab=13,ad=15 is actually B point)4. Then perform the Step2 action at point B, and find the temporary shortest distance for all child nodes of a distance B, so repeatedly, until the close collection includes all points.The specific Java code is as follows: /** * */package com.test.di
Introduction to Dijkstra algorithm
Dijkstra (Dijkstra) algorithm is a typical shortest path algorithm, which is used to compute the shortest path of a node to another node.Its main feature is to extend to the outer layer (breadth-first search idea) with the starting point as the center, until the extension to the endpoint.
Basic ideas
When you calculate the sh
("====================================="); for(inti = 1; I ) {System.out.println (The shortest distance from 1 to "+ i +" points is: "+Bestmin[i]); } } Public Static voidMain (string[] args) {//TODO auto-generated Method StubScanner Input=NewScanner (system.in); System.out.print ("Please enter the number of nodes N, total number of paths m:"); N=Input.nextint (); M=Input.nextint (); Max= 10000; Bestmin=New int[N+1]; Distance=New int[N+1] [N+1]; Visit=New int[N+1]; Path=NewString[n+1];
least-authorized path is as follows:Traversal gets the actual shortest pathShow Shortest Path:Finally, write an external usage class that you can use on Android or anywhere else.Getdijkstrapath.javaIn the main method, the distance to the target point (5, 4) or (5, 5) is output as follows:The output path is in JSON format and is easy to parse. in Android, the source of the snake is adapted for random generation of related "maps". After various tests, the algorithm is correct.--
Task Description: Gets the shortest path description of the starting node to all other nodes in an none graphThe Dijkstra (Dijkstra) algorithm is a typical shortest path routing algorithm used to calculate the shortest path of a node to all other nodes. The main feature is to extend from the center of the starting point to the outer layer until it expands to the end point.Dijkstra general expressions usuall
It took nearly one day to finally implement the dikexch algorithm (Dijkstra. Efficiency needs to be improved, and correctness needs to be verified. Now paste the source code.
Import Java. util. arraylist;
The current running result is:
{1 = [0, 1], 2 = [0, 2], 3 = [0, 4, 3], 4 = [0, 4], 5 = [0, 4, 3, 5]}Length (0-1) = infinityLength (0-2) = 10Length (0-3) = 50Length (0-4) = 30Length (0-5) = 60
{0 = [1, 0]
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.