logo

Sorting Algorithms Assignment 2022

   

Added on  2022-10-17

17 Pages1992 Words18 Views
 | 
 | 
 | 
Running head: SORTING ALGORITHMS 1
Assignment
Student
Course
Instructor
Date
Sorting  Algorithms  Assignment  2022_1

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
Sorting  Algorithms  Assignment  2022_2

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])
{
Sorting  Algorithms  Assignment  2022_3

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]+ " ");
}
Sorting  Algorithms  Assignment  2022_4

End of preview

Want to access all the pages? Upload your documents or become a member.

Related Documents