Python Program to Count the Number of Nodes in Binary Tree

This is a Python program to find the number of nodes in a binary tree. Problem Description The program creates a binary tree and counts the number of nodes in the tree. Problem Solution 1. Create a class BinaryTree with instance variables key, left and right. 2. Define methods set_root, insert_left, insert_right, inorder and search. … Read more

advertisement

Python Program to Count Leaf Nodes in a Tree

This is a Python program to count the number of leaf nodes in a tree. Problem Description The program creates a tree and counts the number of leaf nodes in the tree. Problem Solution 1. Create a class Tree with instance variables key and children. 2. Define methods set_root, add, count_leaf_nodes, count_leaf_nodes_helper and search. 3. … Read more

advertisement

Python Program to Find Minimum and Maximum Element in Binary Search Tree

This is a Python program to find the smallest and largest elements in a binary search tree. Problem Description The program presents a menu to the user to perform various operations on a binary search tree including finding the smallest and largest elements. Problem Solution 1. Create a class BSTNode with instance variables key, left, … Read more

advertisement

Python Program to Construct a Binary Search Tree and Perform Deletion and Inorder Traversal

This is a Python program to construct a binary search tree and perform deletion and inorder traversal. Problem Description The program creates a binary search tree and presents a menu to the user to perform insertion, deletion and inorder traversal operations. Problem Solution 1. Create a class BSTNode with instance variables key, left, right and … Read more

advertisement

Python Program to Construct Binary Tree from Postorder and Inorder

This is a Python program to build a binary tree with in-order and post-order traversals as input. Problem Description The program builds a binary tree from their in-order and post-order traversals. Problem Solution 1. Create a class BinaryTree with instance variables key, left and right. 2. Define methods set_root, inorder, and postorder. 3. The method … Read more

advertisement

Python Program to Create a Mirror Copy of a Tree and Display using BFS Traversal

This is a Python program to create a mirror copy of a binary tree and display its BFS traversal. Problem Description The program creates a mirror copy of a binary tree and displays its BFS traversal. Problem Solution 1. Create a class BinaryTree with instance variables key, left and right. 2. Define methods set_root, insert_left, … Read more

advertisement

Python Program to Implement Depth First Search Traversal using Post Order

This is a Python program to perform depth-first post-order traversal on a tree. Problem Description The program creates a tree and presents a menu to the user to perform operations on the tree including post-order traversal. Problem Solution 1. Create a class Tree with instance variables key and children. 2. Define methods set_root, add, postorder … Read more

advertisement

Python Program to Find Maximum Value in Tree using Inorder Traversal

This is a Python program to find the largest value of a binary tree using in-order traversal. Problem Description The program creates a binary tree and presents a menu to the user to perform operations on the tree including finding the largest element in the tree. Problem Solution 1. Create a class BinaryTree with instance … Read more

advertisement

Python Program to Find Nth Node of Inorder Traversal

This is a Python program to find the Nth node in the in-order traversal of a binary tree. Problem Description The program creates a binary tree and presents a menu to the user to perform operations on the tree including printing the Nth term in its in-order traversal. Problem Solution 1. Create a class BinaryTree … Read more

advertisement

DFS Traversal of a Tree Without using Recursion in Python

This is a Python program to perform depth-first search on a binary tree without using recursion. Problem Description The program creates a binary tree and presents a menu to the user to perform operations on the tree including depth-first search. Problem Solution 1. Create a class Stack to implement a stack. 2. The class Stack … Read more

advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.