write programme in java , Implement the Dijkstra’s method
import java.util.*; public class Dijkstra { public int[][] graph; public Node[] nodes; public static class Node { public Node parent; public int cost; public int id; public Node(Node parent, int cost, int id) { this.parent = parent; this.cost = cost; this.id = id; } } public Dijkstra() { graph = new int[][]{{0, 4, 0, 0, 0, 0, 0, 8, 0}, {4, 0, 8, 0, 0, 0, 0, 11, 0}, {0, 8, 0, 7, 0, 4, 0, 0, 2}, {0, 0, 7, 0, 9, 14, 0, 0, 0}, {0, 0, 0, 9, 0, 10, 0, 0, 0}, {0, 0, 4, 14, 10, 0, 2, 0, 0}, {0, 0, 0, 0, 0, 2, 0, 1, 6}, {8, 11, 0, 0, 0, 0, 1, 0, 7}, {0, 0, 2, 0, 0, 0, 6, 7, 0} }; nodes = new Node[graph.length]; } public static void main(String[] args) { Dijkstra dijkstra = new Dijkstra(); for(int i = 0; i < dijkstra.nodes.length; i++) dijkstra.nodes[i] = new Node(null, Integer.MAX_VALUE, i); int source = 0; int destination = 4; dijkstra.shortestPath(source, destination); System.out.println("Shortest Distance from " + source + " to " + destination + " is " + dijkstra.nodes[destination].cost); Node temp = dijkstra.nodes[destination]; System.out.println("Path is "); while(temp.parent != null) { System.out.print(temp.id + " <--- "); temp = temp.parent; } System.out.println(temp.id); } public void shortestPath(int source, int destination) { Set<Node> visited = new HashSet<>(); PriorityQueue<Node> pQueue = new PriorityQueue<>(new Comparator<Node>() { @Override public int compare(Node o1, Node o2) { return o1.cost - o2.cost; } }); nodes[source].cost = 0; pQueue.add(nodes[source]); while(!pQueue.isEmpty()) { Node currVertex = pQueue.poll(); for(int i = 0; i < graph.length; i++) { if(graph[currVertex.id][i]!=0 && !visited.contains(nodes[i]) ) { if(!pQueue.contains(nodes[i])) { nodes[i].cost = currVertex.cost + graph[currVertex.id][i]; nodes[i].parent = currVertex; pQueue.add(nodes[i]); } else { nodes[i].cost = Math.min(nodes[i].cost, currVertex.cost + graph[currVertex.id][i]); if(nodes[i].cost == currVertex.cost + graph[currVertex.id][i]) nodes[i].parent = currVertex; } } } visited.add(currVertex); } } }
Dijkstra’s Algorithm: You have to implement the Dijkstra’s algorithm and apply it on the graph provided below. You have to take the input from the user as an adjacency matrix representing the graph, the source, the destination. Then you have to apply the Dijkstra’s algorithm to find the shortest path from the source and the destination, and find the shortest route between the source and the destination. For the input you have to read it from a file. It will...
In Java, create a list that represents a sentence. Then: Write a method that counts and returns the number of punctuation in a given sentence. Express this as a higher-order function and implement it. Write a method that counts and returns the number of words in the sentence that have the letter ’z’ in them. Express this as a higher-order function and implement it.
Java Write a pseudocode and Java program to implement the Stack using arrays. Write Push(), Pop(),and Display() methods to demonstrate that it works.
Software Data Structure & Algorithms 1- Write a java method that reversing an array using a stack. Use ArrayStack(). 2- Write a java method that implement matching delimiters. Use LinkedStack.
PLEASE READ THE FULL INSTRUCTION. Write a Java programme to print the pattern of asterisks shown below. For i=1 For i=2 * * For i=3 For i=n ** * ** ** ......... * (n asterisks) Your program should prompt the user to enter the value of n and then draw the corresponding star pattern. Remember if n is 5, you will have to print five patterns for i=1, i=2, i=3, i=4, and i=5. If n is 3, you will have...
1) ALL IN JAVA THANK YOU Design and implement a method that invokes other methods (either predefined in the Java API, or your own helper methods). This is method decomposition. 2) Write or evaluate a comment for a method. Each method should have comments that include its purpose, description of its parameters and return (if any) including data types, and any assumptions.
JAVA PROGRAMME A class called “Gallery” to hold information in an auto gallery catalog It will be described. “Gallery” class, brand (String) belonging to cars, model (int), price (double), color (String) will hold the fuel type (String) and body type (String) attributes. Also a class named “Mother” It will be. Values will be assigned to the properties of the “Gallery” class, and objects will be produced through this class. a. Write the specified classes in Java programming language. b. By...
Write a java code that will Implement Simple Substitution cipher with permutations and Implement Letter Frequency Analysis. As well as Apply Letter Frequency Analysis to chosen outputs of your Simple Substitution encryption.
Write in Java Implement the parse method and test it by calling with three different strings and by printing the results. The Scanner method can be used to read values from strings, files, or System.in. We need to invoke the useDelimiter method to define what symbols can separate, or terminate, the digits of a Fraction. public static Fraction parse(String input) t Scanner s new Scanner(input) useDelimitercTVMitln"); int num s.nextlnt() int denom s.nextlnt); s.close): return new Fraction(num, denom) class Codechef static...
Write a JAVA program: Consider the method displayRowOfCharacters that displays any given character the specified number of times on one line. For example, the call displayRowOfCharacters(‘*’, 5) produces the line ***** Implement this method by using recursion.