Question: DO PLEASE, use C programming, C Programming, C programming Question 4: Lowest Common Ancestor (Bonus 10%) You are given a general tree. You are asked
DO PLEASE, use C programming, C Programming, C programming
Question 4: Lowest Common Ancestor (Bonus 10%) You are given a general tree. You are asked to identify the lowest common ancestor of two nodes. All nodes only contain a unique number ranging from 0 to 200. Your program should read the input from the file, and output the answer to another file. The first argument is the input file name, while the second argument is the output file name. Name your program as lab5-94.c". Input file: First line, an integer N, indicating the number of nodes in the tree. Following n - 1 lines, pn, two integers, node p is the parent of node n. The p in line 2 is the root of the tree. Last line, a b, two integers, find the lowest common ancestor of node a and node b. Output file: An integer, I, indicates the lowest common ancestor of node a and node b. Sample Input: 2 0 1 0 1 Sample Output: 0
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
