From 6faf95adfd92e9cbea4d60deb61fa530531b2305 Mon Sep 17 00:00:00 2001 From: John Law Date: Mon, 20 Apr 2020 20:31:48 +0200 Subject: [PATCH] Update example --- dynamic_programming/tree_height.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/dynamic_programming/tree_height.cpp b/dynamic_programming/tree_height.cpp index e9039c5a1..095d79f7b 100644 --- a/dynamic_programming/tree_height.cpp +++ b/dynamic_programming/tree_height.cpp @@ -1,4 +1,4 @@ -// C++ Program to find height of the tree using bottom - up DP. +// C++ Program to find height of the tree using bottom-up dynamic programming. /* * Given a rooted tree with node 1. @@ -8,7 +8,14 @@ * 1 2 * 1 3 * 2 4 - * Height of the tree : - 3 + * which can be represented as + * 1 + * / \ + * 2 3 + * | + * 4 + * + * Height of the tree : - 2 */ #include @@ -42,6 +49,7 @@ int main() { int no_of_nodes; std::cout << "Enter number of nodes of the tree : " << std::endl; std::cin >> no_of_nodes; + // u,v denotes an undirected edge of tree. int u, v; // Tree contains exactly n-1 edges where n denotes the nodes.