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

 In Prolog help me figure out what is wrong with this

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

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!