Answered step by step
Verified Expert Solution
Question
00
1 Approved Answer
write using prolog prolog Write a predicate called insert(E, Tree, NewTree) that is true if and only if the result of inserting element E into
write using prolog prolog Write a predicate called insert(E, Tree, NewTree) that is true if and only if the result of inserting element E into the binary search tree Tree results in the new binary search tree NewTree. Trees are represented in [Root, Left, Right] format as described above and insertion is the standard binary tree insertion that inserts a new element at a leaf in the location that preserves the binary search tree property. (Thankfully, we're reasoning here about standard binary search trees, not red-black trees, splay trees, etc.!) Here is an example (but test your code on other inputs too). ?- tree (T), insert(200, T, New). T = [42, (5, 0, 0], [47, [], [50, 0], []]], New = [42, (5, [], []], [47, [], [50, (), [......]]]] [write] HERE, PROLOG IS SHOWING ... PRESS THE W KEY TO SEE IT ALL! T = [42, (5, [], [], [47, [], [50, (), []]]], New = [42, (5, [], []], [47, [], [50, [], [200, [], []]]]] %% BASE CASE - STARTER CODE %%%%%%%%%%%%%%%%%%%%%%%%%%% insert(E, [], [E, U . ( ). %% YOUR TURN! insert(E, [Root, Left, Right], [Root, NewLeft, Right]) :- fail. %
write using prolog
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered 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