Question: 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 write using prolog prolog Write a predicate called insert(E, Tree, NewTree) that
prolog
is true if and only if the result of inserting element E

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. %

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!