Skip to content

MonaMobeen/SortingnSearchingAlgorithmOneMoreStep

Repository files navigation

SortingnSearchingAlgorithmOneMoreStep

Sorting n Searching Algorithm Part 2

1. Merge Sort:

Merge sort continuously cuts down a list into multiple sublists until each has only one item, then merges those sublists into a sorted list.

download merge-sort-visual

3 case complexity of merge sort:

The list of size N is divided into a max of Logn parts, and the merging of all sublists into a single list takes O(N) time, the worst-case run time of this algorithm is O(nLogn) Best Case Time Complexity: O(nlog n)* Worst Case Time Complexity: O(nlog n) Average Time Complexity: O(nlog n)

MergeSort


2. Insertion Sort:

Insertion sort is a simple sorting algorithm that works similar to the way you sort playing cards in your hands.

download

three steps of the insertion sort algorithm:

The first element in the array is assumed to be sorted. Take the second element and store it separately in key . Now, the first two elements are sorted. Take the third element and compare it with the elements on the left of it. Similarly, place every unsorted element at its correct position


3. Quick Sort:

Quicksort is a highly efficient sorting technique that divides a large data array into smaller ones.

download

basic operation of quicksort

Quick Sort is a divide and conquer algorithm. It creates two empty arrays to hold elements less than the pivot value and elements greater than the pivot value, and then recursively sort the sub arrays. There are two basic operations in the algorithm, swapping items in place and partitioning a section of the array


4. Shell Sort:

Shell sort is a generalized version of the insertion sort algorithm. It first sorts elements that are far apart from each other and successively reduces the interval between the elements to be sorted. The interval between the elements is reduced based on the sequence used.

images


5. Selection Sort:

Selection sort works by taking the smallest element in an unsorted array and bringing it to the front

download


Thankxx for Reading this file:)

Made with ❣ By Mona