Write Method Return Nodes Vertices Graph Given Vertex Return Neighbors Specified Vertex Im Q37130167

Write a method to return the nodes(vertices) in the graph. Givena vertex return the neighbors of that specified vertex andimplement iterative pseudocode to traverse the graph using DFSalgorithm. (language= c#). Answer please.


Solution


====

This is the graph on which the program is tested

====

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace ConsoleApplication2
{
class Program
{

public static void Main(string[] args)
{
// Create a graph given in the above diagram
var g = new Graph();

//1 and 2 represent edge connecting node 2 from node 1
g.AddEdge(1, 2);
g.AddEdge(1, 3);
g.AddEdge(1, 4);

g.AddEdge(2, 5);
g.AddEdge(2, 6);
g.AddEdge(4, 7);
g.AddEdge(4, 8);

g.AddEdge(5, 9);
g.AddEdge(5, 10);
g.AddEdge(7, 11);
g.AddEdge(7, 12);
g.AddEdge(8, 13);

Console.WriteLine(“Following is Depth First Traversal (startingfrom node 1)”);
g.DFS(1);

//find adjacent node

OR
OR

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.