Free Essay

Sorting Algorithms

In:

Submitted By mpriyanka85
Words 841
Pages 4
REVIEW ON SORTING ALGORITHMS
A comparative study on two sorting algorithms
By
Pooja Adhikari
A Term Paper
Submitted to the Faculty of Dr. Gene Boggess
Mississippi State University
In the Department of Computer Science & Engineering
Mississippi State, Mississippi
04 20072

ABSTRACT Any number of practical applications in computing requires things to be in order. The performance of any computation depends upon the performance of sorting algorithms.
Like all complicated problems, there are many solutions that can achieve the same results. One sort algorithm can do sorting of data faster than another. A lot of sorting algorithms has been developed to enhance the performance in terms of computational complexity, memory and other factors. This paper choose two of the sorting algorithms among them selection sort and shell sort and compares the various performance factor among them.
1. INTRODUCTION
Sorting is the rearrangement of things in a list into their correct lexicographic order. A number of sorting algorithms have been developed like include heap sort , merge sort, quick sort, selection sort all of which are comparison based sort .There is another class of sorting algorithms which are non comparison based sort. This paper gives the brief introduction about sorting algorithms [2] where it discuss about the class of sorting algorithms and their running times. It mainly analyses the performance between two sorting algorithms .Selection sort [3] and Shell sort [5].
Selection sort is the simple sorting method with a very simple sorting algorithm [3].
However the running time of this algorithm is not that optimal as compared to performance of best sorting algorithm .The analysis of the running time [4] concludes this thing. Shell sort is another comparison based sorting algorithm which is better than selection sort [5] and works in a gap sequence [7]. The running time and the performance analysis
[6] shows that although its performance is better than the selection sort, there are other various factor that needs to be keep in mind.
The advantages of selection sort contain within it a lot of disadvantage and so are shell sort [8].However there are equally important and is best for a particular purpose.
2. SORTING Sorting is one of the basic operations that are performed by many computers since handling the data in a certain order is more efficient than handling the randomized data.3
There are different kinds of sorting algorithms .Two common sorting algorithms among them are: Selection Sort and Shell Sort
3. SELECTION SORT
Selection sort is one of the simplest algorithms. It is actual an improvement in performance of bubble sort. This algorithm is called selection sort because it works by selecting a minimum element in each step of the sort. This algorithm, iterating through a list of n unsorted items, has a worst-case, average-case, and best-case runtime of Θ (n
2
), assuming that comparisons can be done in constant time. The
Selection sort spends most of its time trying to find the minimum element in the
"unsorted" part of the array. The brief algorithm for selection sort is given below. SELECTION_SORT (A) Cost of Each Step
1. for i ← 0 to n-1 do O(n)
2. min ← i; O(1)
3. for j ← i + 1 to n do O(n
2
)
4 If A[j] < A[min] then O(1)
5. min←j O(1)
6. swap(A[i] ,A[min]) O(1)
Total run time Cost== Θ (n
2
) asymptotically
It works as follows:
1. Find the smallest element using a linear scan.
2. Swap the element with the element in first position.
3. Find the second smallest element in the remaining array.
4. Then swap to the second position.
5. Continue the steps until a sorted list is obtained.4
4. PERFORMANCE ANALYSIS OF SELECTION SORT For each value of element until n it needs to compare and check whether there is any value smaller than it and needs (n-1) comparisons. Thus it can be easily seen that run time complexity of selection sort is Θ (n
2
) due to the line no.3.But since it just requires the Θ (n) swaps means linear order writes to the memory which is optimal to any sorting algorithm .
Table 1. further clarifies the above statement. The running time is obtained by calculating how many times the line 4 of the above algorithm got executed on the specified array size. Number of Array Elements Running Time
8 28
16 120
32 496
64 2016
128 8128
256 32640 Table 1. Running time of selection sort From the above table it is clear that this naive approach is very good for small number of elements. But it requires the comparison of every element to every other element which will lead to a great deal of work for large data sets.
The worst case occurs if the array is already sorted in descending order. Nonetheless, the time require by selection sort algorithm is not very sensitive to the original order of the array to be sorted: the test "if A[j]

Similar Documents

Premium Essay

Clump Sort

...Sort For Sorting Medical Data Visvasuresh Victor Govindaswamy Computer Science Texas A&M University-Texarkana Texarkana, USA lovebat814@yahoo.com Matthew Caudill Computer Science Texas A&M University-Texarkana Texarkana, USA Jeff Wilson Computer Science Texas A&M University-Texarkana Texarkana, USA Daniel Brower Computer Science Texas A&M University-Texarkana Texarkana, USA G. Balasekaran, FACSM Medical and Sports Science Nanyang Technology University Singapore Abstract—Sorting data sets are a thoroughly researched field. Several sorting algorithms have been introduced and these include Bubble, Insertion, Selection, Shell, Quick, Merge and Heap. In this paper, we present a novel sorting algorithm, named Clump Sort, to take advantage of ordered segments already present in medical data sets. It succeeds in sorting the medical data considerably better than all the sorts except when using totally non-clumped data. In this test using totally nonclumped data, Heap sort does only slightly better than Clump sort. However, Clump sort has the advantage of being a stable sort as the original order of equal elements is preserved whereas in Heap sort, it is not since it does not guarantee that equal elements will appear in their original order after sorting. As such, Clump Sort will have considerably better data cache performance with both clumped and non-clumped data, outperforming Heap Sort on a modern desktop PC, because it accesses the elements in order. Sorting equal...

Words: 1753 - Pages: 8

Free Essay

Reserch Paper on Sorting and Dictionaries

...study on sorting and dictionaries Sujeet Kumar Department of Information and technology Dronacharya College of Engineering, Gurgaon-122001, India Email:sujeet.16939@ggnindia.dronacharya.info, Ashish Gupta Department of Information and technology Dronacharya College of Engineering, Gurgaon-122001, India Email:ashish.16907@ggnindia.dronacharya.info Abstract-Arrays and linked lists are two basic data structures used to store information. We may wish to search, insert or delete records in a database based on a key value. This section examines the performance of these operations on arrays and linked lists. In this research paper we studied about the sorting and types of sorting. This is followed by techniques for implementing dictionaries, structures that allow efficient search, insert, and delete operations. We have also illustrated algorithms that sort data and implement dictionaries for very large files Keywords-insertion sort, quick sort, sort ,binary search tree, skip list. 1. Introduction Arrays and linked lists are two basic data structures used to store information. We may wish to search, insert or delete records in a database based on a key value. This section examines the performance of these operations on arrays and linked lists. 1.1 Arrays Figure 1-1 shows an array, seven elements long, containing numeric values. To search the array sequentially, we may use the algorithm...

Words: 2248 - Pages: 9

Free Essay

Programming

...TeamLRN Robert Lafore Teach Yourself Data Structures and Algorithms in 24 Hours 201 West 103rd St., Indianapolis, Indiana, 46290 USA Sams Teach Yourself Data Structures and Algorithms in 24 Hours Copyright © 1999 by Sams Publishing All rights reserved. No part of this book shall be reproduced, stored in a retrieval system, or transmitted by any means, electronic, mechanical, photocopying, recording, or otherwise, without written permission from the publisher. No patent liability is assumed with respect to the use of the information contained herein. Although every precaution has been taken in the preparation of this book, the publisher and author assume no responsibility for errors or omissions. Neither is any liability assumed for damages resulting from the use of the information contained herein. International Standard Book Number: 0-672-31633-1 Library of Congress Catalog Card Number: 98-83221 Printed in the United States of America First Printing: May 1999 01 00 99 4 3 2 1 EXECUTIVE EDITOR Brian Gill DEVELOPMENT EDITOR Jeff Durham MANAGING EDITOR Jodi Jensen PROJECT EDITOR Tonya Simpson COPY EDITOR Mike Henry INDEXER Larry Sweazy PROOFREADERS Mona Brown Jill Mazurczyk TECHNICAL EDITOR Richard Wright Trademarks All terms mentioned in this book that are known to be trademarks or service marks have been appropriately capitalized. Sams Publishing cannot attest to the accuracy of this information. Use of a term in this...

Words: 10065 - Pages: 41

Free Essay

Sorting

...four methods. c. Comment on the results and compare them to the average-case complexities discussed in class.  As we discussed in the class, all these sorting algorithms I used for testing have the same average-case complexities with O (n log n). But the data I got which shows in the upper diagram illustrate that Quick sort is the most fast sorting method especially when you need to sort a large amount of data. Dual-pivot quicksort is also fast than merge sort and Heap sort. Heap sort can be used when the pending data between 1000-1000, 000, and for Merge sort is the first choice when there are more than 1M data. 3. Do the following for the four sorting methods of #2, and for Radix sort: a. Create 100,000 random strings of length 4 and sort them using the five sorting methods. b. Repeat (a) 10 times Compute the average CPU time taken to sort the keys for the five methods. c. Repeat (a) and (b) with strings of length 6, 8, 10. d. Create a table with the results and compare the times with the average-case and worstcase complexities as studied in class.  The length of string is 4: The length of string is 6: The length of string is 8: The length of string is 10:   The upper diagrams and tables show that when the length of string changed, the total using time of five kinds of different sorting methods are diverse. And we can see that when string’s length is 4, Radix sort used the least time to sort 100000 random strings while Heap sort was the lowest...

Words: 910 - Pages: 4

Premium Essay

Sort

...Heap Sort For Sorting Medical Data Visvasuresh Victor Govindaswamy Matthew Caudill Jeff Wilson Computer Science Texas A&M University-Texarkana Texarkana, USA lovebat814@yahoo.com Computer Science Texas A&M University-Texarkana Texarkana, USA Computer Science Texas A&M University-Texarkana Texarkana, USA Daniel Brower G. Balasekaran, FACSM Computer Science Texas A&M University-Texarkana Texarkana, USA Medical and Sports Science Nanyang Technology University Singapore Abstract—Sorting data sets are a thoroughly researched field. Several sorting algorithms have been introduced and these include Bubble, Insertion, Selection, Shell, Quick, Merge and Heap. In this paper, we present a novel sorting algorithm, named Clump Sort, to take advantage of ordered segments already present in medical data sets. It succeeds in sorting the medical data considerably better than all the sorts except when using totally non-clumped data. In this test using totally nonclumped data, Heap sort does only slightly better than Clump sort. However, Clump sort has the advantage of being a stable sort as the original order of equal elements is preserved whereas in Heap sort, it is not since it does not guarantee that equal elements will appear in their original order after sorting. As such, Clump Sort will have considerably better data cache performance with both clumped and non-clumped data, outperforming Heap Sort on a modern desktop PC, because it accesses the elements in order. Sorting equal elements...

Words: 1753 - Pages: 8

Premium Essay

Computer Science

...Structures & Algorithms Using C- R.S Salaria-2nd Edition 4.Data Structures,Algorithms and applications in C++ --Sartaj Sahni—2nd Edition 5.PC Hardware in a Nutshell-Robert Bruce Thomsan and Barbara Fritchman Thomsan—July2003 :Second Edition Other readings: |Sr.No. |Journal articles as compulsory readings (Complete reference) | |6. |Cisco system advanced exam guide-CISCO press | |7. |Cisco system CCNA Exam dump guide –CISCO press | Relevant websites: |S.No. |Web address |Salient Features | |8. |http://www.java2s.com/Tutorial/C/0260__Data-Structure |A web page on Data Structure| | | |in C | |9. |http://www.java2s.com/Code/C/Data-Structure-Algorithm/CatalogData-Structure-Algorithm.htm |A web page on | | | |Searching/Sorting Techniques| ...

Words: 1499 - Pages: 6

Free Essay

Algorithms Notes

...3PART ONE * Lecture 1 (01/09) Posted on: Monday, January 28, 2013 Topics: Stable Matching Reading: class handout * Lecture 2 (01/14) Posted on: Thursday, January 24, 2013 Topics: Graph Representation, BFS, DFS Reading: CLRS (Sections 22.1, 22.2, 22.3), KT (3.2, 3.3) Notes: 2 possible representations of a graph 1. Adjacency Matrix-used for dense graphs (V2 memory space) a. Aij=1 if edge exists between I and J but 0 if not 2. Adjacency List- Used for sparse graphs (V+E memory space or V+2E for undirected) b. Array adj of |V| lists, one for each vertex. c. Adj[u] contains all vertices adjacent (or reachable by one edge) to u Breadth First Search(G,s) BFS.G; s/ 1 for each vertex u in G.V –{s} 2 u.color = WHITE 3 u.disc =∞ 4 u.parent= NIL 5 s.color = GRAY 6 s.disc = 0 7 s.parent= NIL 8 Q = ∅; 9 ENQUEUE(Q,s) 10 while Q ≠ ∅ 11 u = DEQUEUE(Q) 12 for each v in G.Adj[u] 13 if v.color == WHITE 14 v.color = GRAY 15 v.disc = u.disc + 1 16 v.parent = u 17 ENQUEUE(Q,v) 18 u.color = BLACK White means not discovered yet, grey mean discovered but not finished, black means finished. Run time O(V+E) BFS gives shortest path from s to every vertex Lemma: x in Li and Y in Lj and edge (x,y) exists Then |i-j| less than or equal to 1 Depth First search Properties: 1) v is a descendenant of u iff v if discovered when u is gray 2) Parenthesis theorem, u and v in V. either discovery and finish times are...

Words: 5019 - Pages: 21

Free Essay

Research Paper

... . 19 Chapter 4 Linked Lists. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 Chapter 5 Trees and Graphs. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61 Chapter 6 Arrays and Strings. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85 Chapter 7 Recursion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107 . . Chapter 8 Sorting. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ....

Words: 48008 - Pages: 193

Premium Essay

Comparative Analysis Of Sorting Algorithm

...COMPARATIVE ANALYSIS OF VARIOUS SORTING ALGORITHM ABSTRACT: Sorting is a commonly used operation in computer science. In addition to its main job, sorting is often required to facilitate some other operation such as searching, merging and normalization. A sorting algorithm consists of comparison, swap, and assignment operations. There are several elementary and advanced sorting algorithms that are being used in practical life as well as in computation such as Quick sort, Bubble sort, Merge sort, Bucket sort, Heap sort, Radix sort etc. But the application of these algorithms depends on the problem statement. This paper introduces MQ sort which combines the advantages of quick sort and Merge sort. The comparative analysis of performance and complexity...

Words: 2578 - Pages: 11

Free Essay

Quick Sort Analysis

...Here is an analysis of the time complexity of quick-sort in detail. In quick sort, we pick an element called the pivot in each step and re-arrange the array in such a way that all elements less than the pivot now appear to the left of the pivot, and all elements larger than the pivot appear on the right side of the pivot. In all subsequent iterations of the sorting algorithm, the position of this pivot will remain unchanged, because it has been put in its correct place. The total time taken to re-arrange the array as just described, is always O(n)1 , or αn where α is some constant [see footnote]. Let us suppose that the pivot we just chose has divided the array into two parts - one of size k and the other of size n − k. Notice that both these parts still need to be sorted. This gives us the following relation: T (n) = T (k) + T (n − k) + αn where T (n) refers to the time taken by the algorithm to sort n elements. WORST CASE ANALYSIS: Now consider the case, when the pivot happened to be the least element of the array, so that we had k = 1 and n − k = n − 1. In such a case, we have: T (n) = T (1) + T (n − 1) + αn Now let us analyse the time complexity of quick sort in such a case in detail by solving the recurrence as follows: T (n) = T (n − 1) + T (1) + αn = [T (n − 2) + T (1) + α(n − 1)] + T (1) + αn (Note: I have written T (n − 1) = T (1) + T (n − 2) + α(n − 1) by just substituting n − 1 instead of n. Note the implicit assumption that the pivot that was chosen divided the original...

Words: 1014 - Pages: 5

Free Essay

Ffff

...CS201 Final Study Guide I. Basic Linux Commands a. cd – change directory b. mkdir – make directory c. ls – show contents of directory II. Variables in Python d. Variables do not need to be declared e. Must start with a letter or “_” i. can contain numbers f. **variable names are case sensitive! ii. Use camel case: 1. newValue 2. studentAverage 3. setAverageGrade g. Initializing a variable: iii. 3 2 1 iv. variable = value h. Order of Operations: v. HIGHEST PRIORITY: not ** vi. * / % vii. + - viii. < <= > >= ix. == != x. and xi. LOWEST PRIORITY: or III. Python Data Types (int, float, strings, lists, boolean, NoneType) and the type function i. Int – integer numbers: 5, 6, 3, 25, etc. j. Float – decimals: 5.0, 3.50, 25.4, etc. k. String – string of words or a phrase: “Hello World” etc. l. List – a list of values contained within brackets: [1, 4, 3, 25] m. Boolean – True/False ...

Words: 4622 - Pages: 19

Premium Essay

It 265 Data Structures Phase 5

...Summary 4 Phase 1 4 Phase 2 4 Phase 3 4 Phase 4 4 Phase 5 5 Section 1: Lists, Stacks, and Queues 6 Stacks 6 Queues 10 Section 2: Hashing, Heaps and Trees 14 Section 3: Sorting Algorithms 20 Insertion sort 20 Bubble Sort 20 Selection sort 21 Section 4: Searching 22 Array 22 Linked Lists 23 Section 5: Recursion 30 References 33 Executive Summary Phase 1          A list is a collection of items in which the items have a position (Weiss, 2010).  A linked list allows data to be input or removed easily because each of the data items in the list is connected to its neighbor by a pointer that can be quickly and easily modified to accommodate new or removed items (CTU M.U.S.E. 2014). The Phase 1 portion of this document will be demonstrating the implementation of Stacks and Queues. Phase 2 Hash tables can be viewed as an array of lists and are used to speed up a search for data by creating a situation that does not require the search to start at the beginning and go through every item. The identifying value is the key and the associated record is the data, thus a hash table is a collection of (key, value) pairs. Phase 3 In order to efficiently use a database, the data must be stored in some sort of order. There are a number of different sorting algorithms; a programmer would choose which one to use depending on the amount and type of data being sorted. Insertion sort, Bubble sort, and Selection sort are described with examples. Phase 4 ...

Words: 3704 - Pages: 15

Free Essay

The Final Touch

...INDUSTRIAL TRAINING FROM TATA CMC, JAMMU ON EMBEDDED SYSTEMS. Submitted in the partial fulfilment of requirement for the award of degree of Bachelor of Engineering In Electronics and Communication Engineering Submitted By Ashish Gupta 258/12 Under the guidance of Ms. Sonika Mahajan IT Guide Department of Electronics & Communication Engineering Mahant Bachittar Singh College of Engineering and Technology, Jammu 2015 CERTIFICATE i DECLARATION I hereby declare that the Seminar Report entitled “EMBEDDED SYSTEMS” is an authentic record of my own work carried out as requirement for the award of degree of B.E. (E&C) of Mahant Bachittar Singh College of Engineering & Technology, Jammu. Date: ................ Ashish Gupta 258/12 Certified that the above statement made by the student is correct to the best of my knowledge and belief. Ms. Sonika Mahajan Ms. Neha Gupta Ms. Shalini Sharma IT Guide ...

Words: 998 - Pages: 4

Free Essay

Arrays

...CHAPTER 5 – ARRAYS CASE STUDY SCENARIO Sorting Data A dozen umbrellas lie on the ground just inside the classroom door when Dr. Taylor begins his lecture. “A cold, rainy day like today makes me want to stay in and order pizza for delivery rather than go out myself.” Handing a phone book to a student in the front row, Dr. Taylor says “Gail, please look up the phone number for Domino’s Pizza on Main Street, and if you don’t mind, I will time how long it takes you to find the number.” Gail flips through a few pages while Dr. Taylor looks at his watch. “Here it is . . . 555-8275,” she says. “Seven seconds. Thank you Gail.” Dr. Taylor presses some keys on his cell phone while continuing his conversation. “Now please look up the name of the person with the phone number 555-5982, and again I will time you.” Dr. Taylor’s focus returns to his watch even as he speaks into the phone. Gail slowly flips a couple of pages, then stops just about the same time Dr. Taylor ends his call. “I assure you the number is in there, Gail. We will wait while you look it up.” “You will probably wait a long time,” she says, “because there is no fast way to find a number.” “Why not? It’s the same data.” “But the phone book is sorted by names, so finding a name is easy. Finding a number is very difficult because a phone book is not sorted by numbers.” Dr. Taylor takes the phone book from Gail. “Exactly! The sorting process does not change the data, but it organizes the data in a context...

Words: 5653 - Pages: 23

Free Essay

Thesis

...1. Factorial program in cFactorial program in c: c code to find and print factorial of a number, three methods are given, first one uses for loop, second uses a function to find factorial and third using recursion. Factorial is represented using '!', so five factorial will be written as (5!), n factorial as (n!). Alson! = n*(n-1)*(n-2)*(n-3)...3.2.1 and zero factorial is defined as one i.e. 0! = 1. #include <stdio.h>   int main() { int c, n, fact = 1;   printf("Enter a number to calculate it's factorial\n"); scanf("%d", &n);   for (c = 1; c <= n; c++) fact = fact * c;   printf("Factorial of %d = %d\n", n, fact);   return 0; } 2. c program to check odd or evenc program to check odd or even: We will determine whether a number is odd or even by using different methods all are provided with a code in c language. As you have study in mathematics that in decimal number system even numbers are divisible by 2 while odd are not so we may use modulus operator(%) which returns remainder, For example 4%3 gives 1 ( remainder when four is divided by three). Even numbers are of the form 2*p and odd are of the form (2*p+1) where p is is an integer. #include<stdio.h>   main() { int n;   printf("Enter an integer\n"); scanf("%d",&n);   if ( n%2 == 0 ) printf("Even\n"); else printf("Odd\n");   return 0; } 3. C program to check whether input alphabet is a vowel or notThis code checks whether an input alphabet is a vowel...

Words: 7510 - Pages: 31