Question: SOLVE THE FOLLOWING QUESTION IN HASKELL WITHOUT USING PRELUDE FUNCTIONS OR IMPORTING ANY LIBRARIES. You may make as many helper functions. According to Wikipedia, a

SOLVE THE FOLLOWING QUESTION IN HASKELL WITHOUT USING PRELUDE FUNCTIONS OR IMPORTING ANY LIBRARIES. You may make as many helper functions.

According to Wikipedia, a complete binary tree is a binary tree "where every level, except possibly the last, is completely filled, and all nodes in the last level are as far left as possible."

The Wikipedia page referenced above also mentions that "Binary trees can also be stored in breadth-first order as an implicit data structure in lists, and if the tree is a complete binary tree, this method wastes no space."

Your task is to write a function that takes a list of integers and, assuming that the list is ordered according to an in-order traversal of a complete binary tree, returns a list that contains the values of the tree in breadth-first order.

Example 1: Let the input list be [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]. This list contains the values of the following complete binary tree.

SOLVE THE FOLLOWING QUESTION IN HASKELL WITHOUT USING PRELUDE FUNCTIONS OR IMPORTING

In this example, the input list happens to be sorted, but that is not a requirement.

Output 1: The output of the function shall be an list containing the values of the nodes of the binary tree read top-to-bottom, left-to-right. In this example, the returned list should be:

[7, 4, 9, 2, 6, 8, 10, 1, 3, 5] IT SHOULD PASS THE FOLLOWING TEST CASES: 

ANY LIBRARIES. You may make as many helper functions. According to Wikipedia,

describe "breadthFirstTraversal" $ do it "should return the correct order of the numbers in the matrix" $ do breadthFirstTraversal [10,7,4,2,5,3,8,9] 'shouldBe' [5,4,8,7,2,3,9,10] breadthFirstTraversal [1,2,3,4,5,6,7,8,9,10] 'shouldBe [7,4,9,2,6,8,10,1,3,5] breadthFirstTraversal [1,2,2,6,7,5] 'shouldBe' [6,2,5,1,2,7]

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!