Tree Traversals in C++ with Recursion
Description
Unformatted Attachment Preview
Write a recursive (no loops allowed) routine to determine if ALL paths from leaves to root are the
same length.
The tree nodes are instances of the following struct:
struct Node {
int key;
Node *left, *right;
};
However, for this application the key (or integer) in the node is not utilized and can be ignored.
The function is prototyped in equal-paths.h and should be implemented in the corresponding
.cpp file.
// Prototype
bool equalPaths(Node * root);
Examples
See the images below of trees with equal paths that should return true and trees that do not
have all equal paths which should return false .
?
?
?
You MAY define helper functions if needed in equal-paths.cpp .
You CANNOT use a container (like a set, vector, map) to do your work. Do your work
during your traversal (this is the learning goal of the problem).
We have also provided a VERY RUDIMENTARY test program equal-paths-test. cpp that
you may use and modify as desired to test certain configurations and debug your code.
It will not be graded.
Test your Code
Run equal-paths-test.cpp for basic testing
Open a new terminal:
cd hw4
make equal-paths-test
./equal-paths-test
Run more in-depth tests:
cd hw4_tests/equalpaths-test
make equalpaths_tests
./equalpaths_tests
Prepare your Code for Submission
Ensure you surpassed all debugging messages:
grep -n “cout” equal-paths.h
grep -n “cout” equal-paths.cpp
Make sure code compiles without warning:
make equal-paths-test
Ensure no Valgrind errors:
valgrind –tool=memcheck –leak-check=yes ./equal-paths-test
Purchase answer to see full
attachment
Have a similar assignment? "Place an order for your assignment and have exceptional work written by our team of experts, guaranteeing you A results."