Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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.
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
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