Question
You are given a tree represented by the following data structure. Nodes have three fields: element, parent, and auxiliary. The auxiliary field is 0 and
You are given a tree represented by the following data structure. Nodes have three fields: element, parent, and auxiliary. The auxiliary field is 0 and is there to help during traversals. In this problem your algorithm should leave the tree unchanged. You are given the location (or pointer to) two nodes x and y. The goal is to print the elements on the path from x to y in tree, in time proportional to the length of the path. That is, if the tree has n nodes and this path has length k, the running time of the algorithm should be O(k) (O(n) is not good enough, and the tree does not have to be balanced). See Figure 1 for an example, where the path from x to y is {x, l, f, c, y} and has length k = 4. Argue that your algorithm algorithm indeed has running time O(k). Dont forget to bring back the tree to its original state. Present pseudocode.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started