- Programs List
- Program to calculate the area of rectangle
- Program to calculate the volume of sphere
- Program to find the area of the pentagon
- Program to find the area of parallelogram
- Program to find the area of square
- Program to find the surface area of sphere
- Program to find the volume of cone
- Program to find the volume of the cube
- Program to find the volume of cylinder
- Program to calculate the CGPA percentage
- Program to convert Celsius into Fahrenheit
- Program to convert days into years
- Program to convert Fahrenheit into Celsius
- Program to find the area of an equilateral triangle
- Program to find the area of a triangle
- Program to find the area of the right angle triangle
- Program to find the perimeter of the rectangle
- Program to find the simple interest
- Program to find the surface area of a cube
- Program to find the surface area of cuboid
- Program to find the surface area of the cylinder
- Program to Check Disarium number
- Program to Check Happy number
- Program to Check Harshad number
- Program to print all Disarium numbers between 1 to 100
- Program to print all Happy numbers between 1 to 100
- Program to print all Pronic numbers between 1 to 100
- Program to determine whether a given number is a Deficient number
- Program to determine whether a given number is an abundant number
- Program to determine whether a given number is a twisted prime number
- Program to print all abundant numbers between 1 to 100
- Program to print all Kaprekar numbers between 1 to 100
- Program to print all prime numbers between 1 to 100
- Program to print the average of n numbers
- Program to print the combination (nCr) of the given number
- Program to print the first 10 prime numbers
- Program to print the permutation (nPr) of the given number
- Program to print the sum of digits without using modulus
- Program to swap two numbers
- Program to swap two numbers without using the third variable
- Program to copy all the elements of one array into another array
- Program to find the frequency of each element of an array
- Program to left rotate the elements of an array
- Program to print the duplicate elements of an array
- Program to print the elements of an array
- Program to print the elements of an array in reverse order
- Program to print the elements of an array present on even position
- Program to print the elements of an array present on odd position
- Program to print the largest element present in an array
- Program to print the number of elements present in an array
- Program to print the smallest element present in an array
- Program to print the sum of all the elements of an array
- Program to right rotate the elements of an array
- Program to sort the elements of an array in ascending order
- Program to sort the elements of an array in descending order
- Program to calculate the addition of 2 matrices
- Program to calculate the subtraction of 2 matrices
- Program to determine whether a given matrix is an identity matrix
- Program to determine whether a given matrix is a sparse matrix
- Program to determine whether two matrices are equal
- Program to display the lower triangular matrix
- Program to display the upper triangular matrix
- Program to find the frequency of odd & even numbers in the given Matrix
- Program to find the product of two matrices
- Program to find the sum of each row and each column of a matrix
- Program to find the transpose of a given matrix
- Program to count the total number of punctuation characters exists in a string
- Program to count the total number of vowels and consonants in a string
- Program to determine whether two strings are the anagram
- Program to divide a string in 'N' equal parts
- Program to find all the permutations of a string
- Program to find all possible subsets of a string
- Program to find the longest repeating sequence in a string
- Program to remove all the white spaces from a string
- Program to replace lower-case characters with upper-case and vice versa
- Program to replace the spaces of a string with a specific character
- Program to Count the Total Number of Characters in a String
- Program to Count the Total Number of Words in a String
- Program to Determine Whether a Given String is Palindrome
- Program to Determine Whether One String is a Rotation of Another
- Program to Find Maximum and Minimum Occurring Character in a String
- Program to Find Reverse of a String
- Program to Find the Duplicate Characters in a String
- Program to Find the Duplicate Words in a String
- Program to Find the Frequency of Characters
- Program to Find the Largest and Smallest Word in a String
- Program to Find the Most Repeated Word in a Text File
- Program to Find the Number of Words in the Given Text File
- Program to Print Smallest and Biggest Possible Palindrome Word in a Given String
- Program to Separate the Individual Characters from a String
- Program to Swap two String Variables Without Using Third or Temp Variable
- Program To Print Following Pattern
- Program To Print Following Pattern
- Program To Print Following Pattern
- Program To Print Following Pattern
- Program To Print Following Pattern
- Program To Print Following Pattern
- Program To Print Following Pattern
- Program To Print Following Pattern
- Program To Print Following Pattern
- Program to Print Following Pattern
- Program to Print Following Pattern
- Program to Print Following Pattern
- Program to Print Following Pattern
- Program to Print Following Pattern
- Program to Print Following Pattern
- Program to Print Following Pattern
- Program to Print Following Pattern
- Program to Print Following Pattern
- Program to Print Following Pattern
- Program to Calculate the Difference Between the Sum of the Odd Level and Even Level Nodes of a Binary Tree
- Program to Construct a Binary Search Tree and Perform Deletion and Inorder Traversal
- Program to Convert Binary Tree to Binary Search Tree
- Program to Determine Whether all Leaves are at Same Level
- Program to Determine Whether two Trees are Identical
- Program to Find Maximum Width of a Binary Tree
- Program to Find the Largest Element in a Binary Tree
- Program to Find the Maximum Depth or Height of a Tree
- Program to Find the Nodes Which are at the Maximum Distance in a Binary Tree
- Program to Find the Smallest Element in a Binary Tree
- Program to Find the Sum of all the Nodes of a Binary Tree
- Program to Find the Total Number of Possible Binary Search Trees with N Keys
- Program to Implement Binary Tree using the Linked List
- Program to Search a Node in a Binary Tree
- Singly Linked List Examples
- Program to create and display a singly linked list
- Program to create a singly linked list of n nodes and count the number of nodes
- Program to create a singly linked list of n nodes and display it in reverse order
- Program to delete a new node from the beginning of the singly linked list
- Program to delete a new node from the middle of the singly linked list
- Program to delete a node from the end of the singly linked list
- Program to determine whether a singly linked list is the palindrome
- Program to find the maximum and minimum value node from a singly linked list
- Program to insert a new node at the middle of the singly linked list
- Program to insert a new node at the beginning of the singly linked list
- Program to insert a new node at the end of the singly linked list
- Program to remove duplicate elements from a singly linked list
- Program to search an element in a singly linked list
- Program to sort the elements of the singly linked list
- Program to swap nodes in a singly linked list without swapping data
- Program to swap the last element of the singly linked list from the first one
- Program to Create a Circular Linked List of N Nodes and Count the Number of Nodes
- Program to Create a Circular Linked List of N Nodes and Display it in Reverse Order
- Program to Create and Display a Circular Linked List
- Program to Delete a New Node From the Beginning of the Circular Linked List
- Program to Delete a New Node From the End of the Circular Linked List
- Program to Delete a New Node From the Middle of the Circular Linked List
- Program to Find the Maximum and Minimum Value Node From a Circular Linked List
- Program to Insert a New Node at the Beginning of the Circular Linked List
- Program to Insert a New Node at the End of the Circular Linked List
- Program to Insert a New Node at the Middle of the Circular Linked List
- Program to Remove Duplicate Elements From a Circular Linked List
- Program to Search an Element in a Circular Linked List
- Program to Sort the Elements of the Circular Linked List
- Program to Convert a Given Binary Tree to Doubly Linked List
- Program to Create a Doubly Linked List From a Ternary Tree
- Program to Create a Doubly Linked List of N Nodes and Count the Number of Nodes
- Program to Create a Doubly Linked List of N Nodes and Display it in Reverse Order
- Program to Create and Display a Doubly Linked List
- Program to Delete a New Node From the Beginning of the Doubly Linked List
- Program to Delete a New Node From the End of the Doubly Linked List
- Program to Delete a New Node From the Middle of the Doubly Linked List
- Program to Find the Maximum and Minimum Value Node From a Doubly Linked List
- Program to Insert a New Node at the Beginning of the Doubly Linked List
- Program to Insert a New Node at the End of Doubly Linked List
- Program to Insert a New Node at the Middle of Doubly Linked List
- Program to Remove Duplicate Elements From a Doubly Linked List
- Program to Rotate Doubly Linked List by N Nodes
- Program to Search an Element in a Doubly Linked List
- Program to Sort the Elements of the Doubly Linked List
- Program to Convert cm to Feet and Inches
- Program to Convert Feet to cm
- Program to Convert Feet to Inches
- Program to Convert Inches to cm
- Program to Convert Inches to Feet
- Program to Convert Kilometer to cm
- Pyramid Programs in VB
- Program to calculate Volume of Cone
- Write a Program to calculate the Perimeter of Hexagon
- Write a Program to calculate the Area of Rhombus
- Write a Program to calculate the surface Area of Cone
- Write a Program to calculate the Surface Area of Hemisphere
- Write a Program to find the Perimeter of Ellipse
- Write a program to calculate the Altitude of Isosceles Triangle
- Write a Program to calculate the Area of Isosceles Triangle
- Write a program to find the Volume of Tetrahedron
- Write a program to find the Area of an Icosahedron
- Write a program to find the Volume of Octahedron
- Write a program to find the Area of Tetrahedron
- Write a program to find the Surface Area of the Pentagonal Prism
- Write a program to find the Area of the Rectangular Prism
- Write a program to find the Surface Area of a Triangular Prism
- Write a Program to find the Area of Hexagonal Prism
- Write a Program to find the Volume of a Hexagonal Prism
- Write a program to find the Volume of the Rectangular Prism
- Program to Convert centimeter to millimeter
- Program to Convert centimeter to meter
- Program to Convert Feet to millimeter
- Program to Convert Meter to Centimeter
- Program to Convert mm to cm
- Program to Convert millimeter to Feet
- Program to Convert Feet to m
- Program to Convert Inches to meter
- Program to Convert Inches to mm
- Program to Convert m to Feet and Inches
- Write a program to calculate the Perimeter of a Rhombus
- Write a program to find the quotient and remainder
- Program to convert Kilobytes to bytes and bits
- Program to find the area and perimeter of the semicircle
- Program to find the area and perimeter of trapezium
- Program to find the type of triangle from the given coordinates
- Program to convert hours into minutes and seconds
- Program to convert temperature degree from Celsius to Kelvin
- Write a program to find the sum of even numbers

## Q. Program to calculate the difference between the sum of the odd level and even level nodes of a Binary Tree.## ExplanationIn 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- Define Node class which has three attributes namely: data, left, and right. Here, left represents the left child of the node and right represents the right child of the node.
- When a node is created, Assign the data part of a node with an appropriate value having its left and right child as NULL.
- Define another class which has an attribute root.
**Root**represents the root node of the tree having null value initially.
- The difference() will calculate the difference between the sum of nodes at the odd and even levels:
- Traverse through the binary tree level wise using Queues.
- Keep track of current level using the variable currentLevel.
- If the currentLevel is divisible by 2, then add all the values of nodes present in currentLevel to variable evenLevel. Else, add all the values of nodes to variable oddLevel.
- Calculate the difference by subtracting value present in evenLevel from oddLevel.
## Solution## Python
Difference between sum of odd level and even level nodes: 11 ## C
Difference between sum of odd level and even level nodes: 11 ## JAVA
Difference between sum of odd level and even level nodes: 11 ## C#
Difference between sum of odd level and even level nodes: 11 ## PHP
Difference between sum of odd level and even level nodes: 11 Next TopicPrograms List |

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

© Copyright 2024 Javatpoint. All Rights Reserved.