Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please write a complete working code in Java: Submission: Please show work for 1, 2 and 3 for this Project: please draw the graph with

Please write a complete working code in Java:

image text in transcribed

Submission: Please show work for 1, 2 and 3 for this Project: please draw the graph with 10 or more vertices for # 2 of project.

image text in transcribed

Sample Code and edge graph:

Project 8 Word: Sample Code For Project: import java.io.*; import java.util.*; class Node{ private int data; private Node nextNodePtr; public Node(){} public void setData(int d){ data = d; } public int getData(){ return data; } public void setNextNodePtr(Node nodePtr){ nextNodePtr = nodePtr; } public Node getNextNodePtr(){ return nextNodePtr; } } class List{ private Node headPtr; public List(){ headPtr = new Node(); headPtr.setNextNodePtr(null); } public Node getHeadPtr(){ return headPtr; } public boolean isEmpty(){ if (headPtr.getNextNodePtr() == null) return true; return false; } public void insert(int data){ Node currentNodePtr = headPtr.getNextNodePtr(); Node prevNodePtr = headPtr; while (currentNodePtr != null){ prevNodePtr = currentNodePtr; currentNodePtr = currentNodePtr.getNextNodePtr(); } Node newNodePtr = new Node(); newNodePtr.setData(data); newNodePtr.setNextNodePtr(null); prevNodePtr.setNextNodePtr(newNodePtr); } public void insertAtIndex(int insertIndex, int data){ Node currentNodePtr = headPtr.getNextNodePtr(); Node prevNodePtr = headPtr; int index = 0; while (currentNodePtr != null){ if (index == insertIndex) break; prevNodePtr = currentNodePtr; currentNodePtr = currentNodePtr.getNextNodePtr(); index++; } Node newNodePtr = new Node(); newNodePtr.setData(data); newNodePtr.setNextNodePtr(currentNodePtr); prevNodePtr.setNextNodePtr(newNodePtr); } public int read(int readIndex){ Node currentNodePtr = headPtr.getNextNodePtr(); Node prevNodePtr = headPtr; int index = 0; while (currentNodePtr != null){ if (index == readIndex) return currentNodePtr.getData(); prevNodePtr = currentNodePtr; currentNodePtr = currentNodePtr.getNextNodePtr(); index++; } return -1; // an invalid value indicating // index is out of range } public void modifyElement(int modifyIndex, int data){ Node currentNodePtr = headPtr.getNextNodePtr(); Node prevNodePtr = headPtr; int index = 0; while (currentNodePtr != null){ if (index == modifyIndex){ currentNodePtr.setData(data); return; } prevNodePtr = currentNodePtr; currentNodePtr = currentNodePtr.getNextNodePtr(); index++; } } public void deleteElementAtIndex(int deleteIndex){ Node currentNodePtr = headPtr.getNextNodePtr(); Node prevNodePtr = headPtr; Node nextNodePtr = headPtr; int index = 0; while (currentNodePtr != null){ if (index == deleteIndex){ nextNodePtr = currentNodePtr.getNextNodePtr(); break; } prevNodePtr = currentNodePtr; currentNodePtr = currentNodePtr.getNextNodePtr(); index++; } prevNodePtr.setNextNodePtr(nextNodePtr); } public void deleteElement(int deleteData){ Node currentNodePtr = headPtr.getNextNodePtr(); Node prevNodePtr = headPtr; Node nextNodePtr = headPtr; while (currentNodePtr != null){ if (currentNodePtr.getData() == deleteData){ nextNodePtr = currentNodePtr.getNextNodePtr(); break; } prevNodePtr = currentNodePtr; currentNodePtr = currentNodePtr.getNextNodePtr(); } prevNodePtr.setNextNodePtr(nextNodePtr); } public void IterativePrint(){ Node currentNodePtr = headPtr.getNextNodePtr(); while (currentNodePtr != null){ System.out.print(currentNodePtr.getData()+" "); currentNodePtr = currentNodePtr.getNextNodePtr(); } System.out.println(); } public int countList(){ Node currentNodePtr = headPtr.getNextNodePtr(); int countElements = 0; while (currentNodePtr != null){ //System.out.print(currentNodePtr.getData()+" "); countElements++; currentNodePtr = currentNodePtr.getNextNodePtr(); } return countElements; } } class Queue{ private int array[]; private int maxSize; // useful to decide if resizing (doubling the array size) is needed private int endOfQueue; // same as endOfArray public Queue(int size){ array = new int[size]; maxSize = size; endOfQueue = -1; } public boolean isEmpty(){ if (endOfQueue == -1) return true; return false; } public void resize(int s){ int tempArray[] = array; array = new int[s]; for (int index = 0; index = 0) return array[0]; else return -1000000;// an invalid value indicating // queue is empty } public int dequeue(){ if (endOfQueue >= 0){ int returnVal = array[0]; for (int index = 0; index Project 8: Use the Results of Breadth First Search to Extract the Shortest Paths from a Particular Vertex to the Rest of the Vertices in an Undirected Graph Due: April 19, 2018: by 1 PM (in Canvas) The objective of this project is to use the Breadth First Search (BFS) algorithm to determine the shortest paths (and print them) from a particular vertex to the rest of the vertices in the graph, You are given the code for running the BFS algorithm starting from a particular vertex (say, vertex 0). The Graph class has member variables to keep track of the predecessor vertex for every vertex (in the form of the predecessorList array) on the BFS tree rooted at the starting vertex. The code given for the BFS algorithm also updates the entries in the predecessorList array as part of the traversal. Your task in this project would be to use the results (like the entries in the predecessorList array) of running the BFS algorithm starting from vertex 0 and write an iterative or recursive function that would print the actual shortest paths (sequence of edges) from vertex 0 to the rest of the vertices in the graph. You could add the iterative or recursive function as part of the Graph class and access it from the main function. Your main function can also print the predecessor for every vertex in the BFS tree rooted at vertex 0, as shown in the sample output. A sample output (printing the predecessor entries and the shortest paths from vertex 0) for an example graph is shown below. inter the file name for the edges of the graph: graphEdges 2.txt ter number of nodes: 8 redecessor List Entries redecessor of -1 redecessor of 1 : 0 redecessor of 2 1 redecessor of 3 : 1 redecessor of 4:2 'ro deces or of 5 ; 3 redeceSDO of 6: 4 redecessor of 78 0 3 5 7 2) 4 Shortest Paths from Vertex 8 IELLIT&MBA H24 .. 1-2..??6

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database And Expert Systems Applications 19th International Conference Dexa 2008 Turin Italy September 2008 Proceedings Lncs 5181

Authors: Sourav S. Bhowmick ,Josef Kung ,Roland Wagner

2008th Edition

3540856536, 978-3540856535

More Books

Students also viewed these Databases questions

Question

Describe the job youd like to be doing five years from now.

Answered: 1 week ago

Question

So what disadvantages have you witnessed? (specific)

Answered: 1 week ago