Selection Quick
Selection Quick
Faculty of Engineering
Prepared By:
Areej Ameen
Asmaa Al-anati
Esraa Alswaeer
Layan Mouallah
Supervised By:
ENG. Ibtehal Mishal
1.Abstract: • The extent up to which the given input
One of the basic problems of Computer sequence is Already sorted.
Science is sorting a List of items. It refers • The probable constraints on the given
to the arrangement of numerical or input values
Alphabetical or character data in • The system architecture on which the
statistical order. Bubble, Insertion, sorting Operation will be performed.
Selection, Merge, and Quick sort are most • The type of storage devices to be used:
common Ones and they all have different main Memory or disks [2].
performances based on the Size of the list One of the sorting methods is selection
to be sorted, with complexity of O (n^2) sort an in place comparison –based
for bubble and insertion sort and O
algorithm that is divided in to two parts,
(n*logn) for merge, heap & quick sort, As
the size of a list increases, Some of the the sorted part which is empty in the first
sorting algorithm turns to perform better and the unsorted one, searching the
than Others. As The size of dataset unsorted for the minimum /greater value
increases, there is always the chance of swap it with the leftmost /rightmost value
Duplication or some form of redundancies in the unsorted then moving it to the
occurring in the List. Sorting is considered sorted, repeatedly doing the same to the
as a fundamental operation in Computer remaining values in the unsorted part
Science as it is used as an intermediate until all values are sorted.in enhanced
step in many programs. For example, the selection (ESSA),the concept is to
binary search algorithm (one of the fastest
memorize the last maximum value
search algorithms) requires that data
position and starting the search from
must be sorted before the search could be
done accurately at all Times. Data is there to avoid wasting time in repeated
generally sorted to facilitate the process search.
of Searching, As a result of its vital or key
role in computing, several techniques for In the other hand ,quick sort method is a
sorting have been proposed. The Bubble, divide and conquer method ;breaks the
insertion, selection, merge and problem to sub problems finding solution
quick, the formal definition of the sorting to each then combine it using recursive
problem is as follows: calls , the concept of quick sort is to
divide the list into two parts greater and
Input: A sequence having n numbers in
some random order less than a value usually the most right
(a1, a2, a3, an) one called pivot ,using two pointers
Output: A permutation (a‟1, a‟2, moving in opposite direction, left to right
a‟3, a‟n) of the input Sequence such that pointer move until it point to less than
A‟1 ≤ a‟2 ≤ a‟3 ≤ ….. a‟n. [1] pivot value while right to left pointer
move until it points to greater than pivot
value ,then the two pointer swap values
this continue until two pointers cross
1. Introduction: directions then pivot is swapped with the
Sorting method of a list elements is closer pointer value ,after this break the
linked to efficient data management list in pivot point to two list each of them
and usage, with the arise of data size symbolize sub-problem and apply the
and the need of repeated access, it is previous steps until list is sorted.
important to use faster less complex
sorting method, according to Jadoon et
al. (2011) choosing sorting method In this study our main purpose is to spot
depends on various factor such as : how two different complexity level
• The size of the list (number of sorting algorithm works, as comparing
elements to be sorted). the simplest method (selection sort)
which average complexity is O(n2)with algorithm and n represents the size of the
a highly quick efficient one (quick input data values.
sort) which has an average complexity
of O(n log n) . In this Notation, the O
represents the complexity of the
59 41 31 41 26 58
ARRAY
In the (SSA) partition the list into two main logical parts, the sorted part and the unsorted part.
Any iteration picks a value form the unsorted and places it in the sorted list, making the sort
partition grow in size while the unsorted partition shrinks for each iteration, The process is
terminated when the number of items or the size of the unsorted is one (1). The procedure to select
a value to be moved to the sorted list will return minimum value or maximum value in the
unsorted partition, which will be swapped to position the item correctly.
There are many types of improved selection sorting algorithms and all works better than the
Selection Sort Algorithm:
1.” Initialize i to 1
2. Repeat steps 3-5 until the i equals n.
3. Search from the beginning of the unsorted part of the list to the end.
4. Enqueue the locations of all values that are the same as the Maximum value.
5. Use the indices on the queue to perform swapping.
List – A[n]
Queue – Q[n] “[3]
EX: A[0] A[1] A[2] A[3] A[4] A[5] A[6] A[7] A[8]
A[n] 1 2 3 1 2 4 5 2 1
Q[n]
PASS 1
A[n] 1 2 3 1 2 4 5 2 1
Q[n] A[3] A[8]
PASS 2
A[n] 1 1 1 2 2 4 5 2 3
Q[n] A[7]
PASS 3
A[n] 1 1 1 2 2 2 5 4 3
Q[n] A[8]
PASS 4
A[n] 1 1 1 2 2 2 3 4 5
The list is sorted at the end of the fourth iteration or pass. The existing selection sort
will take more time to sort the same list.
The run time of the ISSA depends on the number of distinct values that are found in the list to be
sorted. If the number of distinct values is big or equal to n, then the run time of the algorithm can be
approximated as O(n2). However, if the number is very small, the algorithm completes the sorting in
the order of O(n).
The code of ISSA and Comlplicty:
n T = n2 O(n2)
Worst and best Case of Run time:
0%
The number of iterations in 10%
the group was determined in 20%
1000 values terms of percentages and 11 30%
40%
different sets of values
50%
%60
%70
%80
%90
%100
The result:
Quick Sort: The Quick Sort algorithm works on the principle of (Divide and Conquer). The
idea of this principle is summarized in dividing the problem to be solved into several smaller
problems in size
(we mean big and small here the number of elements that are addressed) and similar to the big
problem in principle (small problems are usually independent of each other), and after solving
each small problem on sharpness. Comes the stage of assembling the solved parts, so that
together they are a solution to the complete problem.
After explaining how Divide and Conquer works, let's explain how the Quick Sort
algorithm works:
First:
Pivot Selection: Selecting an element
from the array. This chosen element is
called the Pivot. Usually, this element
is in the middle, at the beginning, or at
the end of the array.
Second:
Partitioning: After the first step, the
second step of arranging the elements
of the array begins, so that all the
elements that are smaller than the
selected pivot are arranged before it
and the largest is placed after it.
The principle of Quick Sort:
The worst case of quick sort: In the worst case, the pivot element position may
be either First or last. In that case the elements are always divided in 1: (n-1)
proportions. The recurrence relation for such a proportional division would be:
So, the Best case running time of quick sort is O(n log2 n ) “[4]
4. Conclusion
Selection sort in its modified method may perform better than even the quick
sort,but that depends heavily on limiting distinct values to a very small number
as the strength of the algorithm appears where there is more redundancies and
repetition ,in this case modified selection sort may have complexity of O(n) which
is ideal for relatively large data ,compared to quick sort algorithm which has a
complexity of O(n*logn)in best case which is approached by choosing pivot as a
median to decrease time of comparison iteration .
5. Summary