Java program to find maximum width of a binary tree17 Mar 2025 | 3 min read In this program, we need to find out the maximum width of the binary tree. The width of the binary tree is the number of nodes present in any level. So, the level which has the maximum number of nodes will be the maximum width of the binary tree. To solve this problem, traverse the tree level-wise and count the nodes in each level. ![]() In the given binary tree, Level 1 has one node, so maxWidth = 1. So, the maximum width of the above binary tree is 4 denoted by white ellipse. Algorithm
a. findMaximumWidth() will find out the maximum width of the given binary tree:
Program:Output: Maximum width of the binary tree: 4 Next TopicJava Programs |
Java Program to find Smallest Number in an Array We can find the smallest element or number in an array in java by sorting the array and returning the 1st element. Let's see the full example to find the smallest number in java array. public class SmallestInArrayExample{ public static...
2 min read
Java Convert Object to String We can convert Object to String in java using toString() method of Object class or String.valueOf(object) method. You can convert any object to String in java whether it is user-defined class, StringBuilder, StringBuffer or anything else. Here, we are going to see two examples...
1 min read
In this program, we need to convert the given binary tree to corresponding doubly liked list. The binary tree is a tree data structure in which each node has at most two children node. This can be achieved by traversing the tree in the in-order manner that...
6 min read
Java String to Date We can convert String to Date in java using parse() method of DateFormat and SimpleDateFormat classes. To learn this concept well, you should visit DateFormat and SimpleDateFormat classes. Java String to Date Example Let's see the simple code to convert String to Date in java. import java.text.SimpleDateFormat; import...
2 min read
Java Convert int to long We can convert int to long in java using assignment operator. There is nothing to do extra because lower type can be converted to higher type implicitly. It is also known as implicit type casting or type promotion. Java int to long Example Let's...
1 min read
In this program, we will create a circular linked list and sort the list in ascending order. In this example, we maintain two nodes: current which will point to head and index which will point to node to current. The first loop, keep track...
3 min read
In this section, we will learn what is a smith number and also create Java programs to check if the given number is smith or not. The smith number program frequently asked in Java coding tests and academics. Smith Number A Smith number is a composite number whose...
4 min read
It is a very interesting problem frequently asked in interviews of top IT companies like Google, Amazon, TCS, Accenture, etc. By solving the problem, one wants to check the logical ability, critical thinking, and problem-solving skill of the interviewee. So, in this section, we are going...
7 min read
In this program, we create a circular linked list and insert a new node in the middle of the list. If the list is empty, both head and tail will point to new node. If the list is not empty, then we will calculate the...
8 min read
Java Program Number to Word In this section, we will create a Java program that converts the given number into words. For example, if the given number is 54,297 then the output should be Fifty-Four Thousand Two Hundred Ninety-Seven. Let's create a Java program for the same. NumberToWordExample1.java class...
9 min read
We request you to subscribe our newsletter for upcoming updates.
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India