Question: Scheme Programming Language You may define extra functions if needed. Write your sample programs, and the results of interpreter output of sample executions. A binary
Scheme Programming Language You may define extra functions if needed. Write your sample programs, and the results of interpreter output of sample executions.
A binary search tree is a rooted search tree, whose internal nodes store a value, and two subtrees, namely l?ft subtree and right subtree The key invariant of a binary search tree is that for every node, all the values in the left subtree are smaller than or equal to the value, and all of the values in the right subtree are larger than the value That structure can be implemented in Scheme using a three-element list: first element stores the value, second stores the left tree and third stores the right tree Write a Scheme function called insert-bst, that takes a number to be inserted, and a valid binary search tree. The result of the function should be the binary search tree with item inserted. Sample runs > (insert-bst 8) > (insert-bst 5(8 (O)) (8 (5 O) O) > (insert-bst 4 (8 (5 ) )) > (insert-bst 4 (insert-bst 5 (insert-bst 8 ))) > (insert-bst 7 (insert-bst 4 (insert-bst 5 (insert-bst 8 )))) 8 8 5 5 4 4 7 A binary search tree is a rooted search tree, whose internal nodes store a value, and two subtrees, namely l?ft subtree and right subtree The key invariant of a binary search tree is that for every node, all the values in the left subtree are smaller than or equal to the value, and all of the values in the right subtree are larger than the value That structure can be implemented in Scheme using a three-element list: first element stores the value, second stores the left tree and third stores the right tree Write a Scheme function called insert-bst, that takes a number to be inserted, and a valid binary search tree. The result of the function should be the binary search tree with item inserted. Sample runs > (insert-bst 8) > (insert-bst 5(8 (O)) (8 (5 O) O) > (insert-bst 4 (8 (5 ) )) > (insert-bst 4 (insert-bst 5 (insert-bst 8 ))) > (insert-bst 7 (insert-bst 4 (insert-bst 5 (insert-bst 8 )))) 8 8 5 5 4 4 7
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
