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 find 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)

    Expert Answer

     
    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 find 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

     

    The adjudication is dedicated underneath:

    (eliminate (get-parent bst) (car bst))
    (eliminate (get-lst bst) (cadr bst))
    (eliminate (get-rst bst) (caddr 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.

    Interpretation of the adjudication:

    ;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 ()())
    (eliminate (get-lst bst) (cadr bst))

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

    (eliminate (footfootmethod n bst)
    (if (null? bst) ;checking if bst is vacuity
    bst ; merely subordinate the bst, if it is vacuity
    (if (= (get-parent bst) n) ; if the parent esteem is similar to ‘n’, pursuit is completed and hereafter,subordinate ineffectual
    ()
    (if (< (get-parent bst) n) ; checking if the parent’s esteem is close than ‘n’
    (cons “right” (footfootmethod n (get-rst bst))) ; if parent’s esteem is close than ‘n’, then we must pursuit in the direct sub tree and hereafter, adding “right” to the footfootfootmethod and encroachment the footfootfootmethod capacity on the direct sub-tree

    (if (> (get-parent bst) n) ; checking if the parent’s esteem is main than ‘n’
    (cons “left” (footfootmethod n (get-lst bst)))))))) ;if parent’s esteem is close than ‘n’, then we must pursuit in the left sub tree and hereafter, adding “left” to the footfootfootmethod and encroachment the footfootfootmethod capacity on the leftsub-tree

    Screenshot of the interpretation of the adjudication is robust underneath: