def dfs(labels, graph, start, index):
    """ Depth first search using stack
        Give same label index for every node in a tree

    Input
    ______
    labels: array for labels of each samples in cluster
    graph: 2-D matrix for graph
    start: initial point in a tree. DFS will search the tree includes this point
    index: label index for nodes

    Output
    ______
    labels : modified array which records the cluster label for the points in the tree
    """
    visited = []
    stack = [start]

    while stack:
        n = stack.pop()
        if n not in visited and labels[n] == -1:
            visited.append(n)
            labels[n] = index
            stack += set(graph[n]) - set(visited)

    return labels