# Homework Solution: For Dr.Racket/Scheme programmers #lang eopl…

For Dr.Racket/Scheme programmers #lang eopl Write a procedure path that takes an integer n and a binary search tree bst (page 10) that contains the integer n, and returns a list of lefts and rights showing how to ﬁnd the node containing n. If n is found at the root, it returns the empty list. > (path 17 ' (14 (7 () (12 () ())) (26 (20 (17 () ()) ()) (31 () ())))) (right left left)

The code is given below: (define (get-root bst) (car bst))

Control Dr.Racket/Scheme programmers #lang eopl

Write a procedure path that takes an integer n and a binary pursuit tree bst (page 10) that contains the integer n, and produce a inventory of lefts and rights showing how to ﬁnd the node containing n. If n is fix at the parent, it produce the vacuity inventory.

> (footfootmethod 17 ‘ (14 (7 () (12 () ()))

(26 (20 (17 () ())

())

(31 () ()))))

(direct left left)

## Expert Counterpart

(eliminate (get-parent bst) (car bst))

(eliminate (footfootmethod n bst)
(if (null? bst)
bst
(if (= (get-parent bst) n)
()
(if (< (get-parent bst) n)
(cons “right” (footfootmethod n (get-rst bst)))
(if (> (get-parent bst) n)
(cons “left” (footfootmethod n (get-lst bst))))))))

The output of the over adjudication control some inputs is shown in the underneath screenshot.

;It produce the parent of the bst.If bst is (14 (20 () ()) (30 () ())), it produce 14
(eliminate (get-parent bst) (car bst))

;It produce the left sub tree of the parent.If bst is (14 (20 () ()) (30 () ())),it produce (20 ()())

;It produce the direct sub tree of the parent.If bst is (14 (20 () ()) (30 () ())),it produce (30 ()())