Programming Articles - Page 2477 of 3366

3-Way QuickSort (Dutch National Flag)

Arnab Chakraborty
Updated on 20-Aug-2019 06:56:42

2K+ Views

Here we will see the quicksort technique but we will use three-way quicksort. The basic quicksort technique is just finding an element as pivot then partition the array around pivot, after that, recur for sub arrays on left and right of the pivot.The three-way quicksort is similar, but there are three sections. array arr[1 to n] is divided into three parts.arr[1 to i]arr[i + 1, j]arr[j + 1, n]Algorithmpartition(arr, left, right, i, j) −begin    if right – left

How to select different cells of a JTable programmatically in Java?

raja
Updated on 12-Feb-2020 06:17:43

1K+ Views

A JTable is a subclass of JComponent class and it can be used to create a table with information displayed in multiple rows and columns. When a value is selected from a JTable, a TableModelEvent is generated, which is handled by implementing a TableModelListener interface.In general, a user can select the rows and columns manually in a JTable, we can also select different cells of a JTable programmatically using setRowSelectionInterval() and setColumnSelectionInterval() methods of JTable class.Exampleimport java.awt.*; import java.awt.event.*; import javax.swing.*; public class JTableCellSelectionTest extends JFrame {    private JTable table;    public JTableCellSelectionTest() {       setTitle("JTableCellSelection Test");       Object[][] data = ... Read More

C++: Methods of code shortening in competitive programming?

Arnab Chakraborty
Updated on 19-Aug-2019 14:35:42

445 Views

In this section we will see some examples of code shortening strategy for competitive programming. Suppose we have to write some large amount of codes. In that code, we can follow some strategy to make them more short.We can change the type-name to make it short. Please check the code to get the ideaExample Code#include using namespace std; int main() {    long long x = 10;    long long y = 50;    cout

A Space Optimized Solution of LCS in C Program?

Arnab Chakraborty
Updated on 19-Aug-2019 14:28:42

237 Views

Here we will see one space optimized approach for LCS problem. The LCS is the longest common subsequence. If two strings are “BHHUBC” and “HYUYBZC”, then the length of the subsequence is 4. One dynamic programming approach is already their, but using the dynamic programming approach, it will take more space. We need table of order m x n, where m is the number of characters in first string, and n is the number of characters in the second string.Here we will see how to implement this algorithm using O(n) amount of auxiliary space. If we observe the old approach ... Read More

A Peterson Graph Problem in C Program?

Arnab Chakraborty
Updated on 19-Aug-2019 14:22:04

328 Views

Suppose we have one graph like below. That graph is Peterson graph. The vertices are numbered from 0 through 9. Each vertex has some letters. Let consider one walk W, in that graph, where L vertices are used. A string S with L letters is realized by the walk W when the letter sequence in W and S are same. We can visit the vertices multiple times.For example, one string S is like “ABBECCD”, this is realized by the walk (0, 1, 6, 9, 7, 2, 3). Our task is to find such walk, and if that walk is present, ... Read More

A C/C++ Pointer Puzzle?

Arnab Chakraborty
Updated on 19-Aug-2019 14:15:22

407 Views

Suppose we have one integer variable whose size is 4 byte, another pointer variable is there, whose size is 8 bytes. So what will be the output of the following?Example#include using namespace std; main() {    int a[4][5][6];    int x = 0;    int* a1 = &x;    int** a2 = &a1;    int*** a3 = &a2;    cout

3-digit Osiris number C Program?

Arnab Chakraborty
Updated on 19-Aug-2019 14:07:54

185 Views

Here we will see the Osiris number. An Osiris number is such kind of number that are equal to the sum of permutations of sub-samples of their own digits. Suppose the number is 132. Then if we calculate {12 + 21 + 13 + 31 + 23 + 32} this is also 132. So the number is Osiris number. We have to check whether the given number is Osiris number or not.Approach is simple. If we analyze the numbers, each digit is occurring twice so they are in ones position and tens position. So we can check by multiplying 11 ... Read More

How can we sort a string without using predefined methods in Java?

Vivek Verma
Updated on 14-May-2025 12:39:37

7K+ Views

The java.lang.String class represents an immutable sequence of characters and cannot be changed once created. We need to instantiate this class or assign values directly to its literal to create a string in Java. The String class does not provide any built-in method to sort the contents of a string. To sort a String, we need to convert it into a character array using the toCharArray() method and sort the array. To sort a character array, we can either use the Arrays.sort() method or use sorting algorithms.  Since the given task is to sort a string without using any predefined methods, we ... Read More

Add the elements of given arrays with given constraints?

sudhir sharma
Updated on 19-Aug-2019 12:24:27

278 Views

For this problem, to add elements of two given arrays we have some constraints based on which the added value will get changed. the sum of two given arrays a[] & b[] is stored into to third array c[]in such a way that they gave the some of the elements in single digit. and if the number of digits of the sum is greater than 1, then the element of the third array will split into two single-digit elements. For example, if the sum occurs to be 27, the third array with store it as 2, 7.Input: a[] = {1, ... Read More

What is the use of Object Cloning in Java?

Vivek Verma
Updated on 27-May-2025 15:54:32

2K+ Views

The article will explain the use of object cloning in Java and provide an appropriate example to clarify the problem. What is the Object Cloning in Java? In Java, object cloning is a way to create an exact copy of an object. We can use the clone() method provided by the Object class to create a clone of an object. When an object is cloned, a new instance of the same class is created, and the fields of the original object are copied to the new object. The Cloneable interface must be implemented by a class whose object is ... Read More

Advertisements