Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Ethan is a town librarian. The library administration has completely left the book allocation to himself. Ethan places each book in the library with a
Ethan is a town librarian. The library administration has completely left the book allocation to himself. Ethan places each book in the library with a binary search tree structure. The books are placed in the library completely mixed, but behind each book there is own book id and the location of the other two books that one has smaller id and other one has bigger id. Location of first book (root) is known by librarian. People of the town have a habit. They always ask for two books. Because of that, Ethan wants to help them with finding the smallest subtree that has two of the books that person asks for. Ethan tells root id of the subtree to the people for helping them. For example, in the below figure yellow nodes are the books that are asked. Red node is root book of the library. Blue node is the root of the smallest subtree that have two yellow nodes. Blue node is the answer that Ethan search for. For that, you need to help Ethan for solving this problem. Root 10 12 9 11 2 5 8 3 6 Desired structure for helping Ethan has some requirements. Book node (struct) is expected to keep these variables: . Integer as an id Address of the bigger id book node Address of the smaller id book node Library class is expected to keep these variables: . Address of the root node Library class desired methods: . . insert clear int subtreeRootIDSearch(Book Node * book, int idi, int id2) => for finding ID of the smallest subtree root. (Initial BookNode => root) Driver class also has one desired method: main function
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