Question
Do On Dr. Racket Part1: A complete binary tree is defined as null, or a rotor or an internal node with exactly two children, each
Do On Dr. Racket
Part1:
A complete binary tree is defined as null, or a rotor or an internal node with exactly two children, each of which is also a complete binary tree. In Scheme, we can represent such a tree using a list. One example is (a(b(d)(e))(c(f)(g))), which means that the root of the tree is a, b and c are its left and right child, d and e are the left and right child of b, and f and g are the left and right child of c, respectively. Assume that the input three is always correct.
Write a recursive function, called calheight to count the number of nodes on the longest path from the root to one of leaves in a complete binary tree.
For the tree example above, the result is 3.
Part2:
Continue from Part 1. Given such a complete binary tree represented as a list, create a function, called inorder, to transverse the tree using the inorder. The inorder transversal of a binary tree is: starting from the root node, recursively inorder transverse the left child, access the current node, and recursively inorder transverse the right child.
For the tree example, the result is a list (d b e a f c g).
Answer format should be as follows:
; Answer to (1)
(define (ackermann....)
; Answer to (2)
(define (calheight....)
; Answer to (3)
(define (inorder...)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started