code
342.3 KB
In-place merge two sorted arrays
The time complexity of the above solution is O(m.n), where m is the size of the first array and n is the size of the second array. The solution doesn’t require any extra space. The problem, in fact, can be solved in linear time and constant space.
#Data_structure
#Source_code
The time complexity of the above solution is O(m.n), where m is the size of the first array and n is the size of the second array. The solution doesn’t require any extra space. The problem, in fact, can be solved in linear time and constant space.
#Data_structure
#Source_code
Java
code
Given two sorted arrays, X[] and Y[] of size m and n each, merge elements of X[] with elements of array Y[] by maintaining the sorted order, i.e., fill X[] with the first m smallest elements and fill Y[] with remaining elements.
#Data_structure
#Data_structure
In this program, we need to copy all the elements of one array into another. This can be accomplished by looping through the first array and store the elements of the first array into the second array at the corresponding position.
#Source_code
#78
#Source_code
#78
Using clone() Method
The clone() method is the method of Object class. It creates a copy of an object and returns the same copy. The JVM creates a new object when the clone() method is invoked. It copies all the content of the previously created object into new one object. Note that it does not call any constructor. We must implement the Cloneable interface while using the clone() method. The method throws CloneNotSupportedException exception if the object's class does not support the Cloneable interface. The subclasses that override the clone() method can throw an exception if an instance cannot be cloned
#Source_code
#57
The clone() method is the method of Object class. It creates a copy of an object and returns the same copy. The JVM creates a new object when the clone() method is invoked. It copies all the content of the previously created object into new one object. Note that it does not call any constructor. We must implement the Cloneable interface while using the clone() method. The method throws CloneNotSupportedException exception if the object's class does not support the Cloneable interface. The subclasses that override the clone() method can throw an exception if an instance cannot be cloned
#Source_code
#57
The idea is to traverse both trees and compare values at their root node. If the value matches, recursively check if the first tree’s left subtree is identical to the left subtree of the second tree and the right subtree of the first tree is identical to the right subtree of the second tree. If the value at their root node differs, the trees violate data property. If at any point in the recursion, the first tree is empty and the second tree is non-empty, or the second tree is empty and the first tree is non-empty, the trees violate structural property, and they cannot be identical.
#Data_structure
#Source_code
#Data_structure
#Source_code
code.png
511.2 KB
ATM program Java
In Java, we can create an ATM program for representing ATM transection. In the ATM program, the user has to select an option from the options displayed on the screen. The options are related to withdraw the money, deposit the money, check the balance, and exit.
#Source_code
#79
In Java, we can create an ATM program for representing ATM transection. In the ATM program, the user has to select an option from the options displayed on the screen. The options are related to withdraw the money, deposit the money, check the balance, and exit.
#Source_code
#79
Sunny Number
A number is called a sunny number if the number next to the given number is a perfect square. In other words, a number N will be a sunny number if N+1 is a perfect square.
Let's understand it through an example.
#Source_code
#72
A number is called a sunny number if the number next to the given number is a perfect square. In other words, a number N will be a sunny number if N+1 is a perfect square.
Let's understand it through an example.
#Source_code
#72
Java
Sunny Number A number is called a sunny number if the number next to the given number is a perfect square. In other words, a number N will be a sunny number if N+1 is a perfect square. Let's understand it through an example. #Source_code #72
Steps to Find Sunny Number
The logic is very simple. To find the sunny number, we need only to check whether N+1 is the perfect square or not.
Read or initialize a number (num).
Add 1 to the given number i.e. num+1.
Find the square root of num+1.
If the square root is an integer, the given number is sunny, else not a sunny number.
Let's implement the above steps in a Java program.
#Output
#72
The logic is very simple. To find the sunny number, we need only to check whether N+1 is the perfect square or not.
Read or initialize a number (num).
Add 1 to the given number i.e. num+1.
Find the square root of num+1.
If the square root is an integer, the given number is sunny, else not a sunny number.
Let's implement the above steps in a Java program.
#Output
#72
Forwarded from Java
Find prime numbers between two numbers
You can also find prime numbers between two specified numbers.
#Source_code
#11
You can also find prime numbers between two specified numbers.
#Source_code
#11