Note: Webwork will stop accepting this homework at that time - Turn it in well BEFORE then.
No late homework is accepted.
TURN IN THIS ASSIGNMENT USING WEBWORK!!!
Do this homework using DrScheme. Save the file as a ".scm" file--that is, with a .scm extension. If you turn in a non-scm file, you will lose credit.
At the top of your file, include the student info portion of the HW
Skeleton (Name, GT Number, HW, Course, Instructor, Lecture Time).
NOTE: Instead of using empty for leaf nodes we are going to false. This is the way the book does it. Please be aware of this.
NOTE: Your parameters must be in the same order as they are specified here. If you are unsure, ask your TA. You will lose credit otherwise.
NOTE: Follow the HW Skeleton, these homeworks will be autograded and must be in the specified format. You will lose credit otherwise.
NOTE: Remember that you must be in "Intermediate Scheme".
(define-struct node (data left right))
(define-struct data (ssn name))
Remember to do the analysis for both of these
A binary-search-tree(BST) is either:
1. false; or
2. (make-node mydata lft rgt) is a BST where
(a) mydata is a data instance,
(b) lft and rgt are BSTs,
(c) all data in lft are smaller than mydata, and
(d) all data in rgt are larger than mydata.
(e) data is compared by ssn, so it is the determining factor for comparing
Remember to create the data definition and analysis for data
(inorder <BST>)
(inorder false)
or
(inorder (make-node ((make-data 123456789 'name-1) false false)))
The following is a sample of what should happen if someone tries to run your
function in Dr. Scheme.
Welcome to DrScheme, version 103p1.
Language: Intermediate Student.
> (inorder (make-node (make-data 63 'Terry)
(make-node (make-data 29 'John)
(make-node (make-data 15 'Graham)
(make-node (make-data 10 'Connie) false false)
(make-node (make-data 24 'Brian) false false))
false)
(make-node (make-data 89 'Jones)
(make-node (make-data 77 'Eric) false false)
(make-node (make-data 95 'Michael)
false
(make-node (make-data 99 'Mandy) false false)))))
(list 10 15 24 29 63 77 89 95 99)
> (inorder false)
empty
|
(create-bst <BST> <number> <symbol>)
(create-bst false 123456789 'name-1)
or
(create-bst (make-node ((make-data 123456789 'name-1) false false)) 987654321 'name-2)
The following is a sample of what should happen if someone tries to run your
function in Dr. Scheme.
Welcome to DrScheme, version 103p1.
Language: Intermediate Student.
> (create-bst (make-node (make-data 42 'Ben)
false
(make-node (make-data 314 'Jerry) false false))
100
'Scoop)
(make-node (make-data 42 'Ben)
false
(make-node (make-data 314 'Jerry)
(make-node (make-data 100 'Scoop) false false)
false))
> (create-bst false 3 'Moe)
(make-node (make-data 3 'Moe) false false)
|
(create-bst-from-list <list>)
(create-bst-from-list '())
;; notice we are in Intermediate Scheme so we recommend using '() instead of empty
or
(create-bst-from-list (list (list 992358595 'bryan)
(list 776546546 'ryan)
(list 246354645 'david)
(list 101957321 'janet)
(list 956249621 'travis)
(list 153269413 'james)
(list 899897413 'matt)
(list 296596331 'arjun)))
or
(define sample-list (list (list 992358595 'bryan)
(list 776546546 'ryan)
(list 246354645 'david)
(list 101957321 'janet)
(list 956249621 'travis)
(list 153269413 'james)
(list 899897413 'matt)
(list 296596331 'arjun)))
(create-bst-from-list sample-list)
Note: these are NOT the SSN's of the TAs
The following is a sample of what should happen if someone tries to run your
function in Dr. Scheme.
Welcome to DrScheme, version 103p1.
Language: Intermediate Student.
> (create-bst-from-list '()) ;; in Intermediate Scheme we can use '() instead of empty
false
> (create-bst-from-list (list (list 992358595 'LoneStar)
(list 776546546 'DarkHelmet)
(list 246354645 'Vespa)
(list 101957321 'Scroob)
(list 996249621 'Yogert)))
(make-node (make-data 992358595 'LoneStar)
(make-node (make-data 776546546 'DarkHelmet)
(make-node (make-data 246354645 'Vespa)
(make-node (make-data 101957321 'Scroob)
false
false)
false)
false)
(make-node (make-data 996249621 'Yogert) false false))
|