Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Solve this USING F# The type 'a tree represents binary trees containing elements of 'a, and pos represents positions in such trees (e.g. L (RS)

Solve this USING F#image text in transcribed

The type 'a tree represents binary trees containing elements of 'a, and pos represents positions in such trees (e.g. L (RS) means go left, then go right, then stop). type 'a tree = | Lf | Br of 'a * 'a tree * 'a tree type pos = IS | L of pos | R of pos // stop here // go left // go right Write a function deleteSubtree : 'a tree -> pos -> 'a tree that replaces the subtree at a given position with Lf if the position exists in the tree and leaves the tree unchanged otherwise. > let t = Br (1, Br(2, Lf, Lf), Br (3, Br (4, Lf, Lf), Lf));; val t : int tree = Br (1,Br (2,Lf,Lf),Br (3,Br (4,Lf,Lf),Lf)) > deleteSubtree t S;; val it : int tree = Lf > deleteSubtree t (LS) ;; val it : int tree = Br (1,Lf, Br (3,Br (4,Lf , Lf) , Lf)) > deleteSubtree t (R (L S)) ;; val it : int tree = Br (1,Br(2, Lf, Lf) ,Br (3, Lf , Lf)) > deleteSubtreet (R (R (RS))) ;; val it : int tree = Br (1,Br(2, Lf,Lf),Br (3,Br (4, Lf,Lf),Lf)) The type 'a tree represents binary trees containing elements of 'a, and pos represents positions in such trees (e.g. L (RS) means go left, then go right, then stop). type 'a tree = | Lf | Br of 'a * 'a tree * 'a tree type pos = IS | L of pos | R of pos // stop here // go left // go right Write a function deleteSubtree : 'a tree -> pos -> 'a tree that replaces the subtree at a given position with Lf if the position exists in the tree and leaves the tree unchanged otherwise. > let t = Br (1, Br(2, Lf, Lf), Br (3, Br (4, Lf, Lf), Lf));; val t : int tree = Br (1,Br (2,Lf,Lf),Br (3,Br (4,Lf,Lf),Lf)) > deleteSubtree t S;; val it : int tree = Lf > deleteSubtree t (LS) ;; val it : int tree = Br (1,Lf, Br (3,Br (4,Lf , Lf) , Lf)) > deleteSubtree t (R (L S)) ;; val it : int tree = Br (1,Br(2, Lf, Lf) ,Br (3, Lf , Lf)) > deleteSubtreet (R (R (RS))) ;; val it : int tree = Br (1,Br(2, Lf,Lf),Br (3,Br (4, Lf,Lf),Lf))

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

Modern Database Management

Authors: Jeffrey A. Hoffer Fred R. McFadden

4th Edition

0805360476, 978-0805360479

More Books

Students also viewed these Databases questions