Chat with us, powered by LiveChat Your assignment is to create a graph using an adjacency list and use the above example to populate the list. - EssayAbode

Your assignment is to create a graph using an adjacency list and use the above example to populate the list.

Task 1 Undirected Graph

In the lecture material the following undirected graph was given as an example:

Undirected Graph as an Adjacency List

This type of graph can be represented through the use an adjacency list:

Adjacency Map Depicted

An adjacency list as you can see is nothing more than an array of linked lists. One of the problems faced when creating such a list is to decide where each city belongs in the array. The obvious choice here is to use a hash function to place the initial cities.

Your assignment is to create a graph using an adjacency list and use the above example to populate the list. What this means is that you should be able to create the list by hashing the initial city to determine the location within the array it will be located.

NOTE:

Please note that your assignment MUST be constructed as follows

Graph with Adjacency List

Given the above graph you should create an Adjacency list where the vertex list is constructed as an array and the adjacency list is constructed as a linked list. You must use a linked list that you created in this class. The linked list must be its own class. This means you should not bury any graph code into the linked list. At a minimum your project should have the following two classes

  1. LinkedList
  2. Graph

Your Graph class must be a public class and has the following functionality:

Graph() – Default constructor that sets the size of the vertex list to 53

Graph(int size) – Overloaded constructor that sets the size of the vertex list to the size passed to it

void insert(string city) – Inserts a city into the graph. It might be a good idea to create a value that marks the end of the each adjacency list. Something like graph.insert(“END”); This would signal to start the next adjacency list.

void dfs(int start) – The index of the vertex list to start a depth first traversal. This function will print out all items in the graph.

void dfs(string start) – The name of the city to start the depth first traversal on. This function will print out all items in the graph

void dfs() – Begin a depth first traversal on the first city in the vertex list . This function will print out all items in the graph.

You must use a hash function to position your first city in the vertex list. You can use any hash function you wish.

Task 2 – Depth First Traversal

In addition to creating the graph you are required to write a depth-first traversal algorithm that will visit each node and print out the city it visited.

A depth first traversal of a graph is very similar to a depth first traversal of a tree. The difference is that graphs may contains cycles so you must keep track of what has been visited so that you do not consider nodes more than one time. One of the strategies for this is to use a Boolean array where you mark true when a node is visited. This can also be accomplished by adding a visited field to the node definition.

Required: You must have a recursive solution to solve the depth first traversal problem here.

Related Tags

Academic APA Assignment Business Capstone College Conclusion Course Day Discussion Double Spaced Essay English Finance General Graduate History Information Justify Literature Management Market Masters Math Minimum MLA Nursing Organizational Outline Pages Paper Presentation Questions Questionnaire Reference Response Response School Subject Slides Sources Student Support Times New Roman Title Topics Word Write Writing