code.png
233.2 KB
Selection Sort in Java
We can create a java program to sort array elements using selection sort. In selection sort algorithm, we search for the lowest element and arrange it to the proper location. We swap the current element with the next lowest number
#Source_code
#Selection_Sort
#116
We can create a java program to sort array elements using selection sort. In selection sort algorithm, we search for the lowest element and arrange it to the proper location. We swap the current element with the next lowest number
#Source_code
#Selection_Sort
#116
What is Polymorphism?
Polymorphism refers to many forms, or it is a process that performs a single action in different ways. It occurs when we have many classes related to each other by inheritance. Polymorphism is of two different types, i.e., compile-time polymorphism and runtime polymorphism. One of the examples of Compile time polymorphism is that when we overload a static method in java. Run time polymorphism also called a dynamic method dispatch is a method in which a call to an overridden method is resolved at run time rather than compile time. In this method, the overridden method is always called through the reference variable. By using method overloading and method overriding, we can perform polymorphism. Generally, the concept of polymorphism is often expressed as one interface, and multiple methods. This reduces complexity by allowing the same interface to be used as a general class of action.
#Source_code
#OOP_Concepts_java
#Polymorphism
#117
Polymorphism refers to many forms, or it is a process that performs a single action in different ways. It occurs when we have many classes related to each other by inheritance. Polymorphism is of two different types, i.e., compile-time polymorphism and runtime polymorphism. One of the examples of Compile time polymorphism is that when we overload a static method in java. Run time polymorphism also called a dynamic method dispatch is a method in which a call to an overridden method is resolved at run time rather than compile time. In this method, the overridden method is always called through the reference variable. By using method overloading and method overriding, we can perform polymorphism. Generally, the concept of polymorphism is often expressed as one interface, and multiple methods. This reduces complexity by allowing the same interface to be used as a general class of action.
#Source_code
#OOP_Concepts_java
#Polymorphism
#117
What is Encapsulation ?
Encapsulation is one of the concepts in OOPs concepts; it is the process that binds together the data and code into a single unit and keeps both from being safe from outside interference and misuse. In this process, the data is hidden from other classes and can be accessed only through the current class’s methods. Hence, it is also known as data hiding. Encapsulation acts as a protective wrapper that prevents the code and data from being accessed by outsiders. These are controlled through a well-defined interface.
#Source_code
#OOP_Concepts_java
#Encapsulation
#118
Encapsulation is one of the concepts in OOPs concepts; it is the process that binds together the data and code into a single unit and keeps both from being safe from outside interference and misuse. In this process, the data is hidden from other classes and can be accessed only through the current class’s methods. Hence, it is also known as data hiding. Encapsulation acts as a protective wrapper that prevents the code and data from being accessed by outsiders. These are controlled through a well-defined interface.
#Source_code
#OOP_Concepts_java
#Encapsulation
#118
* Tight coupling: If one class is strongly interrelated to another class, it is said to have a tight coupling with that class.
#Source_code
#OOP_Concepts_java
#coupling_in_java
#119
#Source_code
#OOP_Concepts_java
#coupling_in_java
#119
* Loose coupling: If one class is weakly interrelated to another class ,it is said to have loose coupling with that class. Loose coupling is preferred over tight coupling. A class can achieve this with the help of interfaces, as shows.
#Source_code
#OOP_Concepts_java
#coupling_in_java
#120
#Source_code
#OOP_Concepts_java
#coupling_in_java
#120
* Low Cohesion: In the following code, we have a class called Book. But it is less cohesive because it comprises less focussed and independent attributes and methods to the class. This class should contain information related to the Book. Therefore, the person's name and age method are making this classless cohesive.
#Source_code
#Cohesion_In_Java
#Low_Cohesion
#OOP_Concepts_java
#121
#Source_code
#Cohesion_In_Java
#Low_Cohesion
#OOP_Concepts_java
#121
code.png
410.4 KB
Association is relation between two separate classes that establishes with the help of their Object.
#Source_code
#OOP_Concepts_java
#Association_in_java
#123
#Source_code
#OOP_Concepts_java
#Association_in_java
#123
A method that has the static keyword in the declaration is known as the static method. In other words, a method that belongs to a class rather than an instance of a class is known as a static method. We can also create a static method by using the keyword static before the method name. The main benefit of a static method is that we can invoke the static method without even creating an object. It can access static data members and also change their values and is also used to create an instance method. The main() method is a common example of the static method.
#Source_code
#OOP_Concepts_java
#Static_method_in_java
#126
#Source_code
#OOP_Concepts_java
#Static_method_in_java
#126
A method that is declared final is called a final method. We cannot override a final method. This means the child class can still call the final method of the parent class without any problem, but it cannot override it. This is because the main purpose of making a method final is to stop the modification of the method by the sub-class.
#Source_code
#OOP_Concepts_java
#Final_Method_in_java
#128
#Source_code
#OOP_Concepts_java
#Final_Method_in_java
#128
Java
A method that is declared final is called a final method. We cannot override a final method. This means the child class can still call the final method of the parent class without any problem, but it cannot override it. This is because the main purpose of…
Instead of modifying the method, we can use it as shown:
#Source_code
#OOP_Concepts_java
#Final_Method_in_java
#129
#Source_code
#OOP_Concepts_java
#Final_Method_in_java
#129
code.png
1.5 MB
Magnet Puzzle
We are given a set of bipolar magnets, each domo-shaped. The objective is to place magnet on an M * N board, which satisfies a set of conditions where both M and N are not odd.
The time complexity of the above solution is exponential and requires additional space for the recursion (call stack)
#Source_code
#Data_Structures
#Magnet_Puzzle
#130
We are given a set of bipolar magnets, each domo-shaped. The objective is to place magnet on an M * N board, which satisfies a set of conditions where both M and N are not odd.
The time complexity of the above solution is exponential and requires additional space for the recursion (call stack)
#Source_code
#Data_Structures
#Magnet_Puzzle
#130
Java
code.png
For instance, the following problem has the solution on its right.
Each 2 * 1 or 1 * 2 grid in the board can contain a magnet or empty. The blank entry will be indicated by X's, and the magnet will be represented by + and - (For the positive and negative end, respectively). The digits along the board's left and top sides represent the count of + squares in corresponding rows or columns. Similarly, those along the right and bottom show the total number of - signs in particular rows or columns. Rows and columns for which no number is mentioned can have any number of + or - signs. The puzzle solution must also satisfy the constraint that no two adjacent squares can have the same sight.
#Data_Structures
#Magnet_puzzle
#130
Each 2 * 1 or 1 * 2 grid in the board can contain a magnet or empty. The blank entry will be indicated by X's, and the magnet will be represented by + and - (For the positive and negative end, respectively). The digits along the board's left and top sides represent the count of + squares in corresponding rows or columns. Similarly, those along the right and bottom show the total number of - signs in particular rows or columns. Rows and columns for which no number is mentioned can have any number of + or - signs. The puzzle solution must also satisfy the constraint that no two adjacent squares can have the same sight.
#Data_Structures
#Magnet_puzzle
#130
code.png
563.2 KB
Quickselect Algorithm
Quickselect is a selection algorithm to find the k'th smallest element in an unordered list. It is closely related to the Quicksort sorting algorithm. Like Quicksort, it is efficient traditionally and offers good average-case performance, but has a poor worst-case performance.
#Source_code
#Quickselect_Algorithm
#131
Quickselect is a selection algorithm to find the k'th smallest element in an unordered list. It is closely related to the Quicksort sorting algorithm. Like Quicksort, it is efficient traditionally and offers good average-case performance, but has a poor worst-case performance.
#Source_code
#Quickselect_Algorithm
#131
This media is not supported in your browser
VIEW IN TELEGRAM
A new year means a new chapter. I hope 2024 is an incredible part of your story! It feels like just yesterday we were celebrating last New Year's 😅! Time flies when you're with the one you love. Happy New Year!☺️😁✨🌟⛄️
Find the missing term in a sequence in logarithmic time
Given the missing term in a sequence in logarithmic time
#Source_code
#Data_structure
#132
Given the missing term in a sequence in logarithmic time
#Source_code
#Data_structure
#132