Question

Hello, I'd like someone to help me create these, thanks! 1. Type Vertex Create and document...

Hello, I'd like someone to help me create these, thanks!

1. Type Vertex

Create and document type Vertex. Each vertex v has the following pieces of information.

A pointer to a linked list of edges listing all edges that are incident on v. This list is called an adjacency list.

A real number indicating v's shortest distance from the start vertex. This number is −1 if the distance is not yet known.

A vertex number u. The shortest path from v to the start vertex begins by going from v to u. If the shortest path is not known, u is −1.

Create a constructor for type Vertex that takes no parameters and sets the vertex number and distance to −1 and the linked list to NULL.

2. Type Edge

Create and document type Edge. Type Edge is used for a cell in an adjacency list. The Edge structure stores three things.

A vertex number u.

A weight w.

A pointer next that points to the next Edge in the linked list.

Create a constructor that takes three parameters (a vertex number, a weight and a next pointer) and installs them into the three fields.

If a cell with vertex u and weight w occurs in the adjacency list for vertex v, then the graph has an edge from v to u of weight w.

Important note. An edge between u and v must occur in two adjacency lists, the list for u and the list for v, since it can be used to go from u to v or from v to u.

3. Type Graph

Create and document type Graph. A graph stores the following.

The number of vertices.

The number of edges.

An array, vertices, where vertices[v] is a Vertex structure giving information about vertex v.

Create a contructor for Graph that takes a number of vertices as a parameter. It should allocate an array for the vertices and set the number of edges to 0. Notice that it is not necessary to have a maximum number of vertices. You allocate the array after you know how many vertices there are.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

I am assuming from some terms in the question, that the problem needs to be done in C++. Following is the code:

#include <iostream>
using namespace std;

struct Edge{
   int vertexNumber;
   int weight;
   struct Edge* next;
   Edge( int vn, int wgt, struct Edge* nxt ){
       vertexNumber = vn;
       weight = wgt;
       next = nxt;
   };
};

struct Vertex{
   struct Edge* adjacencyList;
   double shortestDistance;
   int vertexNumber;
   Vertex(){
       vertexNumber = shortestDistance = -1;
       adjacencyList = NULL;
   }
};

struct Graph{
   int nVertices;
   int nEdges;
   struct Vertex* vertices;
   Graph( int nVert ){
       vertices = new struct Vertex[nVert];
       nEdges = 0;
   }
};

typedef struct Edge Edge;
typedef struct Vertex Vertex;
typedef struct Graph Graph;

int main(){

}

Add a comment
Know the answer?
Add Answer to:
Hello, I'd like someone to help me create these, thanks! 1. Type Vertex Create and document...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 3. The indegree of a vertex u is the number of incoming edges into u, .e, edges of the form (v,u)...

    3. The indegree of a vertex u is the number of incoming edges into u, .e, edges of the form (v,u) for some vertex v Consider the following algorithm that takes the adjacency list Alvi, v2, n] of a directed graph G as input and outputs an array containing all indegrees. An adjacency list Alvi, v.. /n] is an array indexed by the vertices in the graph. Each entry Alv, contains the list of neighbors of v) procedure Indegree(Alvi, v2,......

  • (5 marks) a. The pseudo-code for breadth-first search, modified slightly from Drozdek,1 is as follows: void...

    (5 marks) a. The pseudo-code for breadth-first search, modified slightly from Drozdek,1 is as follows: void breadthFirstSearch (vertex w) for all vertices u num (u) 0 null edges i=1; num (w) i++ enqueue (w) while queue is not empty dequeue ( V= for all vertices u adjacent to v if num(u) is 0 num (u) = i++; enqueue (u) attach edge (vu) to edges; output edges; Now consider the following graph. Give the breadth-first traversal of the graph, starting from...

  • Exercise 1 Adjacency Matrix In this part, you will implement the data model to represent a graph. Implement the followi...

    Exercise 1 Adjacency Matrix In this part, you will implement the data model to represent a graph. Implement the following classes Node.java: This class represents a vertex in the graph. It has only a single instance variable of type int which is set in the constructor. Implement hashCode() and equals(..) methods which are both based on the number instance variable Node - int number +Node(int number); +int getNumberO; +int hashCode() +boolean equals(Object o) +String toString0) Edge.java: This class represents a...

  • Exam 3 Sample.pdf * ) Q © w E © 112 A n o 99.9% 1....

    Exam 3 Sample.pdf * ) Q © w E © 112 A n o 99.9% 1. Breadth-first Search a) List out the following graph using adjacency list. Assume the adjacency lists are in sorted order, e.g. when exploring vertex F, the algorithm considers the edge F-B before F-C, F-E, F-H or F-I. b) Run breadth-first-search on the graph below, starting at vertex A. List the vertices in the order in which the vertices are enqueued on the FIFO queue. c)...

  • Below is the Graph file that needs to be modified(using Python3) : #!/usr/bin/python3 # Simple Vertex...

    Below is the Graph file that needs to be modified(using Python3) : #!/usr/bin/python3 # Simple Vertex class class Vertex: """ Lightweight vertex structure for a graph. Vertices can have the following labels: UNEXPLORED VISITED Assuming the element of a vertex is string type """ __slots__ = '_element', '_label' def __init__(self, element, label="UNEXPLORED"): """ Constructor. """ self._element = element self._label = label def element(self): """ Return element associated with this vertex. """ return self._element def getLabel(self): """ Get label assigned to...

  • Show the operation of depth-first search (DFS) on the graph of Figure 1 starting from vertex...

    Show the operation of depth-first search (DFS) on the graph of Figure 1 starting from vertex q. Always process vertices in alphabetical order. Show the discovery and finish times for each vertex, and the classification of each edge. (b) A depth-first forest classifies the edges of a graph into tree, back, forward, and cross edges. A breadth-first search (BFS) tree can also be used to classify the edges reachable from the source of the search into the same four categories....

  • in c++ The Bellman-Ford Algorithm In this assignment, you are asked to implement the Bellman-Ford Algorithm...

    in c++ The Bellman-Ford Algorithm In this assignment, you are asked to implement the Bellman-Ford Algorithm which solves the single-source shortest-paths problem. Specifically, you are given as input a directed graph G = (V. E) with weight w(u, v) on each edge (u, v) E E along with a source vertex s EV. Edges may have negative weights. Input The input has the following format. There are two integers on the first line. The first integer represents the number of...

  • please help me make this into a contradiction or a direct proof please. i put the question, my answer, and the textbook i used. thank you also please write neatly proof 2.5 Prove har a Sim...

    please help me make this into a contradiction or a direct proof please. i put the question, my answer, and the textbook i used. thank you also please write neatly proof 2.5 Prove har a Simple sraph and 13 cdges cannot be bipartite CHint ercattne gr apn in to ertex Sets and Court tne忤of edges Claim Splitting the graph into two vertex, Sets ves you a 8 Ver ices So if we Change tne书 apn and an A bipartite graph...

  • In this question, we will think about how to answer shortest path problems where we have more than just a single sourc...

    In this question, we will think about how to answer shortest path problems where we have more than just a single source and destination. Answer each of the following in English (not code or pseudocode). Each subpart requires at most a few sentences to answer. Answers significantly longer than required will not receive full credit You are in charge of routing ambulances to emergency calls. You have k ambulances in your fleet that are parked at different locations, and you...

  • Use the example Graph.javaPreview the document class and Edge.javaPreview the document class as a starting point...

    Use the example Graph.javaPreview the document class and Edge.javaPreview the document class as a starting point for this assignment, you'll need to make your own main class to create an instance of the Graph class. For this assignment we are going to create a map of a city subway system using a Graph data structure. The Metro Station Map that you'll use for this assignment is here: Assignment 9 - Metro Station Map.PNG Enter all the information from the Metro...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT