Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Problem Description Monkeys like to swing from tree to tree. They can swing from

ID: 3863185 • Letter: P

Question

Problem Description

Monkeys like to swing from tree to tree. They can swing from one tree to another directly as long as there is no tree in between that is taller than or have the same height as either one of the two trees. For example, if there are 5 trees with heights 19m, 17m, 20m, 20m and 20m lining up in that order, then the monkey will be able to swing from one tree to the other as shown below:

1. from first tree to second tree

2. from first tree to third tree

3. from second tree to third tree

4. from third tree to fourth tree

5. from fourth tree to fifth tree

Write a program using a stack abstract datatype to get the correct count for the trees in different parts of the jungle.

Need some guidance for this task. Just an idea of how the overall code will generally look like.

Explanation / Answer

you need to do a Depth First Search of the graph which represents the jungle. Instead of recursion use Stacks.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote