0% found this document useful (0 votes)
46 views6 pages

Selection Sort

Selection sort is an algorithm that sorts an array by repeatedly finding the minimum element and placing it at the beginning. It maintains two subarrays: a sorted subarray and an unsorted subarray. It compares adjacent elements and swaps them if out of order until the entire array is sorted. With N elements, it requires N-1 comparisons to find the minimum element each time, resulting in overall O(N2) time complexity. Selection sort is simple but not efficient for large arrays.

Uploaded by

Haider
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views6 pages

Selection Sort

Selection sort is an algorithm that sorts an array by repeatedly finding the minimum element and placing it at the beginning. It maintains two subarrays: a sorted subarray and an unsorted subarray. It compares adjacent elements and swaps them if out of order until the entire array is sorted. With N elements, it requires N-1 comparisons to find the minimum element each time, resulting in overall O(N2) time complexity. Selection sort is simple but not efficient for large arrays.

Uploaded by

Haider
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Selection Sort

Introduction
The selection sort algorithm sorts an array by repeatedly finding the minimum element (considering
ascending order) from unsorted part and putting it at the beginning. To sort in descending order, find
the maximum element from unsorted part and putting it at the last. The algorithm maintains two
subarrays in a given array.

1) The subarray which is already sorted.

2) Remaining subarray which is unsorted.

Considering ascending order, if the first element is greater than second then, you need to swap the
elements but, if the first element is smaller than second, leave the elements as it is. Then, again first
element and third element are compared and swapped if necessary. This process goes on until first and
last element of an array is compared.
To find the minimum element from the array of N elements, N-1 comparisons are required. After putting
the minimum element in its proper position, the size of an unsorted array reduces to N-1 and then N-2
comparisons are required to find the minimum in the unsorted array. Therefore, (N-1)+(N-
2)+…+1=(N.(N-1))/2 comparisons and N swaps result in the overall time complexity of O(N2).

Selection sort algorithm is easy to use but, there are other sorting algorithm which perform better than
selection sort. Specially, selection sort shouldn't be used to sort large number of elements if the
performance matters in that program.

This figure below clearly explains the working of selection sort algorithm.

Diagram

Pseudocode

Best Case

Worst Case

Applications
1. Selection sort works best when the range of values is known. if the data is random or reversed
scanning the entire data set to find the each sequential value can be time consuming so this is
only practical if the data is nearly ordered already or the data set is very small.
2. A program that renders graphical objects that are layered on top of each other might have to
sort the object according to an “above” bottom to top.
A* search algorithm
Introduction
The aim of path planning algorithms is to find a path from the source to goal position. The discrete path
planning task which is posed as graph search problem. A* is a widely used graph traversal algorithm that
uses Best First Search approach to find least cost path from the source to destination node. It evaluates
nodes by combining g(n) and h(n).

f(n) = g(n) + h(n)

g(n) = path cost from the start node to goal node

h(n) = the estimated cost of the cheapest path from start to the goal

f(n) = estimated cost of the cheapest solution through n

Such methods are called as informed search algorithms which consider cost of paths, heuristic distance
to decide path most likely to lead to a goal or some information about the problem at hand to choose
the most likely node that will lead to goal position. A* search is an example of informed search strategy.

The A* algorithm can considered to operate in 2 states

 Find the node associated with minimum cost


 Expand the node

By expanding the node we mean that all the connected components of the nodes are considered to be
potential candidates for best node in the next iteration of the algorithm.
Diagram

Pseudocode
Best Case
The time complexity of A* depends on quality of heuristic. In the best case, the path to the end is found
immediately, giving an overall running time in the efficiency class O(V).

Worst Case
However, in the worst case, every edge in the graph is searched before finding a path to the end; the
running time in this case would be O(|V|+|E|).

Applications
1. They are used in games. You can use this for each enemy to find a path to the goal. For example,
Tower defense is a type of strategy video game where the goal is to defend a player’s territories
or possessions by obstructing enemy attackers, usually achieved by placing defensive structures
on or along their path of attack.
2. Routing finding – computer networks, airline route planning
3. VLSI layout – cell layout and channel routing
4. Production planning – “just in time” optimization
5. Protein sequence alignment
6. Many other “NP-Hard” problems – A class of problems for which no exact polynomial time
algorithms exist – so heuristic search is the best we can hope for

References

https://www.slideshare.net/HumanoTerricola/analisys-of-selection-sort-and-bubble-sort

https://www.scribd.com/presentation/44315061/Sorting

https://www.scribd.com/document/8764058/Google-University-Sorting-Algorithm

https://betterexplained.com/articles/sorting-algorithms/

https://www.hackerearth.com/practice/algorithms/sorting/selection-sort/tutorial/

You might also like