Sorting Algorithms Assignment 2022
Added on 2022-10-17
17 Pages1992 Words18 Views
|
|
|
Running head: SORTING ALGORITHMS 1
Assignment
Student
Course
Instructor
Date
Assignment
Student
Course
Instructor
Date
![Sorting Algorithms Assignment 2022_1](/_next/image/?url=https%3A%2F%2Fdesklib.com%2Fmedia%2Fimages%2Fwj%2Fab9e4d7881ea4214a4a4c4c48440d933.jpg&w=3840&q=10)
SORTING ALGORITHMS 2
Contents
Introduction....................................................................................................................................3
Part 1...............................................................................................................................................3
Selection Sort...............................................................................................................................3
Part 2...............................................................................................................................................7
Merge Sort...................................................................................................................................7
Part 3.............................................................................................................................................14
De-queues, Queues, and Priority Queues..................................................................................14
Conclusion....................................................................................................................................17
Contents
Introduction....................................................................................................................................3
Part 1...............................................................................................................................................3
Selection Sort...............................................................................................................................3
Part 2...............................................................................................................................................7
Merge Sort...................................................................................................................................7
Part 3.............................................................................................................................................14
De-queues, Queues, and Priority Queues..................................................................................14
Conclusion....................................................................................................................................17
![Sorting Algorithms Assignment 2022_2](/_next/image/?url=https%3A%2F%2Fdesklib.com%2Fmedia%2Fimages%2Fgx%2F94b95739ab7842cfa3321bd5b46bcc06.jpg&w=3840&q=10)
SORTING ALGORITHMS 3
Introduction
Sorting is basically an arrangement of data in ascending or descending order. Sorting
helps in finding the required items quickly. In real life there are many which we required to
search for particular items such as roll numbers in a given list. It arranges data in a proper
sequence, hence sorting algorithms were introduced.
Part 1
Selection Sort
Selection sort in an algorithm used for sorting with a sort of in-place comparison. In
selection sort algorithm the array is sorted by repeating the finding of minimum element from the
array which is not sorted (Shin & Miyazaki, 2016). And the beginning element is kept at the
beginning of the array. The following code to be implemented:
System.out.print("Enter the Elements to be sorted: ");
for(m=0; m<size; m++)
{
arr[m] = sc.nextInt();
}
for(m=0; m<size; m++)
{
for(n=m+1; n<size; n++)
{
if(arr[m] > arr[n])
{
Introduction
Sorting is basically an arrangement of data in ascending or descending order. Sorting
helps in finding the required items quickly. In real life there are many which we required to
search for particular items such as roll numbers in a given list. It arranges data in a proper
sequence, hence sorting algorithms were introduced.
Part 1
Selection Sort
Selection sort in an algorithm used for sorting with a sort of in-place comparison. In
selection sort algorithm the array is sorted by repeating the finding of minimum element from the
array which is not sorted (Shin & Miyazaki, 2016). And the beginning element is kept at the
beginning of the array. The following code to be implemented:
System.out.print("Enter the Elements to be sorted: ");
for(m=0; m<size; m++)
{
arr[m] = sc.nextInt();
}
for(m=0; m<size; m++)
{
for(n=m+1; n<size; n++)
{
if(arr[m] > arr[n])
{
![Sorting Algorithms Assignment 2022_3](/_next/image/?url=https%3A%2F%2Fdesklib.com%2Fmedia%2Fimages%2Ffd%2F63969261d7874f24b9385a34ceeea693.jpg&w=3840&q=10)
SORTING ALGORITHMS 4
temp = arr[m];
arr[m] = arr[n];
arr[n] = temp;
}
}
}
System.out.print("The sorted array is:\n");
for(m=0; m<size; m++)
{
System.out.print(arr[m]+ " ");
}
temp = arr[m];
arr[m] = arr[n];
arr[n] = temp;
}
}
}
System.out.print("The sorted array is:\n");
for(m=0; m<size; m++)
{
System.out.print(arr[m]+ " ");
}
![Sorting Algorithms Assignment 2022_4](/_next/image/?url=https%3A%2F%2Fdesklib.com%2Fmedia%2Fimages%2Ffs%2F6241fa6f4ff04854af21eac96c9447eb.jpg&w=3840&q=10)
End of preview
Want to access all the pages? Upload your documents or become a member.
Related Documents