Posts

Showing posts with the label tree height problem

C: Tree Height Problem

Image
This example is taken from Chapter 2 of the book, "Beginning C", 5th edition . It can be found on page 77. I have made some of my own modifications to the example from the textbook, but it works in the same way. Tree Height Problem The Problem Your problem is to find out the height of a tree without using a very long ladder, which itself would introduce risk to life and limb. To find the height of a tree, you’re allowed the help of a friend—preferably a short friend unless you yourself are short, in which case you need a tall friend. You should assume that the tree you’re measuring is taller than both you and your friend. The Analysis Real-world problems are rarely expressed in terms that are directly suitable for programming. Before you consider writing a line of code, you need to be sure you have a complete understanding of the problem and how it’s going to be solved. Only then can you estimate how much time and effort will be involved in creating the solution. The analysis...