Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Each of the following examples gives a design in a language of a data structure for binary troe and a function for counting the nodes

image text in transcribed
Each of the following examples gives a design in a language of a data structure for binary troe and a function for counting the nodes in a binary tree; mutable struct BNode data: : Int left: Union fNothing, BNode } right:: Unionfothing, BNode\} end BTree = Union (Nothing, BNode } function count (r::BTree) if r= nothing return 0 else return 1+ count (r1 ef t)+ count (r.right) end end - Haskell data BTree a =Nil I Branch a (BTree a) (BTree a) count NiI=0 count (Branch . left right) = (count left) + (count right) +1 - Picat count ( nil )=0. count (f, Left, Right })=count( Lef t)+count(Right)+1. Write each of the following functions on binary trees in one of these languages. 1. min max (tree): This function returns a pair (min, max), where sin is the minimum value, and max is the maximum value in tree. Note that the tree may not be a binary search tree. 2. inc1 (tree): This function returns a copy of tree, in which each node value is incre mented by 1

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Real Time Database And Information Systems Research Advances

Authors: Azer Bestavros ,Victor Fay-Wolfe

1st Edition

1461377803, 978-1461377801

More Books

Students also viewed these Databases questions