Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Ocaml Programing (* TODO: Implement a CPS style postorder traversal function. *) let traverse (tree : 'a tree) : 'a list = let rec helper

Ocaml Programingimage text in transcribed

image text in transcribed

(* TODO: Implement a CPS style postorder traversal function. *) let traverse (tree : 'a tree) : 'a list = let rec helper (tree : 'a tree) (sc : 'a list 'r) = match tree with raise NotImplemented in raise Notimplemented Oftentimes we want to traverse an entire tree in a certain order. One common way of traversing a tree is postorder traversal. (You may be familiar with postorder traversal from COMP 250!) In postorder traversal, we traverse the left subtree first, then traverse the right subtree, then visit the node. Our job is to create a function that returns a list of the values of the tree visited in postorder traversal. This function should be implemented with the Continuation Passing Style. Our function would have the following signature: traverse : 'a tree 'a list Example 1: For the tree in the image above, traverse should return the list [2;5;11;6; 7;5;9;9;1]. Example 2: - Input: Tree (Tree (Empty, 2, Empty), 1, Tree (Empty, 3, Empty)) - Output: [2;3;1] Example 3: - Input: Tree (Tree (Tree (Empty, 4, Empty), 2, Tree (Empty, 5, Empty)), 1, Tree (Empty, 3, Empty)) - Output: [4;5;2;3;1] Hint: You may want to create a recursive helper function with the following type signature: helper : 'a tree (unit 'a list) 'a list

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

Database Concepts

Authors: David M. Kroenke

1st Edition

0130086509, 978-0130086501

More Books

Students also viewed these Databases questions

Question

Did the team members feel that their work mattered

Answered: 1 week ago

Question

3. What may be the goal of the team?

Answered: 1 week ago