Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.

image text in transcribed

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions