Sorting an array means that we could organize things or make things go from decending to ascending order. This has helped many people to organize things that dont look in order. Unlike the encryption method which has many words that dont make sense or cant be read at all this sorting allows it to have it in order. There are many types or sorting an array the first one swaps one letter to the other if it is smaller than the other one. This process repeats itself until the code stops. Insertion sort is one of the simplest and efficient comparison based algorithm, this is best for school based learning and is a good way to test the skills of the students.
This type of algorithm makes use of sorting an array one at a time. It is intuitive and straightforward to understand and implement. The main idea behind Insertion Sort is to divide the input array into two parts: the sorted part and the unsorted part. Initially, the sorted part consists of a single element—the first element of the array. The algorithm then iterates through the unsorted part, one element at a time, and inserts each element into its correct position in the sorted part. For example
public static void main(String[] args) {
int[] arr = {12, 11, 13, 5, 6};
insertionSort(arr);
System.out.println("Sorted array:");
for (int num : arr) {
System.out.print(num + " ");
In this code it puts the number 6 in the first position while the last number which is 13 is put last. This code tells us that we could do this with any thing we want may it be words or numbers.
Posted using Honouree