AYUSH MISHRA

AYUSH MISHRA

112 Articles Published

Articles by AYUSH MISHRA

112 articles

Count the number of nodes in a complete Binary tree using JavaScript

AYUSH MISHRA
AYUSH MISHRA
Updated on 18-May-2025 1K+ Views

A binary tree is a non-linear data structure where each node can have at most two children i.e. left children and right children. In this article, we are going to discuss how to count nodes in a complete binary tree using JavaScript. What is a Complete Binary Tree? A complete binary tree is a binary tree in which all the nodes are completely filled except possibly the last level of the tree, and the last node has all its nodes on the left side as possible. Below are examples to demonstrate the above problem, clearly: Example 1 Input: ...

Read More

Python Program to Print Hollow Rectangle pattern

AYUSH MISHRA
AYUSH MISHRA
Updated on 05-May-2025 2K+ Views

When we start programming then printing different star patterns helps us build our logic and problem-solving skills. One of the easiest and beginner patterns is the hollow rectangle pattern. In this article, we are going to learn how we can print the hollow rectangle pattern using different approaches in Python. Hollow Rectangle Pattern A Hollow rectangle pattern is a rectangle-shaped pattern printing of stars where the stars are present only on the boundaries of the rectangle. The rectangle is hollow, i.e., the stars are printed only on the boundaries of the rectangle, while the inner area remains empty. ***** ...

Read More

Python Program to count nodes in a binary tree

AYUSH MISHRA
AYUSH MISHRA
Updated on 02-May-2025 3K+ Views

In this article, we are going to learn how we can count the total number of nodes in a binary tree in Python, using different approaches. A binary tree is a data structure in which each node can have at most two children. The two children node of a binary tree are called the left child and the right child. We have to calculate the total number of nodes present in the binary tree. Scenario 1 Input: Binary Tree = 1 2 3 4 5 Output: Total number of nodes: 5 Above-given binary tree has five nodes: 1, 2, ...

Read More

Find the number that appears once, and the other numbers twice in Java

AYUSH MISHRA
AYUSH MISHRA
Updated on 30-Apr-2025 5K+ Views

In this problem, we are given an array of integers. In the given array, each element occurs two times except one element, which occurs only once. We have to find the number that appears only once. In this article, we are going to learn how we can find the number that appears once, and all other numbers appear twice in Java. Scenario 1 All other numbers except 4 occur twice, so 4 is the only number that appears only once. Input: [ 1, 2, 3, 3, 2, 4, 1, 5, 5] Output: 4 Scenario 2 All other numbers except ...

Read More

C++ Program to Rotate Array Left by One Position

C++
AYUSH MISHRA
AYUSH MISHRA
Updated on 30-Apr-2025 9K+ Views

Rotating an array means shifting the elements of an array in a specific direction while maintaining their relative order. For example, if the array {6, 12, 18, 24, 30} is rotating it left once will result in {12, 18, 24, 30, 6}. In this article, we are given an array and need to shift all elements one step to the left, with the first element moving to the last position. Example Here is an example of left rotation of elements in array by one place. Input: array = {5, 10, 15, 20, 25} Output: array = {10, 15, ...

Read More

C++ Program to Find Sum of Leaf Node in Binary Tree

C++
AYUSH MISHRA
AYUSH MISHRA
Updated on 28-Apr-2025 5K+ Views

We can find the sum of leaf nodes in a binary tree using an iterative and a recursive approach. This problem has many real-life applications, such as analyzing hierarchies, calculating final results in decision trees, or summing final nodes in various kinds of trees used in computer algorithms. In this article, we are going to learn how can find the sum of all leaf nodes in a binary tree in the C++ language. What are Leaf Nodes in a Binary Tree? The leaf nodes of a binary tree are the nodes that do not have any children. Both the ...

Read More

Find the Angle Between Hour and Minute Hands of a Clock in C#

AYUSH MISHRA
AYUSH MISHRA
Updated on 28-Apr-2025 7K+ Views

The calculation of the angle between the hour and minute hands of a clock is a common problem in Logical Reasoning and programming. This calculation is used in various applications, such as analog clock simulations, scheduling software, and time-based animations In this article, we are going to discuss how we can calculate the angle between the hour and minute hands of a clock in C# using different approaches: What is the Angle Between the Hour and Minute Hands? The angle between the hour and minute hands is determined based on the positions of both hands on the clock ...

Read More

Replace elements by its rank in the array in JavaScript

AYUSH MISHRA
AYUSH MISHRA
Updated on 24-Apr-2025 4K+ Views

In this problem, we are given an array, and we have to replace each element with its rank. The rank of an element is the position of the element when element of the array is arranged in sorted order. In this article, we are going to learn about various approaches to replacing elements with their rank in an array using JavaScript. Below are the examples to understand the problem clearly - Example 1: Input: arr = [40, 10, 20, 30] Output: [4, 1, 2, 3] Explanation: The sorted, unique array is: [10, 20, ...

Read More

Kth largest Element in a 2D matrix where each row and column is sorted in C++

C++
AYUSH MISHRA
AYUSH MISHRA
Updated on 24-Apr-2025 909 Views

Finding the Kth largest element in a 2D matrix where each row and column is sorted is a common problem in computer science. This problem has many real-life applications, such as a ranking system, where we need to find the Kth highest score in a sorted dataset. In this article, we are going to discuss how we can find the Kth largest element in a 2D matrix e where each row and column is in sorted order in the C++ language. What is the Kth Largest Element? The Kth largest element refers to an element that is placed at ...

Read More

Swap all odd and even bits using C++

C++
AYUSH MISHRA
AYUSH MISHRA
Updated on 22-Apr-2025 5K+ Views

We can swap all odd and even bits in a given integer. Swapping of odd and even bits means changing the bits present at odd positions with the bits at even positions in a binary representation of a number. One real-life application is optimizing data storage or modifying data patterns in memory. In this article, we are going to learn how we can swap all odd and even bits of a number in C++ using different approaches. Formula for Swapping Odd and Even Bits Extract all even-positioned bits using a bit mask and shift ...

Read More
Showing 1–10 of 112 articles
« Prev 1 2 3 4 5 12 Next »
Advertisements