Detecting a route between two nodes in a directed graph.

This problem is about finding a route between two nodes in a directed graph. An example input and output is given.

Problem

Given a directed graph, design an algorithm to find out whether there is a route between two nodes.
Example input: 
A -> B
B -> C
A -> C
Example output: 
There is a route between A and C.

Solution

This solution is in C#. Our A.I. can create solutions in multiple languages.
by kayakane
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace InterviewQuestions
{
    class Graph
    {
        public List<Node> Nodes { get; set; }

        public Graph()
        {
            Nodes = new List<Node>();
        }

        public void AddNode(Node node)
        {
            Nodes.Add(node);
        }

        public void AddEdge(Node from, Node to)
        {
            from.Edges.Add(to);
        }

        public bool IsRoute(Node from, Node to)
        {
            //BFS
            Queue<Node> queue = new Queue<Node>();
            queue.Enqueue(from);
            while (queue.Count > 0)
            {
                Node current = queue.Dequeue();
                if (current == to)
                {
                    return true;
                }
                foreach (Node edge in current.Edges)
                {
                    queue.Enqueue( edge);
                }
            }
            return false;
        }
    }

    class Node
    {
        public List<Node> Edges { get; set; }

        public Node()
        {
            Edges = new List<Node>();
        }
    }
}

A.I. Evaluation of the Solution

The candidate's solution is correct and demonstrates a level of completeness. The candidate has correctly implemented a breadth-first search algorithm to find a route between two nodes in a graph. The candidate's approach is sound.

Evaluated at: 2022-11-24 04:16:02