Programming Articles

Page 1302 of 2547

Find the largest Complete Subtree in a given Binary Tree in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 374 Views

ConceptWith respect of a given Binary Tree, the task is to determine the size of maximum complete sub-tree in the given Binary Tree.Complete Binary Tree – A Binary tree is treated as Complete Binary Tree if all levels are completely filled without possibly the last level and the last level has all keys as left as possible.It has been noted that all Perfect Binary Trees are Complete Binary tree but reverse in NOT true. It has been seen that if a tree is not complete then it is also not Perfect Binary Tree.Input       2      / \ ...

Read More

Find the Largest Cube formed by Deleting minimum Digits from a number in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 263 Views

ConceptWith respect of given number N, our task is to determine the largest perfect cube that can be formed by deleting minimum digits (possibly 0) from the number. So any digit can be deleted from the given number to reach the target.A is called a perfect cube if A = B^3 for some integer B.It has been seen that If the number cannot be perfect cube print -1.ExampleLet N = 1025. It has been seen that if we delete 0 from the above number we will get 125 as remaining number, which is cube root of 5(5 * 5 * ...

Read More

Java Program for Standard Normal Distribution (SND)

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 433 Views

Following is the Java program for Standard Normal Distribution −Exampleimport java.io.*; import java.util.*; public class Demo{    public static void main(String[] args){       double std_dev, val_1, val_3, val_2;       val_1 = 68;       val_2 = 102;       val_3 = 26;       std_dev = (val_1 - val_2) / val_3;       System.out.println("The standard normal deviation is: " + std_dev);    } }OutputThe standard normal deviation is: -1.3076923076923077A class named Demo contains the main function, where certain double values are defined, and the formula for standard deviation is applied ((val_1 - val_2) / val_3) on these values and the resultant output is displayed on the console.

Read More

Java Program for Reversal algorithm for array rotation

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 403 Views

Following is the Java program to implement Reversal algorithm for array rotation −Exampleimport java.io.*; public class Demo{    static void rotate_left(int my_arr[], int no_of_rotation){       int n = my_arr.length;       array_reversal(my_arr, 0, no_of_rotation - 1);       array_reversal(my_arr, no_of_rotation, n - 1);       array_reversal(my_arr, 0, n - 1);    }    static void array_reversal(int my_arr[], int start, int end){       int temp;       while (start < end) {          temp = my_arr[start];          my_arr[start] = my_arr[end];          my_arr[end] = temp; ...

Read More

Check for balanced parentheses in an expression - O(1) space - O(N^2) time complexity in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 539 Views

ConceptWith respect of given a string str containing characters ‘(‘, ‘)’, ‘{‘, ‘}’, ‘[‘ and ‘]’, the task is to find if brackets are balanced or not.Brackets are denoted as balanced if −We close open brackets must be closed by the same type of brackets.Again we close open brackets according to the correct order.Input − str = “(()){}”Output − YesInput − str = “))(([][”Output − NoMethodAssign two variables a and b to keep track of two brackets to be compared.A count should be maintained whose value increments on encountering opening bracket and decrements on encountering a closing bracket.Assign b = ...

Read More

Static Control Flow in Java

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 1K+ Views

The Static Control Flow identify static members, executes static blocks, and then executes the static main method. Let us see an example −Examplepublic class Demo{    static int a = 97;    public static void main(String[] args){       print();       System.out.println("The main method has completed executing");    }    static{       System.out.println(a);       print();       System.out.println("We are inside the first static block");    }    public static void print(){       System.out.println(b);    }    static{       System.out.println("We are inside the second static block");    }   ...

Read More

Check if a given Binary Tree is height balanced like a Red-Black Tree in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 331 Views

ConceptWith respect of a Red-Black Tree, the largest height of a node is at most double the minimum height.For a given Binary Search Tree, we need to verify for following property.With respect of every node, length of the longest leaf to node path has not more than double the nodes on shortest path from node to leaf.Examples13    41 \    / \ 15  11 101 \   /    \ 17 61 151Above tree cannot be a Red-Black Tree Above tree can be Red-Black Tree with any color assignmentMax height of 13 is 1Min height of 13 is 3  ...

Read More

Static method in Interface in Java

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 1K+ Views

To implement static method in Interface, the Java code is as follows −Exampleinterface my_interface{    static void static_fun(){       System.out.println("In the newly created static method");    }    void method_override(String str); } public class Demo_interface implements my_interface{    public static void main(String[] args){       Demo_interface demo_inter = new Demo_interface();       my_interface.static_fun();       demo_inter.method_override("In the override method");    }    @Override    public void method_override(String str){       System.out.println(str);    } }OutputIn the newly created static method In the override methodAn interface is defined, inside which a static function is defined. Another ...

Read More

Check if a given Binary Tree is Heap in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 481 Views

ConceptWith respect of a given binary tree, we need to verify whether it has heap property or not, Binary tree need to satisfy the following two conditions for being a heap –Binary tree should be a complete tree (i.e. all levels except last should be full).Binary tree's every node’s value should be greater than or equal to its child node (considering max-heap).ExampleWith respect of following example this tree contains heap property –The following example does not have heap property –MethodIt is required to verify each of the above condition separately, for verifying completeness isComplete(This function checks if the binary tree ...

Read More

Check if a given string is a valid number in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 596 Views

ConceptIt should be validated if a given string is numeric.Input − str = "12.5"Output − trueInput − str = "def"Output − falseInput − str = "2e5"Output − trueInput − 10e4.4Output − falseMethodWe have to handle the following cases in the code.We have to ignore the leading and trailing white spaces.We have to ignore the ‘+’, ‘-‘ and’.’ at the start.We have to ensure that the characters in the string belong to {+, -, ., e, [0-9]}We have to ensure that no ‘.’ comes after ‘e’.A digit should follow a dot character ‘.’.We have to ensure that the character ‘e’ should ...

Read More
Showing 13011–13020 of 25,466 articles
Advertisements