a06sol-cs135-w10

a06sol-cs135-w10 - F: Cfiiab EEELGIHLIC b HHLUTiUHE WiHTLi...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: F: Cfiiab EEELGIHLIC b HHLUTiUHE WiHTLi Iflil ;: JHEJ LUSJHAH ;: fifibfliiflfi ; ere 2: beL.rk; .'I.'. (define—etruet nede (key value left rigbt}} (define tree—2 (make—node 2 "b" empty empty}} (define tree—12 (make—nede 2 "b" (make—nede l "a" empty empty} empty}} (define tree—23 (make—nede 2 "b" empty (make—nede 3 "e" empty empty}}} (define tree—123 (make—nede 2 "b" (make—nede l "a" empty empty} (make—nede 3 "e" empty empty}}} F: a ui—Ena; : LEE; lien} El :_5 J -} ibfif ;: eeee the given eey and yeite Le the g_yen URL. .II r _'_~::.": (ebeek—eepeet (add—bet empty 2 "b"} tree—2} (ebeek—eepeet (add—bet tree—2 2 "a } (make—nede 2 "a" empty empty}} (ebeek—eepeet (add—bet tree—2 l "a"} tree—l2} (ebeek—eepeet (add—bet tree—2 3 "e"} tree—23} I"! (define (add—bet abet k y} (eend > [(empty? abet} (make—nede k y empty empty}] [(= k (nede—key abet}} (make—nede k v (nede—left bet} ede— 'gbt abet}}] [(e k (nede—key abet}} (make—nede (node—key abet:fia\\K } (nede—yalue abe (add—bet'mdpde—'eft a t} k y} (nede— rdbt abet}}ff [elee (make—nede (nede—key abet} (nede—yalue abet} - » (nede—left abet} (add—bet (nedeer gbt a at} k ]}} ;: Iu_i? : JJST —} inn3_een ;: enewere LLLE iff Lne giyen dd! ie Iti_. ;: leciiLTJLee: ;? (ebeek—eepeet (full? empty} true} (ebeek—eepeet (full? tree—2} true} (ebeek—eepeet (full? tree—l2} fale } (ebeek—eepeet (full? tree—23} falee} (ebeek—eepeet (full? tree—123} true} {define (full? abet} (eend [(empty? abet} true] [(and (empty? (nede—left abet}} (empty? (nede—rigbt abet}}} true] [(er (empty? (nede—left abet}} (empty? (node—right abet}}} falee] [elee (and (full? (nede—left abet}} (full? (nede—rigbt abet}}}]}} (define bad—full—tree (make—nede 2 "b" (make—nede l "a" empty empty} (make—nede d "d" (make—nede 3 "e" empty empty} (make—nede 6 "f" (make—nede 5 "e" empty empty} (make—nede 8 "b" (make—nede ? "g" empty empty} (make—nede 9 "i" empty empty}}}}}} This document is for the exclusive use of x284”. {define hadd—full—tree—alt—selutien {make—nede 8 "" {make—node E "” {make—nede 4 "" {make—nede 2 "" {make—nede l "” empty empty} {make—nede 3 "” empty empty}} {make—nede 5 "" empty empty}} {make—nede T "" empty empty}} {make—nede 9 "" empty empty}}} ;: he_gh; : JET —} ‘. ;: Eredunes ;he he_gh; ef Lne given EST ;: lsams_ee: {eheek—espeet {height empty} U} {eheek—espeet {height tree—2} l} {eheek—espeet {height tree—12} 2} {eheek—espeet {height tree—123} 2} {define {height ahst} {eend [{empty? ahst} U] [else {addl {mas {height {nede—left ahst}} {height {nude—right ahst}}}}]}} ;: perien;? : EST —} Jee_ean ;: Enewers true iff Lne given JET is perfee; > ;: lsams_es: {eheek—espeet {perfeet? empty} true} {eheek—espeet {perfeet? tree—2} true} {eheek—espeet {perfeet? tree—12} false} x\\\ax {eheek—espeet {perfeet? tree—23} false} {cheek—expect {perfeet? tree—123} true} {eheek—espeet {perfeet? had—full—tree} falée} {define {perfeet? ahst} - __ {eend [{empty? ahst} true] [else {and {perfeet? {nede—left a t}} {per et? {nede—right ahst}} {= {height {nede—leffl\ahst} {h ght {nede—right ahst}}}}]}} ;: be-aimizea'L'E’ : I-E'i'l' —L'-'- ha'ir.':-'_e:'.-;:". " ;: Enswers true iff Lne glue: JET is haléfieer ;: lsamp_es: {cheek—expect {halaneed? empty} tr e} {eheek—espeet {halaneed? tree—2} true} {eheek—espeet {halaneed? tree—l2} true} {eheek—espeet {halaneed? tree—23} true} {eheek—espeet {halaneed? tree—123} true} {eheek—espeet {halaneed? {make—nede 3 "e" tree—12 empty}} false} {cheek—expect {halaneed? {make—nede l "a" empty tree—23}} false} {define {halaneed? ahst} {eend [{empty? ahst} true] [else {and {halaneed? {nede—left ahst}} {halaneed? {nede—right ahst}} {{= {ahs {— {height {nede—left ahst}} {height {nede—right ahst}}}} l}}]}} This document is for the exclusive use of x284”. ;; QELJLE'i'l'lf.iI 3:: ;; [eeilfle {Ty—HlnHeKC—Ifl sHHTi ;; {send F: Iiiumber? eflfili ... ] FF Iiiy-Hesfllnlfl_sL—in sfiflfili} .r'r' ;; [sellse {fly—HesHiHC—Is eHHTi ;; {send 3: Iiiumbsr? eflfili ... l :: lifly—Hlssss2fl_sL—in sfifliili} .r'r' ;; [fleilfle {fly—Hlnflas3fl_sL—in sEHIls } if {tend ;; liemp y? [resL sHHleLii ... {firsL sHHZ;sLi ...| ;; lelse ... {fly—HlnflssI—Ifl (ELSE; sflfillsLii { ;: my—Hlnflss2fl_sL—in {:esL sHH3lsLii ...Iii .r'r' ;; [fleilfle {fly—Hssflin3fl_sL—in sEHIls } ,, {tend ;; liemp y? [resL sHHleLii ... {firsL sHHZ;sLi ;; lelse ... {fly—HasfllnI—Ifl (ELSE; sflfillsLii {my—Hesflanfil_sL—ifl {:esL sHHIlsLi} ...:}E> ;; fllfllmss—vslue : Elflfiesl —e Hum -; frsduees Lhe vslue sI Lhe g_uen mlsimss Lree ;; Essieles: xa\\xk {eheek—espeet [minimss—vslue '{l}} l} {eheek—espeet [minimss—vslue '{l 2 3}} 1} ~E) J//f {eheek—espeet [minimss—vslue ' {[l 2 3H} 3( {define {minimss—vslue smmti {send [{number? smmti smmt] [else {mssiminflist—vslue smmt}]i ;; fles;m_i—vslue : Easfilfll —e Hum ;; Preduees Lhe value GI Lhe g;ven maxim ;; Essieles: {eheek—espeet [mssimin—vslue '{lii } {eheek—espeet [mssimin—vslue '{l 2 3}} 3} {eheek—espeet [mssimin—vslue '{[l 2 31)} 1} {define {mssimin—vslue smmti {send [{number? smmti smmt] [else {minimssflist—vslue smmt}]i} {define {minimssflist—vslue smmtlst} {send [{empty? [rest smmtlst}i {minimss—vslue {first smmtlstii] [else {mes {minimss—vslue {first smmtlst}i [minimssflist—Uslue {rest smmtlsti}}]}} {define {mssimisflist—vslue smmtlst} {send [{empty? [rest smmtlst}i {mssimin—vslue {first smmtlstii] [else {min {mssimin—vslue {first smmtlst}i [mssiminilist—vslue {rest smmtlsti}}]}} This document is for the exclusive use of x284”. |" F (define—atruet nede 3”“U“ 'H..-' 'I. h.- Q}L§LE§'1'J.DI : (name left right}} (define family (make—nede "Aline" (make—nede "Bah" (make—node "Daisy" empty empty} (make—nede "Edward" empty empty}} (make—nede "Charlie" (make—nede "Fred" empty empty} (make—nede "Gertrude" empty empty}}}} ;; pa hef fiDTree ELring —} (inien (lisLef (unien U L}} false} ;; Re urne a lieL ef flireet_nne Le Lane (U — leiL, l — right} in reach the ;; given name in the given ujTree ;; Examples: (eheek—enpeet (pathef family "Aliee"} empty} (eheek—enpeet (pathef family "Eeb"} '(D}} (eheek—enpeet (pathef family "Charlie"} '(l}} (eheek—enpeet (pathef family "Daisy"} '(U D}} (eheek—enpeet (pathef family "Edward"} '(D 1}} (eheek—enpeet (pathef family "Fred"} T(l 0}} (eheek—enpeet (pathef family "Gertrude"} '(l 1}} 1> (define (pathef apdt name} (ennd [(empty? abdt} falae] x\\\ax [(atring=? (nede—name ahdt} name} empty] [elae (extend—path (pathef (nede—left abet}' ame} (pathef (nede—right aEé-;q%ame}igfj ;; ea ena—pa h (unien (lie nf (unien U- }} 7eIne ;; (unien (lie nf (unie: U fa_ e ;; —h {inien (lie ef (uiien LJ} fa ,_} (define (extend—path left—ree right—r } (eend [(net (false? left—ree}} (egna D left— e ] [(nnt (false? right—ree}} (pens 'Hrigh —ree}] [elae falae]}} I? ;, neueine? UflTree ELr_ng SLring he; HaL Uenlean ;, anewere Lrue iff name; and nameE are mLh neueine n Liiee remnyed _: Lie ;, given JDZree ;; Inampiee: (eheek—enpeet (eeuaina? family "Eeh" "Charlie" U 0} true} (eheek—enpeet (eeuaina? family "Daisy" "Edward" D U} true} (eheek—enpeet (eeuaina? family "Daisy" "Fred" 1 D} true} (eheek—enpeet (eeusins? family "Daisy" "Charlie" U 1} true} (eheek—enpeet (eeuaina? family "Alice" "Gertrude" D 2} false} (define (enusine? abet namel name2 m n} (eheek—m—n (pathef abet namel} (pathef ahdt name2} m n}} (define (eheek—m—n pl p2 m n} (eene [(nr (empty? pl} (empty? p2}} false] [(= (first pl} (first p2}} (eheek—m—n (reat pl} (reat p2} m n}] [else (and (= (min (length pl} (length p2}} (addl m}} (= (ape (— (length pl} (length p2}}} n}}]}} This document is for the exclusive use of x284”. ...
View Full Document

Page1 / 4

a06sol-cs135-w10 - F: Cfiiab EEELGIHLIC b HHLUTiUHE WiHTLi...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online