From 53f77360f06dc9099957f2bcb1fb350a108e0097 Mon Sep 17 00:00:00 2001 From: PULLAMMA Date: Fri, 22 Mar 2019 02:19:51 +0530 Subject: [PATCH] fixed issue #262 --- src/lab/exp3/Theory.html | 51 ++++++++++++++++++++++++++++++++-------- 1 file changed, 41 insertions(+), 10 deletions(-) diff --git a/src/lab/exp3/Theory.html b/src/lab/exp3/Theory.html index a64d47b..8dbbd86 100644 --- a/src/lab/exp3/Theory.html +++ b/src/lab/exp3/Theory.html @@ -163,7 +163,7 @@

1.1 Merge Sort

1.2 Quick Sort


  • - Let us look at one final example of sorting algorithms along with a short proof of correctness. While merge sort can be said to be optimal in terms of its time requiement, it does use some extra space. So one question to prusue is to design a sorting algorithm that can sort in-place, i.e., without using any extra space.C. A. R. Hoare gave an algorithm based on the divide and conquer strategy called the quick sort that can sort in place. The 3 steps of the algorithm in the framework of divide and conquer are:
  • + Let us look at one second example of sorting algorithms along with a short proof of correctness. While merge sort can be said to be optimal in terms of its time requiement, it does use some extra space. So one question to prusue is to design a sorting algorithm that can sort in-place, i.e., without using any extra space.C. A. R. Hoare gave an algorithm based on the divide and conquer strategy called the quick sort that can sort in place. The 3 steps of the algorithm in the framework of divide and conquer are:
     ♦ Divide: Divide the input into 3 parts L,E, and R where L < E < R based on a pivot.
    @@ -176,18 +176,49 @@ 

    1.1 Merge Sort

    following approach is presented.
    +

    1.3 Insertion Sort

    +
    +
  • + Let us look at one final example of sorting algorithms.Insertion sort is a simple sorting algorithm that works the way we sort playing cards in our hands.This algorithm builds the final sorted array (or list) one item at a time. It is much less efficient on large lists than more advanced algorithms such as quicksort, heapsort, or merge sort. +
  • +
    +

    Steps ivolved

    +Step 1 − If it is the first element, it is already sorted. return 1;
    +Step 2 − Pick next element
    +Step 3 − Compare with all elements in the sorted sub-list
    +Step 4 − Shift all the elements in the sorted sub-list that is greater than the 
    +         value to be sorted
    +Step 5 − Insert the value
    +Step 6 − Repeat until list is sorted
       
      -
    • Procedure Parition(A, l, h)
    • -
    • pivot = A[h];
    • -
    • i = l - 1; 4. for j = p to h - 1 do
    • -
    • if A[j] <= pivot
    • -
    • i = i + 1;
    • -
    • swap A[i] with A[j]
    • -
    • swap A[i + 1] with A[h]
    • -
    • End Procedure
    • +
    • procedure insertionSort( A : array of items )
    • +
    • int holePosition
    • +
    • int valueToInsert
    • + +
    • for i = 1 to length(A) inclusive do:
    • + +
    • /* select value to be inserted */
    • +
    • valueToInsert = A[i]
    • +
    • holePosition = i
    • + +
    • /*locate hole position for the element to be inserted */
    • + +
    • while holePosition > 0 and A[holePosition-1] > valueToInsert do:
    • +
    • A[holePosition] = A[holePosition-1]
    • +
    • holePosition = holePosition -1
    • +
    • end while
    • + +
    • /* insert the number at hole position */
    • +
    • A[holePosition] = valueToInsert
    • + +
    • end for
    • + +
    • end procedure
    -

    + +

    +