Sie sind auf Seite 1von 21

Project Report

For

Performance Analysis of Sorting


Algorithms

Version 1.0 approved

Prepared by
Taha Hussain(60810)
Faraz Ahmed(59468)

PAF-KIET
15-April-2019
Project Report for Performance Analysis of Sorting Algorithms

Table of Contents
Table of Contents...........................................................................................................................ii
Revision History.............................................................................................................................ii
1. Introduction..............................................................................................................................1
1.1 Purpose...........................................................................................................................................1
1.2 Document Conventions....................................................................................................................1
1.3 Intended Audience and Reading Suggestions...................................................................................1
1.4 Product Scope.................................................................................................................................1
1.5 References.......................................................................................................................................1
2. Overall Description..................................................................................................................2
2.1 Product Perspective.........................................................................................................................2
2.2 Product Functions...........................................................................................................................2
2.3 User Classes and Characteristics.....................................................................................................2
2.4 Operating Environment...................................................................................................................2
2.5 Design and Implementation Constraints..........................................................................................2
2.6 User Documentation........................................................................................................................2
2.7 Assumptions and Dependencies.......................................................................................................3
3. External Interface Requirements............................................................................................3
3.1 User Interfaces................................................................................................................................3
3.2 Hardware Interfaces........................................................................................................................3
3.3 Software Interfaces.........................................................................................................................4
3.4 Communications Interfaces.............................................................................................................4
4. System Features........................................................................................................................5
4.1 System Feature 1.............................................................................................................................5
4.2 System Feature 2 (and so on)..........................................................................................................5
5. Other Nonfunctional Requirements.......................................................................................6
5.1 Performance Requirements..............................................................................................................6
5.2 Safety Requirements........................................................................................................................6
5.3 Security Requirements.....................................................................................................................6
5.4 Software Quality Attributes.............................................................................................................6
6. Source Code……………………………………………………………………………………7
7. GUI…………………………………………………………………………………………….19
Appendix A:Development………………………………………………………………………20
Appendix B: Software..................................................................................................................20

Revision History
Name Date Reason For Changes Version
Project Report for Performance Analysis of Sorting Algorithms

1. Introduction

1.1 Purpose
Performance analysis refers to the task of determining how much computing time and storage an
algorithm requires. The space complexity of a program is the amount of memory it needs to run to
completion. The time complexity of a program is the amount of computer time it needs to run to
completion. Sorting refers to the operation of arranging data in some given order, such as increasing
or decreasing with numerical data or alphabetically with character data. All sorting algorithm apply to
specific kind of problems. Some sorting algorithm apply to small number of elements, some sorting
algorithm suitable for floating point numbers, some are fit for specific range like (0 1). Some sorting
algorithm are used for large number of data, some are used for data with duplicate values.

1.2 Document Conventions


This document is created on Microsoft Word 2013, and the font-family used in this document
contains font type 'Times New Roman' and font size '12' and line spacing '1'. Headings used the bold
style.

1.3 Intended Audience and Reading Suggestions


All individuals who are participating and who are supporting/supervising this project "Biometric
Attendance System" are the intended audience. Readers who are interested in introduction or
objectives of project, should concentrate on the Chapter 1 (Introduction) as well as Chapter 3
(Overall Description) of the document.

Readers who wants to read about the features of Biometric Attendance System should focus on part
3 'System Features', in which all features are described and discussed in detail. Part 3 also describing
interface requirements (external) and software and hardware requirement.

1.4 Product Scope


This study also aims to collect the runtime data of different sorting algorithms in order to compare
their implementation variants from a practical perspective. Quantities of interest include the number
of operations of different types that are executed, the resulting absolute running time, and the
memory space consumption. Such data can be collected by using a tailor-made package. The goal is
to gather and evaluate data that makes a detailed analysis of the practical efficiency of the algorithms
and their concrete implementations possible. The experiment will be repeated on different Test Cases
for instance, different types of input data, such as arrays of numbers and strings of different sizes.

1.5 References
[1] Knuth, D. The Art of Computer Programming Sorting and Searching, 2nd edition, 3. Addison-
Wesley, (1998).
Project Report for Performance Analysis of Sorting Algorithms

[2] Wirth, N., 1976. Algorithms + Data Structures = Programs: Prentice-Hall, Inc. Englewood Cliffs,
N.J.K.Mehlhorn. Sorting and Searching. Springer Verlag, Berlin, (1984).
[3] LaMarca and R. Ladner. The Influence of Caches on the Performance of Sorting. In Proceeding
of the ACM/SIAM Symposium on Discrete Algorithms, (January 1997), 370–379.
[4] Hoare, C.A.R. Algorithm 64: Quicksort. Comm. ACM 4, 7 (July 1961), 321. 242-250, 242-250.
[5] .lores, I. Analysis of Internal Computer Sorting. J.ACM 7, 4 (Oct. 1960), 389-409.
[6] .lores, I. Analysis of Internal Computer Sorting. J.ACM 8, (Jan. 1961), 41-80.

2. Overall Description

2.1 Product Perspective


The analysis of algorithm defines that the estimation of resources required for an algorithm to solve a
given problem. Sometimes the resources include memory, time and communication bandwidth. In
which running time and memory required are of primary concern for the reason that algorithms that
needed a month or year to solve a problem is not useful. Besides that, it also requires gigabytes of
main memory to solve a problem and is not efficient. In general, to find a suitable algorithm for a
specific problem we have to analyze several possible algorithms.

2.2 Product Functions


In computer science, generally we use some notation to illustrate the asymptotic running time of
algorithms which are defined in terms of functions whose domains are the set of natural numbers and
sometimes real numbers. There are five 12 standard asymptotic notations advanced in which we
examine three basic asymptotic notations such as Big-O, Big-Ω and Big-Θ. Big-O Notation.

2.3 User Classes and Characteristics


Using this project, user can analyze which sorting algorithm is fast.

2.4 Operating Environment


In order to handle the continuous activity, we have to use real time processor with memory allocation
(dynamically). Interfaces of user and software should be easy to use, simple and user friendly.

2.5 Design and Implementation Constraints


The Design Phase of the project started in early September, and this project is developed by using
Visual Studio, SQL Management Studio. It is divided into two phases. In the very first phase,
feasibility study is conducted, requirement analysis is carried out to understand the need for the
system.
Project Report for Performance Analysis of Sorting Algorithms

2.6 User Documentation


To facilitate with the process of managing information of students and teachers record management,
mark attendance is the main objective of Biometric Attendance System. The application will be
designed simple and easy for use. But user still require information and description of each feature
and function of application to utilize.

2.7 Assumptions and Dependencies


User first upload the file then use functionalities of project.

3. External Interface Requirements

3.1 User Interfaces


The way through which user interacts with an application, and facilitate by its each function and
feature is the interface which is called to be user interface, where user see the screen or front end of
application. User can navigate options and menus by using mouse and keyboard. By clicking any
option from menu you can move to other web page of application or if you want to go back to the
previous page so it is also very easy.

3.2 Hardware Interfaces


Hardware interface include computers and laptops.

3.3 Software Interfaces

 We are using Windows Operating System for user friendliness


 We are implementing this software in Visual Studio because we have chosen C# language.

3.4 Communications Interfaces


This project is built for find which algorithm is perform better.

4. System Features
 Upload file
 Perform analysis of sorting algorithms
Project Report for Performance Analysis of Sorting Algorithms

5. Other Nonfunctional Requirements

5.1 Performance Requirements


The performance of project is based upon good computer.

5.2 Safety Requirements


Data that is stored will not damage internal components of system, it will not affected.

5.3 Security Requirements

Only authenticated users can use the project and the system should be accessed by those users who
have input file.

5.4 Software Quality Attributes


The GUI of project will easy for use and would be user friendly. Number of users of our application
would be increase day by day. Application will flexible because there is multiple types of user and can
access to the application. System should work reliably and recover fast, if system crash due to
maximum load so we can recover it and information/data will not be lost.

6. Source Code
class BubbleSort
{
public int[] Bubble_Sort(int[] arr)
{
int temp = 0; bool swapped = true;
while (swapped == true)
Project Report for Performance Analysis of Sorting Algorithms

{
swapped = false;
for (int i = 0; i < arr.Length - 1; i++)
{
if (arr[i] > arr[i + 1])
{
temp = arr[i];
arr[i] = arr[i + 1];
arr[i + 1] = temp;
swapped = true;
}
}
}

return arr;
}
}
class BucketSort
{
public void bucketSort(int[] data)
{
int minValue = data[0];
int maxValue = data[0];

for (int i = 1; i < data.Length; i++)


{
if (data[i] > maxValue)
maxValue = data[i];
if (data[i] < minValue)
minValue = data[i];
}

List<int>[] bucket = new List<int>[maxValue - minValue + 1];

for (int i = 0; i < bucket.Length; i++)


{
bucket[i] = new List<int>();
}

for (int i = 0; i < data.Length; i++)


{
bucket[data[i] - minValue].Add(data[i]);
}

int k = 0;
for (int i = 0; i < bucket.Length; i++)
{
if (bucket[i].Count > 0)
{
for (int j = 0; j < bucket[i].Count; j++)
{
data[k] = bucket[i][j];
Project Report for Performance Analysis of Sorting Algorithms

k++;
}
}
}
}
}
class CombSort
{
public void Comb_Sort(int[] data)
{
double gap = data.Length;
bool swaps = true;

while (gap > 1 || swaps)


{
gap /= 1.247330950103979;

if (gap < 1)
gap = 1;

int i = 0;
swaps = false;

while (i + gap < data.Length)


{
int igap = i + (int)gap;

if (data[i] > data[igap])


{
int temp = data[i];
data[i] = data[igap];
data[igap] = temp;
swaps = true;
}

++i;
}
}
}

}
class HeapSort
{
public void heapSort(int[] arr, int n) {
for (int i = n / 2 - 1; i >= 0; i--)
heapify(arr, n, i);
for (int i = n-1; i>=0; i--) {
int temp = arr[0];
arr[0] = arr[i];
arr[i] = temp;
heapify(arr, i, 0);
}
Project Report for Performance Analysis of Sorting Algorithms

}
static void heapify(int[] arr, int n, int i) {
int largest = i;
int left = 2*i + 1;
int right = 2*i + 2;
if (left < n && arr[left] > arr[largest])
largest = left;
if (right < n && arr[right] > arr[largest])
largest = right;
if (largest != i) {
int swap = arr[i];
arr[i] = arr[largest];
arr[largest] = swap;
heapify(arr, n, largest);
}
}
}
class InsertionSort
{
public int[] Insertion_Sort(int[] arr)
{
int i, j, key;

for (j = 1; j < arr.Length; j++)


{
key = arr[j];
i = j - 1;
while (i >= 0 && arr[i] > key)
{
arr[i + 1] = arr[i];
i = i - 1;
}
arr[i + 1] = key;
}
return arr;
}

}
class MergeSort
{
public int[] Merge_Sort(int[] arr)
{
//Base Case
if (arr.Length <= 1)
{
return arr;
}

List<int> left = new List<int>();


List<int> right = new List<int>();

for (int i = 0; i < arr.Length; i++)


Project Report for Performance Analysis of Sorting Algorithms

{
if (i % 2 != 0)//ODD
{
left.Add(arr[i]);
}
else//EVEN
{
right.Add(arr[i]);
}
}

left = Merge_Sort(left.ToArray()).ToList();
right = Merge_Sort(right.ToArray()).ToList();

return Merge(left, right);

public int[] Merge(List<int> left, List<int> right)


{
List<int> result = new List<int>();

while (left.Count > 0 && right.Count > 0)


{
if (left.First() <= right.First())
{
result.Add(left.First());
left.RemoveAt(0);
}
else
{
result.Add(right.First());
right.RemoveAt(0);
}
}

while (left.Count > 0)


{
result.Add(left.First());
left.RemoveAt(0);
}

while (right.Count > 0)


{
result.Add(right.First());
right.RemoveAt(0);
}

return result.ToArray();
}
}
class QuickSort
Project Report for Performance Analysis of Sorting Algorithms

{
public void Quick_Sort(int[] arr, int p, int r)
{
int partition;
if (p < r)
{
partition = Partition(arr, p, r);
Quick_Sort(arr, p, partition - 1);
Quick_Sort(arr, partition + 1, r);
}
}

public int Partition(int[] arr, int p, int r)


{
int temp, i, pivot, j;
pivot = arr[r];
i = p - 1;
for (j = p; j < r; j++)
{
if (arr[j] > pivot)
{

}
else if (arr[j] < pivot)
{
i = i + 1;
temp = arr[j];
arr[j] = arr[i];
arr[i] = temp;
}
}
temp = arr[i + 1];
arr[i + 1] = arr[r];
arr[r] = temp;
return i + 1;
}
}
class RadixSort
{
public static int getMax(int[] arr, int n)
{
int mx = arr[0];
for (int i = 1; i < n; i++)
if (arr[i] > mx)
mx = arr[i];
return mx;
}
public static void countSort(int[] arr, int n, int exp)
{
int[] output = new int[n];
int i;
int[] count = new int[10];
Project Report for Performance Analysis of Sorting Algorithms

for (i = 0; i < 10; i++)


count[i] = 0;

for (i = 0; i < n; i++)


count[(arr[i] / exp) % 10]++;

for (i = 1; i < 10; i++)


count[i] += count[i - 1];

for (i = n - 1; i >= 0; i--)


{
output[count[(arr[i] / exp) % 10] - 1] = arr[i];
count[(arr[i] / exp) % 10]--;
}
for (i = 0; i < n; i++)
arr[i] = output[i];
}
public void radixsort(int[] arr, int n)
{
int m = getMax(arr, n);
for (int exp = 1; m / exp > 0; exp *= 10)
countSort(arr, n, exp);

}
public static void print(int[] arr, int n)
{
for (int i = 0; i < n; i++)
Console.Write(arr[i] + " ");
}
}
public class SelectionSort
{
public int[] Selection_Sort(int[] arr)
{
int i, min, j, swap;
for (i = 0; i < arr.Length; i++)
{
min = i;

for (j = i + 1; j < arr.Length; j++)


{
if (arr[j] < arr[min])
{
min = j;
}
}
swap = arr[min];
arr[min] = arr[i];
arr[i] = swap;
}
return arr;
Project Report for Performance Analysis of Sorting Algorithms

}
}
public class ShellSort
{
public void Shell_Sort(int[] array)
{
int n = array.Length;
int gap = n / 2;
int temp;

while (gap > 0)


{
for (int i = 0; i + gap < n; i++)
{
int j = i + gap;
temp = array[j];

while (j - gap >= 0 && temp < array[j - gap])


{
array[j] = array[j - gap];
j = j - gap;
}

array[j] = temp;
}

gap = gap / 2;
}
}
}
public partial class frm_Main : MetroFramework.Forms.MetroForm
{
int[] array;
InsertionSort sr = new InsertionSort();
SelectionSort sls = new SelectionSort();
BubbleSort bbs = new BubbleSort();
RadixSort rs = new RadixSort();
HeapSort hs = new HeapSort();
ShellSort ss = new ShellSort();
BucketSort bs = new BucketSort();
CombSort cs = new CombSort();
MergeSort ms = new MergeSort();
QuickSort qs = new QuickSort();
public frm_Main()
{
InitializeComponent();
}

private void frm_Main_Load(object sender, EventArgs e)


{
panel1.Enabled = false;
}
Project Report for Performance Analysis of Sorting Algorithms

private void btn_Choose_Click(object sender, EventArgs e)


{
string path = null;
string input = null;
List<int> list = new List<int>();
OpenFileDialog ofd = new OpenFileDialog();
if (ofd.ShowDialog() == DialogResult.OK)
{
path = ofd.FileName;
txt_Name.Text = ofd.SafeFileName;
}
StreamReader file = new StreamReader(path);
while ((input = file.ReadLine()) != null)
{
lb_Input.Items.Add(input);
list.Add(int.Parse(input));
}
array = list.ToArray();
panel1.Enabled = true;
panel2.Enabled = false;
}

private void btn_InsertionSort_Click(object sender, EventArgs e)


{
try
{
int[] arr = sr.Insertion_Sort(array);
lb_Output.Items.Clear();
lb_Output.Items.Add("Insertion Sort Output");
Print(arr);
}
catch (Exception excep)
{
MessageBox.Show(excep.Message);
}
}

private void btn_SelectionSort_Click(object sender, EventArgs e)


{
try
{
int[] arr = sls.Selection_Sort(array);
lb_Output.Items.Clear();
lb_Output.Items.Add("Selection Sort Output");
Print(arr);
}
catch (Exception excep)
{
MessageBox.Show(excep.Message);
}
}
Project Report for Performance Analysis of Sorting Algorithms

private void btn_MergeSort_Click(object sender, EventArgs e)


{
try
{
int [] arr= ms.Merge_Sort(array);
lb_Output.Items.Clear();
lb_Output.Items.Add("Merge Sort Output");
Print(arr);
}
catch (Exception excep)
{
MessageBox.Show(excep.Message);
}
}

private void btn_QuickSort_Click(object sender, EventArgs e)


{
try
{
qs.Quick_Sort(array,0,array.Length-1);
lb_Output.Items.Clear();
lb_Output.Items.Add("Quick Sort Output");
Print(array);
}
catch (Exception excep)
{
MessageBox.Show(excep.Message);
}
}

private void btn_BubbleSort_Click(object sender, EventArgs e)


{
try
{
int[] arr = bbs.Bubble_Sort(array);
lb_Output.Items.Clear();
lb_Output.Items.Add("Bubble Sort Output");
Print(arr);
}
catch (Exception excep)
{
MessageBox.Show(excep.Message);
}
}
private void btn_HeapSort_Click(object sender, EventArgs e)
{
try
{
hs.heapSort(array, array.Length);
lb_Output.Items.Clear();
lb_Output.Items.Add("Heap Sort Output");
Project Report for Performance Analysis of Sorting Algorithms

Print(array);
}
catch (Exception excep)
{
MessageBox.Show(excep.Message);
}
}
private void btn_RadixSort_Click(object sender, EventArgs e)
{
try
{
rs.radixsort(array, array.Length);
lb_Output.Items.Clear();
lb_Output.Items.Add("Radix Sort Output");

Print(array);
}
catch (Exception excep)
{
MessageBox.Show(excep.Message);
}

}
private void btn_ShellSort_Click(object sender, EventArgs e)
{
try
{
ss.Shell_Sort(array);
lb_Output.Items.Clear();
lb_Output.Items.Add("Shell Sort Output");
Print(array);
}
catch (Exception excep)
{
MessageBox.Show(excep.Message);
}
}

private void btn_BucketSort_Click(object sender, EventArgs e)


{
try
{
bs.bucketSort(array);
lb_Output.Items.Clear();
lb_Output.Items.Add("Bucket Sort Output");
Print(array);
}
catch (Exception excep)
{
MessageBox.Show(excep.Message);
}
}
Project Report for Performance Analysis of Sorting Algorithms

private void btn_CombSort_Click(object sender, EventArgs e)


{
try
{
cs.Comb_Sort(array);
lb_Output.Items.Clear();
lb_Output.Items.Add("Comb Sort Output");
Print(array);
}
catch (Exception excep)
{
MessageBox.Show(excep.Message);
}
}
private void btn_SortByAll_Click(object sender, EventArgs e)
{
Stopwatch timer = new Stopwatch();
timer.Start();
int[] arr = sr.Insertion_Sort(array);
timer.Stop();
lbl_InsertionTime.Text = timer.Elapsed.TotalMilliseconds.ToString();
lb_Output.Items.Add("Insertion Sort Output");
Print(arr);

timer.Start();
int[] arr1 = sls.Selection_Sort(array);
timer.Stop();
lbl_SelectionTime.Text = timer.Elapsed.TotalMilliseconds.ToString();
lb_Output.Items.Add("Selection Sort Output");
Print(arr1);

timer.Start();
int[] arr2 = ms.Merge_Sort(array);
timer.Stop();
lbl_MergeTime.Text = timer.Elapsed.TotalMilliseconds.ToString();
lb_Output.Items.Add("Merge Sort Output");
Print(arr2);

timer.Start();
qs.Quick_Sort(array, 0, array.Length - 1);
timer.Stop();
lbl_QuickTime.Text = timer.Elapsed.TotalMilliseconds.ToString();
lb_Output.Items.Add("Quick Sort Output");
Print(array);

timer.Start();
int[] arr3 = bbs.Bubble_Sort(array);
timer.Stop();
lbl_BubbleTime.Text = timer.Elapsed.TotalMilliseconds.ToString();
lb_Output.Items.Add("Bubble Sort Output");
Print(arr3);
Project Report for Performance Analysis of Sorting Algorithms

timer.Start();
rs.radixsort(array, array.Length);
timer.Stop();
lbl_RadixTime.Text = timer.Elapsed.TotalMilliseconds.ToString();
lb_Output.Items.Add("Radix Sort Output");
Print(array);

timer.Start();
hs.heapSort(array, array.Length);
timer.Stop();
lbl_HeapTime.Text = timer.Elapsed.TotalMilliseconds.ToString();
lb_Output.Items.Add("Heap Sort Output");
Print(array);

timer.Start();
ss.Shell_Sort(array);
timer.Stop();
lbl_ShellTime.Text = timer.Elapsed.TotalMilliseconds.ToString();
lb_Output.Items.Add("Shell Sort Output");
Print(array);

timer.Start();
bs.bucketSort(array);
timer.Stop();
lbl_BucketTime.Text = timer.Elapsed.TotalMilliseconds.ToString();
lb_Output.Items.Add("Bucket Sort Output");
Print(array);

timer.Start();
cs.Comb_Sort(array);
timer.Stop();
lbl_CombTime.Text = timer.Elapsed.TotalMilliseconds.ToString();
lb_Output.Items.Add("Comb Sort Output");
Print(array);

mychart.Series["Time"].Points.AddXY("Insertion Sort", lbl_InsertionTime.Text);


mychart.Series["Time"].Points.AddXY("Selection Sort", lbl_SelectionTime.Text);
mychart.Series["Time"].Points.AddXY("Merge Sort", lbl_MergeTime.Text);
mychart.Series["Time"].Points.AddXY("Quick Sort", lbl_QuickTime.Text);
mychart.Series["Time"].Points.AddXY("Bubble Sort", lbl_BubbleTime.Text);
mychart.Series["Time"].Points.AddXY("Heap Sort", lbl_HeapTime.Text);
mychart.Series["Time"].Points.AddXY("Shell Sort", lbl_ShellTime.Text);
mychart.Series["Time"].Points.AddXY("Radix Sort", lbl_RadixTime.Text);
mychart.Series["Time"].Points.AddXY("Bucket Sort", lbl_BucketTime.Text);
mychart.Series["Time"].Points.AddXY("Comb Sort", lbl_CombTime.Text);
}
public void Print(int[] arr)
{
for (int i = 0; i < arr.Length; i++)
{
lb_Output.Items.Add(arr[i]);
Project Report for Performance Analysis of Sorting Algorithms

}
}

private void btn_Clear_Click(object sender, EventArgs e)


{
panel1.Enabled = false;
panel2.Enabled = true;
txt_Name.Text = "";
lb_Input.Items.Clear();
lb_Output.Items.Clear();
lbl_InsertionTime.Text = "";
lbl_SelectionTime.Text = "";
lbl_MergeTime.Text = "";
lbl_QuickTime.Text = "";
lbl_BubbleTime.Text = "";
lbl_HeapTime.Text = "";
lbl_RadixTime.Text = "";
lbl_ShellTime.Text = "";
lbl_BucketTime.Text = "";
lbl_CombTime.Text = "";
}

}
Project Report for Performance Analysis of Sorting Algorithms

7. GUI

Appendix A– Development

8. Operating System

Microsoft Windows 8

9. Programming Language(s)

C#

Appendix B – Software
Project Report for Performance Analysis of Sorting Algorithms

Visual Studio

Das könnte Ihnen auch gefallen