Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Server Side Programming Articles - Page 1572 of 2650
3K+ Views
Problem Statement Given a sentence, create a program in Java that swaps the first and last characters of each word efficiently as given below − Input That is a sample Output The string after swapping the last characters of every word is : thaT si a eampls Steps to swap first and last characters of words in a sentence Below are the steps to swap first and last characters of words in a sentence − Convert string to character array. Iterate through the character array using while loop to identify the ... Read More
4K+ Views
In this article, we will learn to merge two files into a third file in Java. Combining the contents of two files into a third file is a typical operation in file handling, frequently needed to aggregate data. Java offers efficient facilities such as BufferedReader and PrintWriter to accomplish this easily. ApproachThe following are the steps to merge the contents of two files into a third file in Java− Read the contents of the first file line by line using a BufferedReader. Write each line to the third file using a ... Read More
733 Views
In this article, we will learn to write a program for shell sort using Java. In the program, we’ll apply this technique to sort an array and observe how the algorithm optimizes the sorting process by reducing the interval between elements. Shell sort Shell sort is a sorting technique that is similar to insertion sort, wherein elements are sorted which are at far ends (either end) of the array. This way, the interval size between the next and the second to last element reduces. This happens for all the elements in the array until the interval distance is reduced to ... Read More
466 Views
In this article, we will learn Pigeonhole Sort in Java, a sorting algorithm designed for arrays with a small range of integer values. It organizes elements into "pigeonholes" based on their values and then reconstructs the sorted array. We’ll discuss two approaches: a basic method using arrays and an optimized approach using LinkedLists. What is Pigeonhole Sort? Pigeonhole Sort works by distributing elements into a range of buckets based on their values. It is most effective when the range of input values is relatively small compared to the size of the dataset. The algorithm ensures stability and simplicity in sorting ... Read More
464 Views
Radix sort is a sorting technique that sorts the elements based on every digit in every element (or number). Based on the ones place digit (which is also known as least significant digit) and tens place digit (which is also known as most significant digit), hundreds place digit, and so on, the elements are sorted.ExampleFollowing is an example for Radix Sort in Java − Live Demoimport java.util.*; public class my_radix_sorting { static int get_max_val(int my_arr[], int arr_len) { int max_val = my_arr[0]; for (int i = 1; i < arr_len; i++) ... Read More
726 Views
In this article, we will learn pancake sorting which is a unique way to sort an array by flipping sections of it. The algorithm finds the largest unsorted element, flipping it to the front, and then flipping it to its correct position. Although not the fastest sorting method, it’s an interesting and creative way to learn about problem-solving and data manipulation. This article explains the algorithm in simple steps and shows how to implement it in Java. What is Pancake Sorting? Pancake sorting is a sorting technique that resembles selection sort, i.e. sorting the largest element first thereby reducing the ... Read More
171 Views
In this tutorial, we will be discussing a program to find maximum sum subsequence with at-least k distant elements.For this we will be provided with an array containing integers and a value K. Our task is to find the subsequence having maximum sum such that all the elements are at least K elements apart.Example Live Demo#include using namespace std; //finding maximum sum subsequence int maxSum(int arr[], int N, int k) { int MS[N]; MS[N - 1] = arr[N - 1]; for (int i = N - 2; i >= 0; i--) { if (i ... Read More
201 Views
In this tutorial, we will be discussing a program to find maximum sum subarray such that start and end values are same.For this we will be provided with an array containing integers. Our task is to find the subarray with the maximum sum such that the elements are both its ends are equal.Example Live Demo#include using namespace std; //finding the maximum sum int maxValue(int a[], int n) { unordered_map first, last; int pr[n]; pr[0] = a[0]; for (int i = 1; i < n; i++) { pr[i] = pr[i - 1] + a[i]; ... Read More
219 Views
In this tutorial, we will be discussing a program to find maximum sum rectangle in a 2D matrix.For this we will be provided with a matrix. Our task is to find out the submatrix with the maximum sum of its elements.Example Live Demo#include using namespace std; #define ROW 4 #define COL 5 //returning maximum sum recursively int kadane(int* arr, int* start, int* finish, int n) { int sum = 0, maxSum = INT_MIN, i; *finish = -1; int local_start = 0; for (i = 0; i < n; ++i) { sum += arr[i]; ... Read More
123 Views
In this tutorial, we will be discussing a program to find maximum sum possible for a sub-sequence such that no two elements appear at a distance < K in the array.For this we will be provided with an array containing N intergers and a value K. Our task is to find the maximum sum of the subsequence including elements not nearer than K.Example Live Demo#include using namespace std; //returning maximum sum int maxSum(int* arr, int k, int n) { if (n == 0) return 0; if (n == 1) return arr[0]; ... Read More