Searching Basics
Arraylists 👨💻
Linear Search? 👨💻
Binary Search?👨💻
Sorting Basics
Sorting in Arrays

Basic Algorithms
- Bubble Sort
- Selection Sort
- Insertion Sort
What is Sorting?
//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}
Check if Array is Sorted?
Bubble Sort

Key Idea
Take larger element to the end by repeatedly swapping the adjacent elements.
In-built Sort
Problems
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]
Subarray Sort

Homework! 👨💻
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
Check Subsequence

More techniques
Intermediate Course
Selection Sort

Key Idea
Repeatedly find the minimum element from unsorted part and putting it at the beginning.
Insertion Sort

Key Idea
Insertion sort is similar to playing cards in our hands.
Insert the card in its correct position in a sorted part.

[Java] Sorting & Searching
By Prateek Narang
[Java] Sorting & Searching
- 11