• Tidak ada hasil yang ditemukan

FACULTY OF MEDICAL SCIENCES - Rama University

N/A
N/A
Protected

Academic year: 2024

Membagikan "FACULTY OF MEDICAL SCIENCES - Rama University"

Copied!
19
0
0

Teks penuh

(1)

FACULTY OF ENGINEERING & TECHNOLOGY

Lecture : 06

Mr. Nilesh

Assistant Professor

Computer Science & Engineering

(2)

 Outline

 Introduction Sorting and Order Statistics

 Types of Sorting algorithms

 Order statistics

 Selection Sort

(3)

Introduction Sorting and Order Statistics

Algorithms that solve the following sorting problem:

Input: A sequence of n numbers <a1, a2, . . . , an>.

Output:

A permutation (reordering) <a'1, a'2, . . . , a'n> of the input sequence such that a'1 a'2 a'n.

The input sequence is usually an n-element array,

although it may be represented in some other fashion, such as a linked list.

Introduction

(4)

The structure of the data

• The numbers to be sorted are rarely isolated values.

• That may be a record (Each record contains a key)

• which is the value to be sorted,

• When a sorting algorithm permutes the keys, it must permute the satellite data as well.

• If each record is large in size - we often permute an array of pointers to the records rather than the records themselves in order to minimize data

movement.

(5)

 Types of Sorting algorithms

How many Sorting also. We have?

• Selection Sort

• Bubble Sort

• Insertion Sort

• Merge Sort

• Quick Sort

• Heap Sort

• Radix Sort

• ShellSort

• Pigeonhole Sort

• Cycle Sort

• Cocktail Sort

• Strand Sort

• Recursive Bubble Sort

• Recursive Insertion Sort

• Iterative Merge Sort

• Iterative Quick Sort

• Counting Sort

• Bucket Sort

• TimSort

(6)

Order statistics

• Order statistics are sample values placed in ascending order. The study of order statistics deals with the applications of these ordered values and their functions.

Let’s say you had three weights:

X1 = 22 kg, X2 = 44 kg, and X3 = 12 kg.

To get the order statistics (Yn), put the items in numerical increasing order:

Y1 = 12 kg Y2 = 22 kg Y3 = 44 kg

The kth smallest X value is normally called the kth order statistic.

(7)

Selection Sort

Suppose an array A with N

1. Find the smallest element in the list & put it in the first position.

2. Find 2

nd

smallest element in the list and put in the second position

3. So on

(8)
(9)

 Time Complexity

Notes:

Outer loop executes N-1 times( No each rd.. For final elements) Inner loop executes N-i-1 comparisons.

(N-1)* (N-2)+….+2+1 = N*(N-1)/2

Best case: Square(n)

Average Case: Square(n)

(10)

Advantages

 Easy to write

 Can be done “In place”

 Can be done on linked lists too( Keep a tail Pointer) Disadvantages

• It is about square(n) even in the best case for comparisons.

• So the running time is Approx. Square(n)

(11)

Initial Configuration

(search all cards and find the largest) Example

(12)

Swap the two cards

(13)

As before, the swap is

performed in three

steps.

(14)

Sorted Unsorted

Among the remaining cards the king is the largest.

It will remain in place.

But the algorithm may perform Some empty operations

(ie., swap it with itself in place)

(15)

Sorted Unsorted

Among the remaining cards the queen is the largest.

It will remain in place.

But the algorithm may perform Some empty operations

(i.e., swap it with itself in place)

(16)

Sorted Unsorted

Among the remaining cards the Jack is the largest.

It will remain in place.

But the algorithm may perform Some empty operations

(i.e., swap it with itself in place)

(17)

As before, the swap is

performed in three

steps.

(18)

Sorted Unsorted

We are down to the last card.

Because there is only one and Because we know that it is Smaller than all the rest

We don’t need to do anything Else with it. This is why the Algorithm goes up to < N-1

(19)

Sorted

All cards are now sorted.

Referensi

Dokumen terkait

Section 13 of the Transfer of Property Act, 1882 provides that when for the transfer of property, an interest therein is created for the benefit of an unborn person at the date of the

Broth test The following qualities of the broth samples must be checked to make sure that the broths are in good condition: 2.1 pH 2.2 Staining 2.3 Optical density 2.4 Total count

—For the purpose of filling the seats of members of the Council of States retiring on the expiration of their term of office the President shall, by one or more notifications published

Section 67 of the Transfer of Property Act run as follows - In the absence of a contract to the contrary, the mortgagee has, at any time after the mortgage- money has become due to

Synchronous culture system A synchronous or synchronized culture is a microbiological culture or a cell culture that contains cells that are all in the same growth stage e.g.,

The Charter of 1726 made Mayor' Courts at all the three administrations that is Madras, Calcutta and Bombay consequently, out of the blue, building up a uniform legal framework.. 3 The

The small scale Photovoltaic and Thermal Hybridized Casserole type solar cooker as designed and developed was developed [22] tested for the performance with a Thermal Energy Storage

Chapter-2 AGENCIES RESPONSIBLE FOR INTELLECTUAL PROPERTY REGISTRATION United States Patents and Trademark Office: The agency charged with granting patents and registering