SophiaPretty

(5)

$14/per page/Negotiable

About SophiaPretty

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Accounting,Algebra See all
Accounting,Algebra,Applied Sciences,Architecture and Design,Art & Design,Biology,Business & Finance,Calculus,Chemistry,Communications,Computer Science,Economics,Engineering,English,Environmental science,Essay writing Hide all
Teaching Since: Jul 2017
Last Sign in: 305 Weeks Ago, 1 Day Ago
Questions Answered: 15833
Tutorials Posted: 15827

Education

  • MBA,PHD, Juris Doctor
    Strayer,Devery,Harvard University
    Mar-1995 - Mar-2002

Experience

  • Manager Planning
    WalMart
    Mar-2001 - Feb-2009

Category > Computer Science Posted 12 Dec 2017 My Price 10.00

UnweightedDirectedGraph.java (file attached) as starter code

For this assignment, I need to modify the UnweightedDirectedGraph.java (file attached) as starter code and add a method to compute the in-degree and out-degree of each vertex in the graph. The in-degree of a vertex is the number of incoming edges to that vertex and the out-degree of a vertex is the number of outgoing edges from that vertex. 

Snip20170501_77.png

For example, in the directed graph attached below, The in-degree of vertex H is 3 (because there are three incoming edges to node H ) and out-degree of vertex H is 1 ( because there is only one outgoing edge from vertex H). Similarly, the in-degree of node A is 0 and its out-degree is 3. 

 

I'm attaching

  • Degree.java : This is a class with two integer attributes: in-degree and out-degree used to store the in-degree and out-degree of a vertex, respectively.
  • UnweightedDirectedGraph.java : This is a minimal code for an unweighted directed graph. The only attribute of this class is “adjacencyList” which is a hashMap<LinkedList<V>> where V is a parametric type for vertices in graph. For each vertex in the graph, the adjacencyList stores all the outgoing edges from that vertex. Please refer to the lectures and the practice problem in module 12 for more details on this adjacency list. The class also has an addEdge method which allows you to construct a graph by adding edges to it. 

 

I need help implementing:

  1. public Map<V, Degree> findInOutDegrees() : This method should return a Degree object for each vertex in the graph. The return type is a Map of <vertex, Degree>where the ley is a vertex in graph and value is a Degree object containing the in-degree and out- degree for that vertex. 
  2. An explanation of the efficiency of the method in terms of |E| the number of edges in the graph, or |V| the number of vertices in graph. 

  • /**
     * The class to store the number of incoming edges (indegree) to a vertex and the number of outgoign edges (outdegree) from a vertex
     * @author esahe2
     *
     * @param <V>
     */
    public class Degree {
       
       
        //Number off incoming edges to a vertex
        int indegree;
       
        //number of outgoing edges from a vertex
        int outdegree;
       
        //Constructor
        public Degree ( int indegree, int outdegree){
           
            this.indegree= indegree;
            this.outdegree= outdegree;
        }

       
        //Getter and Setter MNethods

        public int getIndegree() {
            return indegree;
        }

        public void setIndegree(int indegree) {
            this.indegree = indegree;
        }

        public int getOutdegree() {
            return outdegree;
        }

        public void setOutdegree(int outdegree) {
            this.outdegree = outdegree;
        }
       
       
    /**
     * A class representing a directed unweighted graph using Adjacency list
     */
    import java.util.*;
    import java.io.*;
    /**
     *
     * @author esahe2
     *
     * @param <V> is the generic type for vertices in graph
     */
    class UnweightedGraph<V>
    {
        //A HashMap of lists for Adjacency list representation. Key is a source vertex and
        //value is a list of outgoing edges (i.e., destination vertices) for the key
        private HashMap<V,LinkedList<V>> adj;
       
        public UnweightedGraph()
        {
            adj = new HashMap<V,LinkedList<V>>();
        }
       
        /**
         * A function to add an edge
         * @param source : The source of the edge
         * @param dest: The destination of the edge
         */
       
        public void addEdge(V source, V dest)
        {
            LinkedList<V> edgeList = adj.get(source);
            if (edgeList==null)
                edgeList = new LinkedList<V>();
           
            edgeList.add(dest);
            adj.put(source, edgeList);
        }
       
       
       
       
       
    //TO DO   
       
    /**
     * Computes the in-degree and outDegree for each vertex in the graph
     * @returns a dictionary which maps every vertex to its Degree object containing the in-degree and out-degreeo of the vertex
     */
    public Map<V, Degree> findInOutDegrees()
    {
        // TO DO : YOUR IMPLEMENTATION GOES HERE
       
    }
       


    }
    }

Attachments:

Answers

(5)
Status NEW Posted 12 Dec 2017 12:12 PM My Price 10.00

-----------  ----------- H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly

Not Rated(0)