Given the following fuction in Java write a similiar function in Scheme: public
ID: 3693810 • Letter: G
Question
Given the following fuction in Java write a similiar function in Scheme:
public static boolean recursiveSplit(Node currentNode, int sumA, int sumB, int target){ // the recursive method that solves the problem
if (currentNode == null) return target == (sumA - sumB); // base case of recursion:
return( (recursiveSplit(currentNode.next, sumA + currentNode.data, sumB, target)) || //two recursive calls in which the current element is added to the first subset sum
(recursiveSplit(currentNode.next, sumA, sumB + currentNode.data, target))); // and to the second subset sum
}
The whole solution must be packed in one recursive function recursive-split which must look as follows:
(define recursive-split (lambda (<list L followed by parameters of your
choice initially set to zero>)
(cond
...
)))
Inside COND, you can use ONLY the following constructs:
null?
cond
car
cdr
else
+
–
=
#t
#f
recursive-split
the names of your parameters
numeric constants
parentheses
Explanation / Answer
Given below are the function in Scheme:
(define recursive-split
(lambda (currentNod sumA sumB target)
(cond
(if (null? currentNode)
(target == (sumA - sumB)
(else (cond
( (recursiveSplit(currentNode.next, sumA + currentNode.data, sumB, target)) || (recursiveSplit(currentNode.next, sumA, sumB + currentNode.data,target))))
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.