Answered step by step
Verified Expert Solution
Link Copied!

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 image text in transcribed
prolog
image text in transcribed
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

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions