Shell sort

Shell sort works by comparing elements that are distinct rather than adjacent elements in an array. It is an improvement over Insertion sort. The increment sequences in shell sort can be Shell's original sequence, Hibbard's increments, etc. The average performance of shell sort is thought to be O(n^(5/4)).

Summary

Shell sort works by comparing elements that are distinct rather than adjacent elements in an array. It is an improvement over Insertion sort. The increment sequences in shell sort can be Shell's original sequence, Hibbard's increments, etc. The average performance of shell sort is thought to be O(n^(5/4)).

Things to Remember

  1. Shell sort works by comparing elements that are distinct rather than adjacent elements in an array. 
  2. It is an improvement over Insertion sort.
  3. The increment sequences in shell sort can be Shell's original sequence, Hibbard's increments, etc. 
  4. The average performance of shell sort is thought to be O(n^(5/4)).

MCQs

No MCQs found.

Subjective Questions

Q1:

Write a short note on Myocardial Infarction.


Type: Short Difficulty: Easy

Show/Hide Answer
Answer: <h4>Myocardial infarction</h4>
<p><strong>Definition</strong></p>
<p>A heart attack usually occurs when a blood clot blocks the flow of blood through a coronary artery &amp;mdash; a blood vessel that feeds blood to a part of the heart muscle. The interrupted blood flow that occurs during a heart attack can damage or destroy a part of the heart muscle.</p>
<p>A heart attack also called a myocardial infarction, can be fatal. Treatment for heart attack has improved dramatically over the years. It is crucial to promptly recognize symptoms and call 911 or emergency medical help if you think you might be having a heart attack.</p>
<p>&nbsp;</p>
<p><img src="https://d1vzuwdl7rxiz0.cloudfront.net/content/ehj/early/2012/08/23/eurheartj.ehs184/F2.large.jpg" alt="Image result for Myocardial Infarction" width="394" height="257" /></p>
<p><strong>Causes</strong></p>
<p>_ Vasospasm of coronary artery</p>
<p>_ Prinz mental's variant angina</p>
<p>_ Decreased oxygen supply</p>
<p>_ Acute blood loss anemia,low BP</p>
<p>_ Increased demand for oxygen</p>
<p>_ Rapid heart rate, thyrotoxicosis,ingestion of cocaine.</p>
<p><strong>Risk factor</strong></p>
<p>Non- modifiable - family history, increasing age, sex ( 3 times more in men )</p>
<p>Modifiable - high blood cholesterol level,smoking, tobacco,DM, HTN, obesity</p>
<p><strong>Symptoms</strong></p>
<p>Common heart attack symptoms include:</p>
<p>- A feeling of fullness, nausea, indigestion, heartburn</p>
<p>- Shortness of breath</p>
<p>- Sweating or a cold sweat</p>
<p>- Feelings of anxiety or an impending sense of doom</p>
<p>- Fatigue</p>
<p>- Trouble sleeping</p>
<p>- Lightheadedness or dizziness</p>
<p><strong>Diagnosis</strong></p>
<ol>
<li>ECG</li>
<li>Troponin</li>
<li>Myoglobin</li>
<li>LHD</li>
<li>Increased CPK - MB</li>
<li>Leukocytosis appears on the second day after MI and disappears in 1 week.</li>
</ol>
<p><strong>Management</strong></p>
<p>_ High flow oxygen.</p>
<p>_ IV access</p>
<p>_ IV analgesia and antiemetics</p>
<p>_ Serial ECG Monitoring</p>
<p>_ IV analgesia : 5-10 mg morphine with metoclopramide 10 mg.</p>
<p>_ Avoid intramuscular injection.</p>
<p>_ Thrombolytic therapy has been shown to improve survival rates in MI</p>
<p>_ Angiography provides essential knowledge of the extent of coronary disease</p>
<p>_ Anticoagulants : subcutaneous heparin 12500 units twice daily with an addition to oral aspirin.</p>
<p><strong>Nursing intervention</strong></p>
<ol>
<li>Monitor ECG results to detect ischemia, injury new or extended infarction, arrhythmia and conduction defects.</li>
<li>Monitor, record vital signs and hemodynamic variable to monitor response to the therapy and detect complications.</li>
<li>Administer oxygen as prescribed to improve oxygen supply to the heart.</li>
<li>Obtain an ECG reading during acute pain to detect myocardial ischemia, injury or infarction.</li>
<li>Maintain the patient's prescribed diet to reduce fluid retention and cholesterol level.</li>
<li>Allay the patient's anxiety because the anxiety increases oxygen demand.</li>
</ol>
<p><strong>Complications</strong></p>
<p>_ Left ventricular failure</p>
<p>_ Ventricular arrhythmia</p>
<p>_ Papillary miscle rupture</p>
<p>_ Pericarditis</p>
<p>_ Post MI angina</p>
<p>_ Ventricular aneurism</p>

Videos

Myocardial Infarction
Shell sort

Shell sort

Shell Sort

Shell sort is also known as diminishing increment sort. It was invented by Donald Shell in 1959. Shell sort works by comparing elements that are distinct rather than adjacent elements in an array. It is the improvement on simple insertion sort. The distance between comparisons decreased as the sorting algorithm runs until the last phase in which adjacent elements are compared.

The basic approach is

  • Divide and conquer approach to insertion sort
    • Sort many small sub arrays using insertion sort
    • Sort progressively larger arrays
    • Finally sort the entire array
  • These arrays are elements separated by a gap
    • Start with large gap
    • Decrease the gap on each pass

Increment Sequences in Shell Sort:

  • Shell's Original Sequence: n/2, n/4, . . . , 1 (repeatedly divide by 2)
  • Hibbard's Increments: 1, 3, 7, . . . , 2K - 1; k = 1,2,...
  • Knuth's Increments: 1, 4, 13, . . ., (3K - 1)/2 ; k = 1,2,3,. . .
  • Sedgewick's Increments: 1, 5, 19, 41, 109, . . ., 9 * 4k - 9 * 2k + 1

Algorithm: ShellSort(A,n)

Input: A, an array of size n

Output: Sorted A

loop1 gap = n/2 to gap > 0; gap = gap/2

loop2 p = gap to p < n ; p = p + 1

temp = A[p]

loop3 j = p to j >= gap && temp < A[j-gap]; j = j - gap

A[j] = A[j-gap]

Endloop3

A[j] = temp

Endloop2

Endloop1

Stop

Example: Sort 18 32 5 38 33 16 2

Steps: Shell's increment will be floor(n/2) = floor(8/2) = 4

1

Step 1: Only look at 18 and 38 and sort in order;

18 and 38 stay at their current position because they are in order

Step 2: Only look at 32 and 33 and sort in order;

32 and 33 stay at their current position because they are in order.

Step 3: Only look at 12 and 16 and sort in order;

12 and 16stay at their current position because they are in order.

Step 4: Only look at 5 and 2 and sort in order;

2 and 5 need to be switched to be in order.

Resulting numbers after increment 4 pass:

2

3

Step 1: Look at 18,12,38,16 and sort them in their appropriate location:

22

Step 2: Look at 32,2,33,5 and sort them in their appropriate location:

23

Resulting numbers after increment 2 pass:

24

floor1

The last increment of phase of Shell sort is basically an Insertion Sort Algorithm.

Analysis of Shell Sort:

  • Shell Sort's worst-case performance using Hibbard's increments is O(n3/2)
  • The average performance is thought to be about O(n5/4)
  • For mid-sized data : O(nlogn) sorts.

References

1. http://faculty.simpson.edu/lydia.sinapova/www/cmsc250/LN250_Weiss/L12-ShellSort.htm

2.T. H. Cormen, C. E. Leiserson, R. L. Rivest, C. Stein, “Introduction to Algorithms”

3. G. Brassard and P. Bratley, “Fundamentals of Algorithms”

Lesson

Sorting

Subject

Computer Engineering

Grade

Engineering

Recent Notes

No recent notes.

Related Notes

No related notes.