public void buildpath(final String start, final String end, final HashMap<String, ArrayList<String>> map, final ArrayList<String> tmparray, final ArrayList<ArrayList<String>> res) {
        // tracing back from the end word, because start word doesn't have a prev
        final ArrayList<String> pre = map.get(end);
        if (end.equals(start)) {
            final ArrayList<String> tmparray2 = new ArrayList<String>(tmparray);
            Collections.reverse(tmparray2);
            res.add(tmparray2);
            // return;
        }
        for (final String s : pre) {
            tmparray.add(s);
            buildpath(start, s, map, tmparray, res);
            // clear elements in the list; so that next time there will be the next group of words
            tmparray.remove(tmparray.size() - 1);
        }

    }