please answer in scheme racket flavor 1. Create the recursive function far-left that will find the left-most value

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter15: Recursion
Section: Chapter Questions
Problem 6PE
icon
Related questions
Question

please answer in scheme racket flavor

1. Create the recursive function far-left that will find the left-most value

2.Create the recursive function far-right that will find right-most value

3. Write depth, a procedure that takes a tree as an argument and returns the largest number of nodes connected through parent-child links. That is, a leaf node has depth 1; a tree in which all the children of the root node are leaves has depth 2. Our world tree has depth 4 (because the longest path from the root to a leaf is, for example, world, country, state, city).

4. Write count-nodes, a procedure that takes a tree as an argument and returns the total number of nodes in the tree. (Earlier we counted the number of leaf nodes.)

(define (leaf? node) (null? (children node))) (define (datum node) (car node)) (define (children node) (cdr node)) (define (count-leaves tree) (if (leaf? tree) 1 (count-leaves-in-forest (children tree)) ) ) (define (count-leaves-in-forest forest) (if (null? forest) 0 (+ (count-leaves (car forest)) (count-leaves-in-forest (cdr forest))) ) ) (define (make-node datum children) (cons datum children)) (define (leaf datum) (make-node datum '()) ) (define (cities name-list) (map leaf name-list) ) (define (in-tree? place tree) (or (equal? place (datum tree)) (in-forest? place (children tree)) ) ) (define (in-forest? place forest) (if (null? forest) #f (or (in-tree? place (car forest)) (in-forest? place (cdr forest))) ) ) (define (locate city tree) (if (equal? city (datum tree)) (list city) (let ((subpath (locate-in-forest city (children tree)))) (if subpath (cons (datum tree) subpath) #f)))) (define (locate-in-forest city forest) (if (null? forest) #f (or (locate city (car forest)) (locate-in-forest city (cdr forest))))) (define world-tree2 (make-node 'world (list (make-node 'italy (cities '(venezia riomaggiore firenze roma))) (make-node '(united states) (list (make-node 'california (cities '(berkeley (san francisco) gilroy))) (make-node 'massachusetts (cities '(cambridge amherst sudbury))) (make-node 'ohio (cities '(kent))))) (make-node 'zimbabwe (cities '(harare hwange))) (make-node 'china (cities '(beijing shanghai guangzhou suzhou))) (make-node '(great britain) (list (make-node 'england (cities '(liverpool))) (make-node 'scotland (cities '(edinburgh glasgow (gretna green)))) (make-node 'wales (cities '(abergavenny))))) (make-node 'australia (list (make-node 'victoria (cities '(melbourne))) (make-node '(new south wales) (cities '(sydney))) (make-node 'queensland (cities '(cairns (port douglas)))))) (make-node 'honduras (cities '(tegucigalpa)))))) ; (count-leaves world-tree) (display (count-leaves world-tree2)) (newline) ;> (in-tree? 'abergavenny world-tree) (display (in-tree? 'abergavenny world-tree2)) (newline) ;#T ;> (in-tree? 'abbenay world-tree) (display (in-tree? 'abbenay world-tree2)) (newline) ;#F ;> (in-tree? 'venezia (cadr (children world-tree))) (display (in-tree? 'venezia (cadr (children world-tree2)))) (newline) ;#F

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Computational Systems
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning