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

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
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
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education