Skip to content

Added node count and leaf count #83

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Added node count and leaf count
  • Loading branch information
gupta2140 committed Jun 8, 2017
commit ecf5624a7609c4d49f0b8e8859071bae4df7c381
4 changes: 2 additions & 2 deletions traverals/binary_tree_traversals.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def build_tree():
def pre_order(node):
no_of_nodes=0
if not isinstance(node, TreeNode) or not node:
return 0
return
print(node.data, end=" ")
return 1+pre_order(node.left)#counting number of left nodes
return 1+pre_order(node.right)#counting number of right nodes
Expand All @@ -53,7 +53,7 @@ def pre_order(node):
def in_order(node):
leaf_count=0
if not isinstance(node, TreeNode) or not node:
return 0
return
in_order(node.left)
print(node.data, end=" ")
return 1+in_order(node.right)#counting number of leaf nodes
Expand Down