## Binary Search

public class BinarySearch { static int search(int arr[], int el) { int l = 0; int h = arr.length - 1; while(l <= h){ int mid = (l + h)…

## Linear Search

public class LinearSearch { static int search(int arr[], int el) { for (int i = 0; i < arr.length; i++) { if (arr[i] == el) { return i + 1;…

## Recursion

When a function calls itself it is known as recursion. Program to find factorial of no using recursion public class FactorialUsingRecursion { public static void main(String[] args) { System.out.println(fact(5)); }…

## Time Complexities Table

Here is a list of some of the common time complexities. Time ComplexitiesNameExampleO(1)Constant- Accessing an element of an array- Adding element at beginning of a linked listO(log n)Logarithmic- Finding an…

## Implementing Queue using Arrays

public class Queue { private int front, rear, capacity; private int[] queue; Queue(int size) { this.front = 0; this.rear = 0; this.capacity = size; this.queue = new int[capacity]; } void…

## How to Compare Algorithms

We can compare algorithms based on the following method Execution Time We can compare algorithm based on the time it takes to execute some input. But the thing is the…

## Quick Sort

Quick sort Algorithm low, high => represents start and end index of arrayquickSort(arr[], low, high){if(low < high){pi = partition(arr, low, high);quickSort(arr, low, pi - 1);quickSort(arr, pi + 1, high);}} Code…

## Merge Sort

merge sort package sorting; import java.util.Arrays; public class MergeSort { public static void main(String[] args) { int[] arr = new int[]{5,4,3,2,1,23,2,4,1}; mergeSort(arr, 0, arr.length - 1); System.out.println(Arrays.toString(arr)); } static void…

## Selection Sort

selection sort package sorting; import java.util.Arrays; public class SelectionSort { public static void main(String[] args) { int[] arr = new int[]{5, 4, 3, 2, 1}; selectionSort(arr); System.out.println(Arrays.toString(arr)); } static void…

## Insertion Sort

insertion sorot package sorting; import java.util.Arrays; public class InsertionSort { public static void main(String[] args) { int[] arr = new int[]{5, 4, 3, 2, 1}; insertionSort(arr); System.out.println(Arrays.toString(arr)); } /** *…