3

Iterative method to Count full nodes in a Binary tree

 1 year ago
source link: https://www.geeksforgeeks.org/videos/iterative-method-to-count-full-nodes-in-a-binary-tree/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Iterative method to Count full nodes in a Binary tree

Iterative method to Count full nodes in a Binary tree
  • 31/05/2022

Given A binary Tree, how do you count all the full nodes (Nodes which have both children as not NULL) without using recursion and with recursion? Note leaves should not be touched as they have both children as NULL. 1) Create an empty Queue Node and push root node to Queue. 2) Do following while nodeQeue is not empty. a) Pop an item from Queue and process it. a.1) If it is full node then increment count++. b) Push left child of popped item to Queue, if available. c) Push right child of popped item to Queue, if available.

Iterative method to Count full nodes in a Binary tree : https://www.geeksforgeeks.org/count-full-nodes-binary-tree-iterative-recursive/


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK