Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In Prolog help me figure out what is wrong with this delete predicate . The getMin function is working so i dont know why this

image text in transcribed

In Prolog help me figure out what is wrong with this delete predicate . The getMin function is working so i dont know why this is having issues.

\% delete/3: a predicate to delete an integer from a binary search tree \% Delete function to remove a node from a binary search tree. delete(nil, _, nil). delete(tree(X,nil,nil),X, nil). delete(tree( X, Left, nil), X, Left). delete(tree( X, nil, Right), X, Right). delete(tree(X, Left, Right), X, tree(Pred, NewLeft, RightNew)) :- getMin(Right, Pred), delete(Right, Pred, RightNew), replaceRoot(X, Pred, Left, NewLeft). delete(tree(X, Left, Right), Y, tree( X, NewLeft, Right)) :- YX,Y, delete(Right, Y, NewRight). replaceRoot(X, Y,tree(X, Left, Right), tree(Y, NewLeft, Right)) :- delete(Left, Y, NewLeft). replaceRoot(X, Y, tree( X, Left, Right), tree(Y, Left, NewRight)) :- delete(Right, Y, NewRight). \% treeRead/2: a predicate to read a binary search tree from a file treeFromList ([], nil). treeFromList ([X], tree (X, nil, nil )). treeFromList ([XXss], Tree) :- treefromList(Xs, T), insert(T,X, Tree ). treeRead(FileName, Tree) :- open(FileName, read, Stream), read_line_to_codes(Stream, Codes), atom_codes(Atom, Codes), 15 OUTPUT TERMINAL DEBUG CONSOLE g: Singleton variables: [X] delete(tree(5, tree(3, tree(1, nil, nil), tree(4, nil, nil)), tree(7, nil, nil)), 3, NewTree). [p5.pl] delete(tree(5, tree(3, tree(1, nil, nil), tree(4, nil, nil)), tree(7, nil, nil)), 3, NewTree)

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_2

Step: 3

blur-text-image_3

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

Understanding Oracle APEX 5 Application Development

Authors: Edward Sciore

2nd Edition

1484209893, 9781484209899

More Books

Students also viewed these Databases questions