1. Shell Sort -General Description
Essentially a segmented insertion sort
Divides an array into several smaller non-contiguous
segments
The distance between successive elements in one
segment is called a gap.
Each segment is sorted within itself using insertion
sort.
Then resegment into larger segments (smaller gaps)
and repeat sort.
Continue until only one segment (gap = 1) - final sort
finishes array sorting.
2. Shell Sort -Background
General Theory:
Makes use of the intrinsic strengths of Insertion sort. Insertion sort is fastest
when:
The array is nearly sorted.
The array contains only a small number of data items.
Shell sort works well because:
It always deals with a small number of elements.
Elements are moved a long way through array with each swap and this leaves it
more nearly sorted.
8. Shell Sort: Gap Values
Gap: the distance between items being
sorted.
As we progress, the gap decreases. Shell
Sort is also called Diminishing Gap Sort.
Shell proposed starting gap of N/2, halving at
each step.
There are many ways of choosing the next
gap.
9. Generic Sort
So far we have methods to sort integers. What about
Strings? Employees? Cookies?
A new method for each class? No!
In order to be sorted, objects should be comparable (less
than, equal, greater than).
Solution:
use an interface that has a method to compare two objects.
Remember: A class that implements an interface inherits
the interface (method definitions) = interface inheritance, not
implementation inheritance.
10. How many squares can you create in this figure by connecting any 4
dots (the corners of a square must lie upon a grid dot?
TRIANGLES:
How many triangles are located in the image below?
11. There are 11 squares total; 5 small, 4 medium, and 2 large.
27 triangles. There are 16 one-cell triangles, 7 four-cell triangles, 3 nine-cell
triangles, and 1 sixteen-cell triangle.
16. CONTD..
3.The _________ sort can also undertake sorting
in
the descending order by selecting the maximum
element.
a)bubble
b)insertion
c)selection
d)shell