Check if path exists directed graph, without using collection I have written code to find whether the path exists between source and destination in a directed graph. I have used BFS and instead of ArrayList or queue. I have written my own helper class.

Please let me know how the code can be improved.

public class Graph {

    private int numVertex;
    // Helper class, which can act like Adjacency List or Queue for BFS search.
    private HelperClass[] adjList;

    public Graph(int n) {
        numVertex = n;
        adjList = new HelperClass[n];
        for (int i = 0; i &lt; n; i++) {
            adjList[i] = new HelperClass();
        }
    }

    public void setAdjacencyList(HelperClass[] adjList) {
        this.adjList = adjList;

    }

    // Assuming that source and destination will be in the range of vertices.
    public boolean isPathExists(int source, int destination) {
        if (source == destination)
            return true;
        // else do BFS until the destination is found or all the nodes are
        // visited.
        HelperClass hc = new HelperClass();
        boolean[] isVisited = new boolean[numVertex];
        hc.add(source);
        isVisited[source] = true;
        while (!hc.isEmpty()) {
            int current = hc.poll();
            if (current == destination) {
                return true;
            }
            int leftIndex = adjList[current].first;
            int rightIndex = adjList[current].last;
            while (leftIndex &lt; rightIndex) {
                int temp = adjList[current].array[leftIndex++];
                if (!isVisited[temp]) {
                    hc.add(temp);
                }

            }
        }
        return false;
    }

    public static class HelperClass {
        // assuming the maximum array size will not be more than 10000.
        int[] array = new int[10000];
        int first = 0;
        int last = 0;

        public void add(int x) {
            array[last++] = x;
        }

        public int poll() {
            if (!isEmpty()) {
                return array[first++];
            } else {
                return -1;
            }
        }

        public boolean isEmpty() {
            return first == last ? true : false;
        }

    }

}
Performance

HelperClass used a fix amount memory, due to the predetermined array size. This looks like a waste. 

Single responsibility principle

HelperClass is used in 2 different ways:


As a queue, that can grow at its end and shrink at its beginning
As an array to store the neighbors of each vertex


I suspect this dual use has lead to the terrible meaningless name of this class.

Instead of doing different things, it's recommended to design classes that do one thing and do it well. This is called the single responsibility principle, one of the first crucial considerations when creating a new class.

If you want to write your own queue, that's fine, but focus on its most important responsibility, which is efficient push, poll, isEmpty operations.

When your class has a single responsibility, naming becomes easier too, often obvious.

For the storage of neighbors, it's unclear what you really need. You haven't shared how they are initialized, so it's impossible to comment on that. A fixed array might be good enough, who knows.

Pointless Graph constructor

The constructor initializes the vertices empty, with no neighbors. That seems rather useless. Perhaps you want to move the functionality of the setAdjacencyList method inside the constructor.