Top Banner
Data Structures: A Pseudocode Approach with C, Second Edition 1 Chapter 12 Objectives Upon completion you will be able to: Understand the basic concepts of internal sorts Discuss the relative efficiency of different sorts Recognize and discuss selection, insertion and exchange sorts Sorting
57

Sorting - topstep.weebly.com filesection we study two insertion sorts: the straight insertion sort and the shell sort.

Jun 09, 2019

Download

Documents

phamngoc
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Sorting - topstep.weebly.com filesection we study two insertion sorts: the straight insertion sort and the shell sort.

Data Structures: A Pseudocode Approach with C, Second Edition 1

Chapter 12

Objectives

Upon completion you will be able to:

• Understand the basic concepts of internal sorts

• Discuss the relative efficiency of different sorts

• Recognize and discuss selection, insertion and exchange sorts

Sorting

Page 2: Sorting - topstep.weebly.com filesection we study two insertion sorts: the straight insertion sort and the shell sort.

Data Structures: A Pseudocode Approach with C, Second Edition 2

Page 3: Sorting - topstep.weebly.com filesection we study two insertion sorts: the straight insertion sort and the shell sort.

Data Structures: A Pseudocode Approach with C, Second Edition 3

Page 4: Sorting - topstep.weebly.com filesection we study two insertion sorts: the straight insertion sort and the shell sort.

Data Structures: A Pseudocode Approach with C, Second Edition 4

12-2 Selection Sorts

In each pass of the selection sort, the smallest element is

selected from the unsorted sublist and exchanged with the

element at the beginning of the unsorted list. We discuss two

classic selection sorts, straight selection and heap sort.

• Straight Selection Sort

• Heap Sort

• Selection Sort Efficiency

• Selection Sort Implementation

Page 5: Sorting - topstep.weebly.com filesection we study two insertion sorts: the straight insertion sort and the shell sort.

Data Structures: A Pseudocode Approach with C, Second Edition 5

Page 6: Sorting - topstep.weebly.com filesection we study two insertion sorts: the straight insertion sort and the shell sort.

Data Structures: A Pseudocode Approach with C, Second Edition 6

Page 7: Sorting - topstep.weebly.com filesection we study two insertion sorts: the straight insertion sort and the shell sort.

Data Structures: A Pseudocode Approach with C, Second Edition 7

Page 8: Sorting - topstep.weebly.com filesection we study two insertion sorts: the straight insertion sort and the shell sort.

Data Structures: A Pseudocode Approach with C, Second Edition 8

Page 9: Sorting - topstep.weebly.com filesection we study two insertion sorts: the straight insertion sort and the shell sort.

Data Structures: A Pseudocode Approach with C, Second Edition 9

Page 10: Sorting - topstep.weebly.com filesection we study two insertion sorts: the straight insertion sort and the shell sort.

Data Structures: A Pseudocode Approach with C, Second Edition 10

Page 11: Sorting - topstep.weebly.com filesection we study two insertion sorts: the straight insertion sort and the shell sort.

Data Structures: A Pseudocode Approach with C, Second Edition 11

Page 12: Sorting - topstep.weebly.com filesection we study two insertion sorts: the straight insertion sort and the shell sort.

Data Structures: A Pseudocode Approach with C, Second Edition 12

Page 13: Sorting - topstep.weebly.com filesection we study two insertion sorts: the straight insertion sort and the shell sort.

Data Structures: A Pseudocode Approach with C, Second Edition 13

Page 14: Sorting - topstep.weebly.com filesection we study two insertion sorts: the straight insertion sort and the shell sort.

Data Structures: A Pseudocode Approach with C, Second Edition 14

Page 15: Sorting - topstep.weebly.com filesection we study two insertion sorts: the straight insertion sort and the shell sort.

Data Structures: A Pseudocode Approach with C, Second Edition 15

Page 16: Sorting - topstep.weebly.com filesection we study two insertion sorts: the straight insertion sort and the shell sort.

Data Structures: A Pseudocode Approach with C, Second Edition 16

Page 17: Sorting - topstep.weebly.com filesection we study two insertion sorts: the straight insertion sort and the shell sort.

Data Structures: A Pseudocode Approach with C, Second Edition 17

Page 18: Sorting - topstep.weebly.com filesection we study two insertion sorts: the straight insertion sort and the shell sort.

Data Structures: A Pseudocode Approach with C, Second Edition 18

Page 19: Sorting - topstep.weebly.com filesection we study two insertion sorts: the straight insertion sort and the shell sort.

Data Structures: A Pseudocode Approach with C, Second Edition 19

Page 20: Sorting - topstep.weebly.com filesection we study two insertion sorts: the straight insertion sort and the shell sort.

Data Structures: A Pseudocode Approach with C, Second Edition 20

Page 21: Sorting - topstep.weebly.com filesection we study two insertion sorts: the straight insertion sort and the shell sort.

Data Structures: A Pseudocode Approach with C, Second Edition 21

12-3 Insertion Sorts

In each pass of an insertion sort, one or more pieces of data are

inserted into their correct location in an ordered list. In this

section we study two insertion sorts: the straight insertion sort

and the shell sort.

• Straight Insertion Sort

• Shell Sort

• Insertion Sort Efficiency

• Insertion Sort Implementation

Page 22: Sorting - topstep.weebly.com filesection we study two insertion sorts: the straight insertion sort and the shell sort.

Data Structures: A Pseudocode Approach with C, Second Edition 22

Page 23: Sorting - topstep.weebly.com filesection we study two insertion sorts: the straight insertion sort and the shell sort.

Data Structures: A Pseudocode Approach with C, Second Edition 23

Page 24: Sorting - topstep.weebly.com filesection we study two insertion sorts: the straight insertion sort and the shell sort.

Data Structures: A Pseudocode Approach with C, Second Edition 24

Page 25: Sorting - topstep.weebly.com filesection we study two insertion sorts: the straight insertion sort and the shell sort.

Data Structures: A Pseudocode Approach with C, Second Edition 25

Page 26: Sorting - topstep.weebly.com filesection we study two insertion sorts: the straight insertion sort and the shell sort.

Data Structures: A Pseudocode Approach with C, Second Edition 26

Page 27: Sorting - topstep.weebly.com filesection we study two insertion sorts: the straight insertion sort and the shell sort.

Data Structures: A Pseudocode Approach with C, Second Edition 27

(continued)

Page 28: Sorting - topstep.weebly.com filesection we study two insertion sorts: the straight insertion sort and the shell sort.

Data Structures: A Pseudocode Approach with C, Second Edition 28

Page 29: Sorting - topstep.weebly.com filesection we study two insertion sorts: the straight insertion sort and the shell sort.

Data Structures: A Pseudocode Approach with C, Second Edition 29

Page 30: Sorting - topstep.weebly.com filesection we study two insertion sorts: the straight insertion sort and the shell sort.

Data Structures: A Pseudocode Approach with C, Second Edition 30

Page 31: Sorting - topstep.weebly.com filesection we study two insertion sorts: the straight insertion sort and the shell sort.

Data Structures: A Pseudocode Approach with C, Second Edition 31

Page 32: Sorting - topstep.weebly.com filesection we study two insertion sorts: the straight insertion sort and the shell sort.

Data Structures: A Pseudocode Approach with C, Second Edition 32

Page 33: Sorting - topstep.weebly.com filesection we study two insertion sorts: the straight insertion sort and the shell sort.

Data Structures: A Pseudocode Approach with C, Second Edition 33

Page 34: Sorting - topstep.weebly.com filesection we study two insertion sorts: the straight insertion sort and the shell sort.

Data Structures: A Pseudocode Approach with C, Second Edition 34

Page 35: Sorting - topstep.weebly.com filesection we study two insertion sorts: the straight insertion sort and the shell sort.

Data Structures: A Pseudocode Approach with C, Second Edition 35

12-4 Exchange Sorts

This section discusses the four basic queue operations. Using

diagrammatic figures, it shows how each of them work. It

concludes with a comprehensive example that demonstrates

each operation.

• Bubble Sort

• Quick Sort

• Exchange Sort Efficiency

• Sort Summary

• Exchange Sort Implementation

Page 36: Sorting - topstep.weebly.com filesection we study two insertion sorts: the straight insertion sort and the shell sort.

Data Structures: A Pseudocode Approach with C, Second Edition 36

Page 37: Sorting - topstep.weebly.com filesection we study two insertion sorts: the straight insertion sort and the shell sort.

Data Structures: A Pseudocode Approach with C, Second Edition 37

Page 38: Sorting - topstep.weebly.com filesection we study two insertion sorts: the straight insertion sort and the shell sort.

Data Structures: A Pseudocode Approach with C, Second Edition 38

Page 39: Sorting - topstep.weebly.com filesection we study two insertion sorts: the straight insertion sort and the shell sort.

Data Structures: A Pseudocode Approach with C, Second Edition 39

Page 40: Sorting - topstep.weebly.com filesection we study two insertion sorts: the straight insertion sort and the shell sort.

Data Structures: A Pseudocode Approach with C, Second Edition 40

Page 41: Sorting - topstep.weebly.com filesection we study two insertion sorts: the straight insertion sort and the shell sort.

Data Structures: A Pseudocode Approach with C, Second Edition 41

Page 42: Sorting - topstep.weebly.com filesection we study two insertion sorts: the straight insertion sort and the shell sort.

Data Structures: A Pseudocode Approach with C, Second Edition 42

Page 43: Sorting - topstep.weebly.com filesection we study two insertion sorts: the straight insertion sort and the shell sort.

Data Structures: A Pseudocode Approach with C, Second Edition 43

Page 44: Sorting - topstep.weebly.com filesection we study two insertion sorts: the straight insertion sort and the shell sort.

Data Structures: A Pseudocode Approach with C, Second Edition 44

Page 45: Sorting - topstep.weebly.com filesection we study two insertion sorts: the straight insertion sort and the shell sort.

Data Structures: A Pseudocode Approach with C, Second Edition 45

Page 46: Sorting - topstep.weebly.com filesection we study two insertion sorts: the straight insertion sort and the shell sort.

Data Structures: A Pseudocode Approach with C, Second Edition 46

Page 47: Sorting - topstep.weebly.com filesection we study two insertion sorts: the straight insertion sort and the shell sort.

Data Structures: A Pseudocode Approach with C, Second Edition 47

12-5 External Sorts

In external sorting portions of the data may be stored in

secondary memory during the sorting process. Included in this

section is a discussion of file merging and three external sort

approaches-natural, balanced, and polyphase.

• Merging Ordered Files

• Merging Unordered Files

• The Sorting Process

• Sort Phase Revisited

Page 48: Sorting - topstep.weebly.com filesection we study two insertion sorts: the straight insertion sort and the shell sort.

Data Structures: A Pseudocode Approach with C, Second Edition 48

Page 49: Sorting - topstep.weebly.com filesection we study two insertion sorts: the straight insertion sort and the shell sort.

Data Structures: A Pseudocode Approach with C, Second Edition 49

Page 50: Sorting - topstep.weebly.com filesection we study two insertion sorts: the straight insertion sort and the shell sort.

Data Structures: A Pseudocode Approach with C, Second Edition 50

Page 51: Sorting - topstep.weebly.com filesection we study two insertion sorts: the straight insertion sort and the shell sort.

Data Structures: A Pseudocode Approach with C, Second Edition 51

Page 52: Sorting - topstep.weebly.com filesection we study two insertion sorts: the straight insertion sort and the shell sort.

Data Structures: A Pseudocode Approach with C, Second Edition 52

Page 53: Sorting - topstep.weebly.com filesection we study two insertion sorts: the straight insertion sort and the shell sort.

Data Structures: A Pseudocode Approach with C, Second Edition 53

Page 54: Sorting - topstep.weebly.com filesection we study two insertion sorts: the straight insertion sort and the shell sort.

Data Structures: A Pseudocode Approach with C, Second Edition 54

Page 55: Sorting - topstep.weebly.com filesection we study two insertion sorts: the straight insertion sort and the shell sort.

Data Structures: A Pseudocode Approach with C, Second Edition 55

Page 56: Sorting - topstep.weebly.com filesection we study two insertion sorts: the straight insertion sort and the shell sort.

Data Structures: A Pseudocode Approach with C, Second Edition 56

Page 57: Sorting - topstep.weebly.com filesection we study two insertion sorts: the straight insertion sort and the shell sort.

Data Structures: A Pseudocode Approach with C, Second Edition 57