Skip to content

sudheerkodali/Sorting-DSA

Repository files navigation

Sorting

DSA -Sorting in Java Script1

No. Questions
Sorting-concepts
1 Module-Introduction
2 Selection-sort-implementation-java-script
3 Merge two sorted arrays-theory
4 Merge-sort-theory
5 Merge-sort-implementation
6 Merge-sort-complexity-analysis
7 Two-way-partitioning-Algorithm
8 Quick-sort - Theory
9 Quick-sort - Implementation
10 counting-sort-Algorithm
11 How-to-make-counting-sort-table
12 Bubble-sort-work
13 Bubble-sort-implementation
14 Selection-sort-working
15 Merge-two-sorted-arrays-implemention
16 Two-way-partitioning-implementation-programming
17 Count-sort-implementation
18 Radix-sort-introduction
19 Radix-sort-implementation

| 3 | Merge two sorted arrays-theory
Image of Merge Sort array

Now A, B are two different Arrays with different data types

Let take two sorting arrays with A and B to merge them

Merge A & B

Image of Merge sort array`

  • New Array variable called C to combain two arrays A & B in Assending order

  • How to Merge A & B values with explination

    Image of Merge sort array`

  • First essume that A[i] B[j] with start with sorting with 'i' to 'j' from LEFT to RIGHT

  • while as we know the count the DATA TYPES with 0,1,2,3,4, where values are i= [2,5,8,9,10] j=[2,4,7,18] count with [0,1,2,3]

  • maximum count from LEFT TO RIGHT i=[2,5,8,9,10] j=[2,4,7,18] => that means I to J Assending order SMALL to Higher values.

  • i=0 => 2 & j=0 =>2 :[2] =>2 is small from starting with 'i' compared to 'j'

  • j=0 => 2 & i=1 =>5 :[2,2] =>2 is small compared to'5' so 'j' value comes first and value 2 is forwoded

  • i=1 => 5 & j=1 =>4 :[2,2,4] => 4 is smaller compared to 5 so 'j' comes first and value 2,2 is forwored

  • i=1 => 5 & j=2 =>7 :[2,2,4,5] => 5 is smaller compared to 7 so 'i' comes first and value 2,2,4 is forworded

  • Till the Highest number comes and it ends with [2,2,4,5,7,8,9,18]

  • Merge two sorted Arrays and the values are

    Image of Merge sort array

  • when we compare the array values between A & B , combine with C then the values look in the above picture

  • | 4 | Merge-sort-theory

    Merge sort theory

    combination of values

    merge sort theoty

    Added values to Merge sort

    Merge sort theory

    | 14 | Selection-sort-working

    14.1

    Select-sort-work

    14.2

    Select-sort-work

    14.3

    Select-sort-work

    14.4

    Select-sort-work

    14.5

    Select-sort-work

    | 10 | Countsort
    Image of Countsort

    Let us assume that count sort is not a comparision, however it is the array that we can not count from the range

    It would be the certain range between [0,k] we can not expect the range in count sort but to some expect from this range like negative range or number,in an Array

    countsort

    Image of Countsort

    Let we determine the number range array A=[2,5,1,4,4,2,6] => count=[0,1,2,3,4,5,6,7,8]

    itterate to A with count values for instance A = 2 value in count =[0,0,1,0,0,0,0,0,0]

    itterate to A with count values for instance A = 5 value in count =[0,0,1,0,0,1,0,0,0]

    itterate to A with count values for instance A = 1 value in count =[0,1,1,0,0,1,0,0,0]

    itterate to A with count values for instance A = 4 value in count =[0,1,1,0,1,1,0,0,0]

    itterate to A with count values for instance A = 4 value in count =[0,1,1,0,2,1,0,0,0] Here 4 comes two times and the value of 4 is 2

    itterate to A with count values for instance A = 2 value in count =[0,1,2,0,2,1,0,0,0] Here 2 value comes two times and the value of 2 is 2 times occurs

    count num in order

    Image of Countsort

    itterate to A with count values for instance A = 6 value in count =[0,1,2,0,2,1,1,0,0]

    The count values of 7, 8 are 0,0-----------------------------count=[0,1,2,0,2,1,1,0,0]

    cumulative sum

    Image of Countsort

    Cumulative sum final result add result value from left 0, 0+1=1,1+2=3,3+0=3,3+2=5,5+1=6,6+1=7,7+0=7,7+0=7

    -------------count=[0,1,3,3,5,6,7,7,7] is called cumelative sum

    Final count

    Image of Countsort

    New result value array formula is K, COUNT[K]: [K-1], for instance [k =2] , [k-2-1-1], [k=5, K-1=5-1=4],

    Counting sort count the number of elements

    Complexity would be 'LINEAR'