## 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)…

Skip to content
##
Binary Search

##
Linear Search

##
Recursion

##
Time Complexities Table

##
Implementing Queue using Arrays

##
How to Compare Algorithms

##
Quick Sort

##
Merge Sort

##
Selection Sort

##
Insertion Sort

Scroll to Top
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)…

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;…

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)); }…

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…

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…

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 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 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 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 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)); } /** *…