Skip to main content

Different Sorting Algorithm

Selection Sort:
The selection sort algorithm sorts an array by repeatedly finding the minimum element (considering ascending order) from unsorted part and putting it at the beginning.
arr[] = 64 25 12 22 11
// Find the minimum element in arr[0...4]
// and place it at beginning
11 25 12 22 64

// Find the minimum element in arr[1...4]
// and place it at beginning of arr[1...4]
11 12 25 22 64

// Find the minimum element in arr[2...4]
// and place it at beginning of arr[2...4]
11 12 22 25 64

// Find the minimum element in arr[3...4]
// and place it at




Insertion Sort:






Merge Short.






QuickSort
2.9
Like Merge Sort, QuickSort is a Divide and Conquer algorithm. It picks an element as pivot and partitions the given array around the picked pivot.  There are many different versions of quickSort that pick pivot in different ways.

  1. Always pick first element as pivot.
  2. Always pick last element as pivot (implemented below)
  3. Pick a random element as pivot.
  4. Pick median as pivot.

Heap Sort.

Input data: 4, 10, 3, 5, 1
                 4(0)
        /   \
         10(1)   3(2)
            /   \
     5(3)    1(4)

The numbers in bracket represent the indices in the array 
representation of data.

Applying heapify procedure to index 1:
         4(0)
        /   \
            10(1)    3(2)
           /   \
    5(3)    1(4)

Applying heapify procedure to index 0:
            10(0)
        /  \
         5(1)  3(2)
            /   \
         4(3)    1(4)
The heapify procedure calls itself recursively to build heap
 in top down manner.

The Radix Sort Algorithm
1) Do following for each digit i where i varies from least significant digit to the most significant digit.
………….
a) Sort input array using counting sort (or any stable sort) according to the i’th digit.
Example:
Original, unsorted list:
170, 45, 75, 90, 802, 24, 2, 66
Sorting by least significant digit (1s place) gives: [*Notice that we keep 802 before 2, because 802 occurred before 2 in the original list, and similarly for pairs 170 & 90 and 45 & 75.]
170, 90, 8022, 24, 45, 75, 66
Sorting by next digit (10s place) gives: [*Notice that 802 again comes before 2 as 802 comes before 2 in the previous list.]
802, 2, 24, 45, 66, 170, 75, 90
Sorting by most significant digit (100s place) gives:
2, 24, 45, 66, 75, 90, 170, 802


Bucket Search:


ref: https://www.geeksforgeeks.org/

Comments

Popular posts from this blog

ifference between @RestController and @Controller

Difference between @RestController and @Controller Annotation in Spring MVC and REST Read more:  http://javarevisited.blogspot.com/2017/08/difference-between-restcontroller-and-controller-annotations-spring-mvc-rest.html#ixzz4sbGy2Glh The  @RestController  annotation in Spring MVC is nothing but a combination of  @Controller  and  @ResponseBody  annotation. It was added into Spring 4.0 to make the development of RESTful Web Services in Spring framework easier. If you are familiar with the  REST web services  you know that the fundamental difference between a web application and a REST API is that the response from a web application is generally view (HTML + CSS + JavaScript) while REST API just return data in form of JSON or XML. This difference is also obvious in the  @Controller  and  @RestController  annotation. The job of  @Controller  is to create a Map of model object and find a view but  @RestContr...

Presentation topics

Topics for presentation : Knockout.js, Angular.js, Node,js, Kendo UI, MVC 4, Nuget, Ninject, Unity Framework, Dependency Injection , PMC Package Manager Control, Mordenizer, Moq, Json, Html5, Entity Framework code1st. Spring.net Castle Windsor , Structure Map and Microsoft Unity ,
What happens when you compile/run the following code: class MyClass { public static void main(String[] args) { new MyClass(); } Ans: It executes and create a object for that class without reference. The output of the program is nothing.