Question: Please write a function in Haskell which does the following, without using any prelude functions or importing any libraries. Make relevant helper functions where needed.

Please write a function in Haskell which does the following, without using any prelude functions or importing any libraries. Make relevant helper functions where needed.

Please write a function in Haskell which does the following, without using

any prelude functions or importing any libraries. Make relevant helper functions where

In this question, we have a tree which is being set on fire . You are given a binary tree which has a pair of numbers on each of its nodes. The pair contains the value of the node and the time it will take to burn (val, time). Apart from that, you will be provided with a value of a node which is being set on fire initially. A node when set on fire, starts burning and spreading fire at the same time. It can spread fire to all the nodes it is connected to after a single unit of time. Similarly, all nodes will keep burning and spreading fire. If a node has burned completely then it dies and gets removed from the tree along with its children (obviously). Your job is to return the time that will take for the tree to burn completely. For example, for the following tree: If the target node is 10 , then at t=0, node with data 10 , will be set on fire. At t=1, the fire will be passed to the node with data 14 as well but at that time node with value 10 will still not be burnt completely since it's time to burn equals to 2 ( 1 second is still left). At t=2, node 10 and node 14 will die, while the fire has been passed to node 19 . But because node 14 has died so the entire tree will die at t=2. Note: No imports are allowed. The fire that is passed from one node to another is always after 1 unit of time. For example, if a node A is on fire at T=0 and is connected to Node B. Then Node B will be on fire at t=1( not t=0)

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!