function buildQueries(root) {
    var children = Object.keys(root).filter(notPathMapInternalKeys),
        child, memo, paths, key, childIsNum, list, head, tail, clone, results, i = -1,
        n = children.length,
        j, k, x;
    if (n === 0 || Array.isArray(root) === true) {
        return [
            []
        ];
    }
    memo = {};
    while (++i < n) {
        child = children[i];
        paths = buildQueries(root[child]);
        key = createKey(paths);
        childIsNum = typeof child === 'string' && !charPattern.test(child);
        if ((list = memo[key]) && (head = list.head)) {
            head[head.length] = childIsNum ? parseInt(child, 10) : child;
        } else {
            memo[key] = {
                head: [childIsNum ? parseInt(child, 10) : child],
                tail: paths
            };
        }
    }
    results = [];
    for (x in memo) {
        head = (list = memo[x]).head;
        tail = list.tail;
        i = -1;
        n = tail.length;
        while (++i < n) {
            list = tail[i];
            j = -1;
            k = list.length;
            if (head[0] === '') {
                clone = [];
            } else {
                clone = [head.length === 1 ? head[0] : head];
                while (++j < k) {
                    clone[j + 1] = list[j];
                }
            }
            results[results.length] = clone;
        }
    }
    return results;
}
Builds the set of collapsed
queries by traversing the tree
once