Basic Algorithms
//Unsorted Array
a = {10,12,5,4,1,3,2};
//Sorted Array in Increasing Order
a = {1,2,3,4,5,10,12}
//Sorted Array in Decreasing Order
a = {12,10,5,4,3,2,1}
Key Idea
Take larger element to the end by repeatedly swapping the adjacent elements.
Given an array of size at-least two, find the smallest subarray that needs to be sorted in place so that entire input array becomes sorted.
If the input array is already sorted, the function should return [-1,-1], otherwise return the start & end index of smallest subarray.
Sample Input
a1 = [1, 2, 3, 4, 5, 8, 6, 7, 9, 10, 11] Sample Output
[5,7]
Given two non-empty arrays, write a function that determines whether the second arrays is subsequence of first one.
Sample Input
[5, 1, 22, 25, 6, -1, 8, 10]
[1, 22, 8]
Sample Output
Yes
Key Idea
Repeatedly find the minimum element from unsorted part and putting it at the beginning.
Key Idea
Insertion sort is similar to playing cards in our hands.
Insert the card in its correct position in a sorted part.