Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please solve this question. This is related to recursion and induction. You may use 'base case', 'step case'. Thank you so much! EExercise 128. Let

Please solve this question. This is related to recursion and induction. You may use 'base case', 'step case'. Thank you so much!

image text in transcribed

EExercise 128. Let N be a set of numbers between N and R. Consider the function search: OFBTrees n x N + {0,1} that for an input consisting of a orderedl binary tree t with labels from N and an element n of N gives 1 if n occurs as a label in t, and 0 otherwise. (a) Give a recursive definition of search. We may think of this function as performing a binary search. (b) Write code that implements this function, assuming we have a class OBTree which restricts BTree to ordered binary trees only. (c) Draw a picture of the ordered binary tree tree-3(tree_5(tree 7, tree 4), tree5(tree 3, tree 7)). Imagine you want to add a node with label 4 to the tree. Where should that go? Draw your solution. Do you still have a full binary tree? (d) Write code that takes as inputs an object of the class OBTree and an integer and returns an object of class OBTree in which the second argument has been inserted if it is not already present. Use the previous part to guide you. Hint: Your definition should take advantage of the fact that the tree is ordered and not look at every label. EExercise 128. Let N be a set of numbers between N and R. Consider the function search: OFBTrees n x N + {0,1} that for an input consisting of a orderedl binary tree t with labels from N and an element n of N gives 1 if n occurs as a label in t, and 0 otherwise. (a) Give a recursive definition of search. We may think of this function as performing a binary search. (b) Write code that implements this function, assuming we have a class OBTree which restricts BTree to ordered binary trees only. (c) Draw a picture of the ordered binary tree tree-3(tree_5(tree 7, tree 4), tree5(tree 3, tree 7)). Imagine you want to add a node with label 4 to the tree. Where should that go? Draw your solution. Do you still have a full binary tree? (d) Write code that takes as inputs an object of the class OBTree and an integer and returns an object of class OBTree in which the second argument has been inserted if it is not already present. Use the previous part to guide you. Hint: Your definition should take advantage of the fact that the tree is ordered and not look at every label

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

Database Basics Computer EngineeringInformation Warehouse Basics From Science

Authors: Odiljon Jakbarov ,Anvarkhan Majidov

1st Edition

620675183X, 978-6206751830

More Books

Students also viewed these Databases questions

Question

What causes a partnership to dissolve?

Answered: 1 week ago

Question

Which are non projected Teaching aids in advance learning system?

Answered: 1 week ago