Java Program to calculate the Difference between the Sum of the Odd Level and the Even Level Nodes of a Binary Tree17 Mar 2025 | 3 min read In this program, we need to calculate the difference between the sum of nodes present at odd levels and sum of nodes present at even levels. Suppose, if a tree contains 5 levels, then ![]() In the above diagram, odd levels are represented using blue dotted lines and even with green. Algorithm
a. The difference() will calculate the difference between the sum of nodes at the odd and even levels:
Program:Output: Difference between sum of odd level and even level nodes: 11 Next TopicJava Programs |
Java Program to find the frequency of odd & even numbers in the given matrix In this program, we need to find the frequencies of odd and even numbers present in the matrix. In the above example, all odd numbers are represented by the blue square and...
3 min read
Java Convert int to double We can convert int to double 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 double Example Let's...
1 min read
In this program, we will create a singly linked list and delete a node from the beginning of the list. To accomplish this task, we need to make the head pointer pointing to the immediate of the initial node which will now become the...
6 min read
In this program, we will create a doubly linked list and sort nodes of the list in ascending order. Original List: Sorted List: To accomplish this, we maintain two pointers: current and index. Initially, current point to head node and index will point to node to current....
7 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...
19 min read
Java Convert Hexadecimal to Decimal We can convert hexadecimal to decimal in java using Integer.parseInt() method or custom logic. Java Hexadecimal to Decimal conversion: Integer.parseInt() The Integer.parseInt() method converts string to int with given redix. The signature of parseInt() method is given below: public static int parseInt(String s,int redix) Let's see...
2 min read
. In this program, we need to find the reverse of the string. This can be done by iterating the string backward and storing each character from the original string into a new string. Original string: Dream big Reverse of the string: big maerD ALGORITHM STEP 1: START STEP 2: DEFINE...
2 min read
In this program, we need to replace all the spaces present in the string with a specific character. String: Once in a blue moon String after replacing space with '-': Once-in-a-blue-moon One of the approach to accomplish this is by iterating through the string to find spaces. If...
2 min read
In this program, we need to check whether two trees are identical or not. For two trees to be identical, they have to satisfy two conditions: Structure of both the trees should be the same. Nodes present in one tree should be present in another tree. Above diagram...
4 min read
Java program to print the following pattern on the console Algorithm: STEP 1: START STEP 2: SET coe=1, rows= 6. STEP 3: SET i=0. REPEAT STEP 4 to STEP 11 UNTIL i STEP 4: SET space = 1. REPEAT STEP 5 and STEP 6 UNTIL space<(rows ?i) STEP 5: PRINT...
2 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