2 views

Original Title: Sample Copy

Uploaded by bachayadav

- 05987184
- Artificial Intelligence
- My Summary for CS001x_Computer Science for Beginners
- Arrays Intersection : Programming Fortran
- 3sum
- INDEX SORT
- Fd_data Struct Algor_AIA En_an2 s1
- Csci 5454 Hw
- SelectionSort With Java
- HCL_PlacementPapers
- Excel VBAMacros
- Lesson Plan 2GSSD
- BGV09
- Data Structure
- Computer Science 2001 Question Paper
- howto-sorting.pdf
- Array and Enum
- csesyllabus2to4year.pdf
- 2620005 Programming Skills
- gcse-11

You are on page 1of 6

(An Autonomous Institute Under UGC act 1956 & affiliated to R.T.M. Nagpur University)

3 Semester A

TAE-1

Technical Report

on

SELECTION SORT

Submitted By:

1. Aishwarya Shirod[A-01]

2. Ashu Pawar[A-04]

3. Manaswi Mate[A-16]

4. Minakshi Jaiswal[A-18]

INTRODUCTION:

One of the basic problems of computer science is sorting a list of items. It refers to the

arranging of numerical or alphabetical or character data in statistical order (either in

increasing order or decreasing order) or in lexicographical order (alphabetical value like

addressee key) [1-3]. There are a number of solutions to this problem, known as sorting

algorithms. There are several elementary and advanced sorting algorithms. Some sorting

algorithms are simple and spontaneous, such as the bubble sort. Others, such as the quick sort

are enormously complex, but produce super-fast results. Some sorting algorithm work on less

number of elements, some are suitable for floating point numbers, some are good for specific

range, some sorting algorithms are used for huge number of data, and some are used if the list

has repeated values. Other factors to be considered in choosing a sorting algorithm include

the programming effort, the number of words of main memory available, the size of disk or

tape units and the extent to which the list is already ordered . That means all sorting

Algorithms are problem specific, meaning they work well on some specific problem and do

not work well for all the problems. However, there is a direct correlation between the

complexity of an algorithm and its relative effectiveness . Many different sorting algorithms

have been developed and improved to make sorting fast.

The classical bubble sort, selection sort, and insertion sort are very simple

algorithms, often included in the text books to introduce algorithms and

sorting, having runtime complexity of (n2) making them impractical to

use. The selection sort has a slight better running time than the simplest

bubble sort algorithm and worse than the insertion sort.

THEORY:

Here is an example of this sort algorithm sorting 6 elements:

Selection sort can also be used on list structures that make add and remove efficient, such as a

linked list. In this case it is more common to remove the minimum element from the

remainder of the list, and then insert it at the end of the values sorted so far.

ALGORITHM:

Selection Sort (a[], length)

Here a is the unsorted input list and length is the length of array. After completion of the

algorithm array will become sorted. Variable max keeps the location of the maximum value.

1. Repeat steps 2 to 5 until length=1

2. Set max=0

3. Repeat for count=1 to length

If (a[count]>a[max])

Set max=count

End if

4. Interchange data at location length-1 and max

5. Set length=length-1

PROGRAM:

var swap = function(array, firstIndex, secondIndex) {

var temp = array [firstIndex];

array [firstIndex] = array[secondIndex];

array [secondIndex] = temp;

};

var indexOfMinimum = function(array, startIndex) {

var minIndex = startIndex;

if(array[i] < minValue) {

minIndex = i;

minValue = array[i];

}

}

return minIndex;

};

var selection Sort = function(array) {

};

selectionSort(array);

println("Array after sorting: " + array);

ANALYSIS:

Selection sort loops over indices in the array; for each index, selection sort calls

indexOfMinimum and swap. If the length of the array is n, there are n indices in the

array.

Since each execution of the body of the loop runs two lines of code, you might think that 2n2

n2n lines of code are executed by selection sort. But it's not true! Remember that

indexOfMinimum and swap are functions: when either is called, some lines of code are

executed.

How many lines of code are executed by a single call to swap? In the usual implementation,

it's three lines, so that each call to swap takes constant time.

How many lines of code are executed by a single call to indexOfMinimum? We have to

account for the loop inside indexOfMinimum. How many times does this loop execute in a

given call to indexOfMinimum? It depends on the size of the subarray that it's iterating

over. If the subarray is the whole array (as it is on the first step), the loop body runs nnn

times. If the subarray is of size 6, then the loop body runs 6 times.

For example, let's say the whole array is of size 8 and think about how selection sort works.

1. In the first call of indexOfMinimum, it has to look at every value in the array, and

so the loop body in indexOfMinimum runs 8 times.

2. In the second call of indexOfMinimum, it has to look at every value in the subarray

from indices 1 to 7, and so the loop body in indexOfMinimum runs 7 times.

3. In the third call, it looks at the subarray from indices 2 to 7; the loop body runs 6

times.

4. In the fourth call, the subarray from indices 3 to 7; the loop body runs 5 times.

5.

6. In the eighth and final call of indexOfMimimum, the loop body runs just 1 time.

If we total up the number of times the loop body of indexOfMinimum runs, we get 8 + 7 +

6 + 5 + 4 + 3 + 2 + 1 = 36 times.

Best case: in every pass statement 5 will be executed just once and hence the comparison in

statement 6 will be accomplished also once and hence, T(n) = n-1 = O(n). The best-case

complexity of the classical selection sort is O(n2).

Worst case: in the iteration no k, when k-1 items are already sorted and n-k+1 items are still

unsorted, n-k comparisons are required to find the largest element. Thus in this case T(n) =

(n-1) + (n-2) +(n-3) + . + 3 + 2 + 1 = n(n-1)/2 = (n2-n)/2 = O(n2).

Average case: probabilistically an item is greater than half of the items in the list and smaller

than the other half in the list. So, in iteration k, when k-1 items are already sorted and n-k+1

items are still unsorted, (n-k)/2 comparisons are required to find the current maximum. This

leads to T(n) = ((n-1) + (n-2) + (n-3) + . + 3 + 2 + 1)/2 = n(n-1)/4 = (n2-n)/4 = O(n2).

CONCLUSION:

Sorting a list of items into ascending or descending order can help either a human or a

computer find items on that list quickly, perhaps using an algorithm like binary search.

JavaScript has a built-in sorting method. It works on arrays of numbers, or even on arrays of

strings.

Even though JavaScript has a built-in sorting method, sorting is a great example of how there

may be many ways to think about the same problem, some perhaps better than others.

Understanding sorting is a traditional first step towards mastery of algorithms and computer

science.

REFERENCES:

1] Khan Academy

[https://www.khanacademy.org/computing/computer-science/algorithms/sortingalgorithms/a/analysis-of-selection-sort]

2] PDF attached.

- 05987184Uploaded bySahilYadav
- Artificial IntelligenceUploaded byRejoice Chikutye
- My Summary for CS001x_Computer Science for BeginnersUploaded byIbrahim Omar
- Arrays Intersection : Programming FortranUploaded byYang Yi
- 3sumUploaded byAakash Parkash
- INDEX SORTUploaded byAI Coordinator - CSC Journals
- Fd_data Struct Algor_AIA En_an2 s1Uploaded byCalin Vlasin
- Csci 5454 HwUploaded byRamnarayan Shreyas
- SelectionSort With JavaUploaded byArpit Gupta
- HCL_PlacementPapersUploaded byChetan Sharma
- Excel VBAMacrosUploaded byAbhishek Suryawanshi
- Lesson Plan 2GSSDUploaded bykiransree
- BGV09Uploaded byAnonymous RrGVQj
- Data StructureUploaded byAshwin Kumar
- Computer Science 2001 Question PaperUploaded bybaluchandrashekar2008
- howto-sorting.pdfUploaded byAmar Deep
- Array and EnumUploaded byNithin Ricky
- csesyllabus2to4year.pdfUploaded byPrikshit Rana
- 2620005 Programming SkillsUploaded byPragnesh Patel
- gcse-11Uploaded byPrashantBhattacharji
- 10 Ch12 Query ProcessingUploaded byanon1326
- CSE680-07QuickSort(1)Uploaded byGaspar dela Rosa Jr.
- 282-28Uploaded byNagesh Khandare
- Mt Cheat SheetUploaded byoscar6zhen
- Vectors and Array ListsUploaded byjanamaisie
- Vectors_in_PETScUploaded byZakaria Bendifallah
- ArraysUploaded byAbdullah Anjum
- hwUploaded byAnonymous tRCCfL
- arraysUploaded byMoulika Sushma Buragadda
- chapter 1Uploaded bySandeep Goyal

- Vortex FlowUploaded bybachayadav
- Self Study ReportUploaded bybachayadav
- Important Topics For GATE.pdfUploaded byVivek Bhatia
- How to Use Virtual CalculatorUploaded byRobin Flyer
- one dimensional flowUploaded bybachayadav
- Presentation on motor oilsUploaded bybachayadav
- Sbi Clerk Mock paperUploaded bybachayadav
- English Grammar BookUploaded byIsmeet Singh
- presentation on value added taxUploaded bybachayadav
- ElectromagnetismUploaded byEralyn Ebon
- Lubrication in I. C. EngineUploaded bybachayadav
- After Gate by s k mondalUploaded bysonalibara
- lec18Uploaded bybachayadav
- Thermo - Hydrulic Turbine - Dimensional AnlysisUploaded bybachayadav
- Unconventional Machining Process Student CopyUploaded bybachayadav
- M4L3slidesUploaded bybachayadav
- Impact of JetUploaded bybachayadav
- GATE ColumnUploaded bybachayadav
- Unit-3-61.pdfUploaded byDeepankumar Athiyannan
- FP 1 Objective QuestionsUploaded bybachayadav
- GATE IES Thin Cylinder and SpringUploaded bybachayadav
- ME IES 2014 Objective Paper IIUploaded bybachayadav
- ME IES 2014 Conventional Paper IUploaded bybachayadav
- ME IES 2014 Objective Paper IUploaded bybachayadav
- StaticsUploaded byNurul 'Uyun Ahmad
- ME-GATE'14-Paper-03Uploaded byAjendra Singh
- Sridhar ResumeUploaded bybachayadav
- MQCUploaded bybachayadav

- Pointer_Introduction.pdfUploaded byramy86
- Hdd SerialUploaded byAndres Marchorro
- Basic JavaUploaded byanu224149
- Appendix Q - Answers to Odd-Numbered Review QuestionsUploaded byJacobmmcdonald
- Distributed SchedulingUploaded byAanchal Arora
- chap-5Uploaded byBlack Sword
- jav_J2eeUploaded byapi-26483995
- 1. What Type of Errors Are Checked During Compilation (a)Uploaded byAndrew Johnson
- 1.Language Fundamentals of javaUploaded byArnav Vaid
- doc_view[1]Uploaded byRicardo Cardenas Corpus
- Mat LabUploaded byVaitheeshwaran Adhusudan
- codeigniter.pdfUploaded byRyanbimaji
- AdvancedQTPBookUploaded byIndrani Maity
- CLIREFERENCE EQUALLOGIC FRCUploaded byFredy Ricse
- VHDL PPTUploaded byuninorsasta
- Data StructuresUploaded byRavi Prasad
- Data StructuresUploaded byMcaif
- N-person games with crossing payoff functionsUploaded byMiklos N. Szilagyi
- Tutorial 6 LecturerUploaded byRushane Wallace
- 03 Stream GridUploaded byTravis Chen
- Comp vivaUploaded byVenkata Sivaram
- 03-CCFP4.0_OOP Using JavaUploaded byVishal Iyer
- CMPL Instuction Bulletin.pdfUploaded byAlfredo Ap
- Mcs-21Uploaded byfirstname234
- Automated Test GenerationUploaded byUsman Ali
- Hash i Mbyllur KuadratikUploaded byBruna Kapaj
- MoviDrive Drive Inverters DFD11A DeviceNet Fbus Interface ManualUploaded bytom corvin
- Multiple Choice questionUploaded byNikhil Prakash
- The Computer Book _where you can learn more__ C - programming.pdfUploaded byPrafull
- Chapter_3Uploaded byRuthira Nair AB Krishenan