Pages

Showing posts with label Java Program. Show all posts
Showing posts with label Java Program. Show all posts

Tuesday, October 27, 2020

Java Program to Find Transpose of a Matrix

1. Overview

In this article, you'll learn how to find the transpose of a given matrix using a simple for loop.

You can go thorough the previous articles on addition and multiplication of two matrices using arrays.

Transpose is nothing but a swapping the rows with columns and also order will be swapped. Finally, it produces the new matrix.

Matrix M :    [A11, A12 

	      A21, A22

	      A31, A32]


Transpose of Matrix M: [ A11, A21, A31

			 A12, A22, A32]
 

Order of Transpose Matrix:

Matrix M order: 3 X 2 

Transpose of Matrix M order: 2 X 3

Java Program to Find Transpose of a Matrix

Wednesday, December 11, 2019

Java Program to "Run Length Encoding (RLE)" - String Compression

1. Introduction


In today's article, You will learn What is the "Run Length Encoding" technique which is heavily used in string data compression. This is an experienced java interview question for 4-6 years developers. Earlier days this is used to compress the black and white photos.


Run Length Encoding is abbreviated as "RLE".

Run-length encoding (RLE) is a form of lossless data compression in which runs/flows of data are stored as a single data value and count, rather than as the original run.
Java Program to "Run Length Encoding (RLE)" - String Compression



This works for only sequences in which the same data value occurs in many consecutive data elements.

Examples:

Input: aaabbccccd
Output:a3b2c4d1

Input: xxxyyziiii
Output: x3y2z1i4

Input: kkkkkkiiiiiiuuuuasdfgllll
Output: k6i6u4a1s1d1f1l4

All of the above examples are valid. If the string "aaabba" is invalid because character 'a' is repeated in non-consecutive which is appeared after character 'b'. If the string is invalid then it may produce unexpected results. Please keep in mind this note before implementing it in real-time applications.

Tuesday, May 14, 2019

Insert a String into another String in Java

1. Overview

We'll demonstrate how to add a string into another string at any given position in java.

We will write implementation in 3 ways which iterate through the string till given position and then add new string, finally add the remaining original string.

As we know String class is immutable in java. Any operation on string will result a new String.

Insert a String into another String