Here is my current understanding of what's confusing you:
- In order to reduce RMQ to LCA, you need to convert the array into a tree and then do an Euler tour of that tree.
- In order to do an Euler tour, you need to store the tree such that each node points at its children.
- The reduction that is listed from RMQ to LCA has each node point to its parent, not its children.
If this is the case, your concerns are totally justified, but there's an easy way to fix this. Specifically, once you have the array of all the parent pointers, you can convert it to a tree where each node points to its children in O(n) time. The idea is the following:
- Create an array of n nodes. Each node has a value field, a left child, and a right child.
- Initially, set the nth node to have a null left child, null right child, and the value of the nth element from the array.
- Iterate across the T array (where T[n] is the parent index of n) and do the following:
- If T[n] = *, then the nth entry is the root. You can store this for later use.
- Otherwise, if T[n] < n, then you know that node n must be a right child of its parent, which is stored at position T[n]. So set the T[n]th node's right child to be the nth node.
- Otherwise, if T[n] > n, then you know that node n must be a left child of its parent, which is stored at position T[n]. So set the T[n]th node's left child to be the nth node.
This runs in time O(n), since each node is processed exactly once.
Once this is done, you've explicitly constructed the tree structure that you need and have a pointer to the root. From there, it should be reasonably straightforward to proceed with the rest of the algorithm.
Hope this helps!