Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
For
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.
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.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
4. System Features
Upload file
Perform analysis of sorting algorithms
Project Report for Performance Analysis of Sorting Algorithms
Only authenticated users can use the project and the system should be accessed by those users who
have input file.
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];
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;
if (gap < 1)
gap = 1;
int i = 0;
swaps = false;
++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;
}
class MergeSort
{
public int[] Merge_Sort(int[] arr)
{
//Base Case
if (arr.Length <= 1)
{
return arr;
}
{
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 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);
}
}
}
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
}
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;
}
}
public class ShellSort
{
public void Shell_Sort(int[] array)
{
int n = array.Length;
int gap = n / 2;
int temp;
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();
}
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);
}
}
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);
}
}
}
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