Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

How is it possible to print from a leaf node to an Ancestor root node? Problem 2 Definition: A Lowest Common Ancestor (LCA) of two

image text in transcribed

How is it possible to print from a leaf node to an Ancestor root node?

Problem 2 Definition: A Lowest Common Ancestor (LCA) of two node (given by the keys akey1 and akey2) is the node that occurs in the path from the root to the node with the key akey1 and that also occurs in the path from the root to the node with the key akey2. Moreover, LCA is the deepest such node (as far from the root as possible) For example, on Figure to the left, given two keys, ma and no, the key mo occurs on the path from the root to ma and from the root to no, and it is the farthest from the root (the keys lo and pl also occur 2on both paths, but they are not the deepest such be nodes) to ma mq no Assignment: You need to write a recursive member function (or a few functions) that accomplishes this goal: given two keys akey1 and akey2, it will print out the nodes on the path from akey1 to their LCA and the nodes in the path from akey2 to their LCA. You must to write this public member function (with exact header as shown below) void printPathsLCA(string akey1, string akey2) You may write as many functions as you need to accomplish this task, but these functions must be called from the printPathsLCA function. You must accomplish this task in O(logn)-time. This means that all functions that you will write must run in O(logn)-time. If your program runs in asymptotically larger time, you will not receive any credit. Given: Two strings akey1 and akey2 Output: Use cout to print out all the keys on two paths. Format of the output Output a space after each key; At the end of each path, output endl - Example Given a tree shown on Figure to the left, and two keys re and mq, your program will print out these two lines re sp pl mq mu mo pl 2 The path from the first key re to their LCA pl is re sp pl The path from the second key mq to their LCA is mo emq mu mo pl To test your program: use files t19.in and t19.out /run t19.my diff t19.my tests/t19.out no

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Logidata+ Deductive Databases With Complex Objects Lncs 701

Authors: Paolo Atzeni

1st Edition

354056974X, 978-3540569749

More Books

Students also viewed these Databases questions

Question

2. Develop a persuasive topic and thesis

Answered: 1 week ago

Question

1. Define the goals of persuasive speaking

Answered: 1 week ago