Shell sort by group .pptx kkjskanjkkanank

NIMONAFEKADU 4 views 11 slides Jun 17, 2024
Slide 1
Slide 1 of 11
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11

About This Presentation

hhjkaklllapmllamalamaal


Slide Content

Shell sort …

OUTLINE 1 Introduction to Shell Sort 2 How Shell Sort Works 3 Steps of Shell Sort 4 Example 5 Time Complexity of shell sort 6 Advantages and Disadvantages 7 Conclusion

INTRODUCATION Shell sort is an efficient sorting algorithm. Also known as Shell's method or the diminishing increment sort. Invented by Donald Shell in 1959. It's an improvement over insertion sort.

How Shell Sort Works Shell Sort divides the input into smaller subarrays. It sorts the subarrays using the insertion sort algorithm. The subarrays are chosen based on a predefined sequence of gaps.

Steps of Shell Sort Define a sequence of gaps. Start with the largest gap and divide the list into subarrays. Sort each subarray using the insertion sort algorithm. Reduce the gap and repeat steps 2 and 3 until the gap is 1. Finally, perform a final insertion sort on the entire array.

Example Let's take an example to understand Shell Sort better. Consider the following unsorted array: [9, 5, 7, 3, 2, 1, 8, 4, 6]. We'll use the sequence of gaps: [5, 3, 1].

Example (continued) With a gap of 5: [1, 5], [2, 1], [8, 4], [7, 3], [9, 6]. Using insertion sort on each subarray: [1, 5] -> [1, 5] [2, 1] -> [1, 2] [8, 4] -> [4, 8] [7, 3] -> [3, 7] [9, 6] -> [6, 9]

Example (continued) With a gap of 3: [1, 2, 4, 3, 6, 5], [5, 7, 8, 9]. Using insertion sort on each subarray: [1, 2, 4, 3, 6, 5] -> [1, 2, 3, 4, 5, 6] [5, 7, 8, 9] -> [5, 7, 8, 9] With a gap of 1, perform a final insertion sort on the entire array: [1, 2, 3, 4, 5, 6, 7, 8, 9]. The array is now sorted.

Time Complexity The time complexity of Shell Sort depends on the chosen gap sequence. In the worst-case scenario, the time complexity is O(n^2). In the best-case scenario, it can be as low as O(n log^2 n).

Advantages and Disadvantages Advantages: Shell Sort is an in-place sorting algorithm. It performs well on small to medium-sized lists. Disadvantages: The choice of gap sequence affects the efficiency of the algorithm. It is not stable, meaning it may change the relative order of equal elements

Conclusion Shell Sort is an efficient sorting algorithm based on the insertion sort technique. It divides the input into smaller subarrays and sorts them using insertion sort. Although it has some limitations, Shell Sort can be a good choice for small to medium-sized lists.
Tags