Question: Complete the Prolog program below that processes a binary tree replacing all keys in nodes with a value of 0 with a value of 1.

Complete the Prolog program below that processes a binary tree replacing all keys in nodes with a value of 0 with a value of 1.

 zeroNodes(nil,_______________________) :- !. zeroNodes(t(0,L,R),________________________) :- zeroNodes(L,___________________), zeroNodes(R,___________________), !. zeroNodes(t(Key,L,R),________________________) :- zeroNodes(L,___________________), zeroNodes(R,___________________). 

Examples:

?- zeroNodes(t(0,nil,nil),T). T = t(1, nil, nil). ?- zeroNodes(t(0,t(3,nil,t(0,nil,nil)),t(3,nil,nil)),T). T = t(1, t(3, nil, t(1, nil, nil)), t(3, nil, nil)). 

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!