Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help with this JAVA program implement an editable graph data structure and a new algorithm for finding the topological sort of a graph. The

Please help with this JAVA program implement an editable graph data structure and a new algorithm for finding the topological sort of a graph. The goal will be to load two data files, and print out a topological order for the characters that they list. Attached to this post are a base file and two interfaces.

you will need to:

~Create a new class called BetterDiGraph that implements the EditableDiGraph interface. See the interface file for details.

~Create a new class called IntuitiveTopological that implements the TopologicalSort interface. Use BetterDiGraph to store the graph. Instead of using DFS to find a topological sort, implement the following algorithm: "IntuitiveTopological". This algorithm works as follows: look at your graph, pick out a node with in-degree zero, add it to the topological ordering, and remove it from the graph. This process repeats until the graph is empty. Make sure to check for cycles before trying to generate a topological

EDITABLEDIGRAPH interface

import java.util.NoSuchElementException;

/** * Implements an editable graph with sparse vertex support. */ public interface EditableDiGraph { /** * Adds an edge between two vertices, v and w. If vertices do not exist, * adds them first. * * @param v source vertex * @param w destination vertex */ void addEdge(int v, int w);

/** * Adds a vertex to the graph. Does not allow duplicate vertices. * * @param v vertex number */ void addVertex(int v);

/** * Returns the direct successors of a vertex v. * * @param v vertex * @return successors of v */ Iterable getAdj(int v); /** * Number of edges. * * @return edge count */ int getEdgeCount(); /** * Returns the in-degree of a vertex. * @param v vertex * @return in-degree. * @throws NoSuchElementException exception thrown if vertex does not exist. */ int getIndegree(int v) throws NoSuchElementException; /** * Returns number of vertices. * @return vertex count */ int getVertexCount(); /** * Removes edge from graph. If vertices do not exist, does not remove edge. * * @param v source vertex * @param w destination vertex */ void removeEdge(int v, int w);

/** * Removes vertex from graph. If vertex does not exist, does not try to * remove it. * * @param v vertex */ void removeVertex(int v);

/** * Returns iterable object containing all vertices in graph. * * @return iterable object of vertices */ Iterable vertices();

/** * Returns true if the graph contains at least one vertex. * * @return boolean */ boolean isEmpty(); /** * Returns true if the graph contains a specific vertex. * * @param v vertex * @return boolean */ boolean containsVertex(int v); }

TopicalSort interface

/** * Interface for classes providing a topological sort of a digraph. * */ public interface TopologicalSort { /** * Returns an iterable object containing a topological sort. * @return a topological sort. */ public Iterable order(); /** * Returns true if the graph being sorted is a DAG, false otherwise. * @return is graph a DAG */ public boolean isDAG(); }

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

Medical Image Databases

Authors: Stephen T.C. Wong

1st Edition

1461375398, 978-1461375395

Students also viewed these Databases questions

Question

Choose one of the challenges listed on page

Answered: 1 week ago

Question

explain what is meant by redundancy

Answered: 1 week ago