0% found this document useful (0 votes)
15 views5 pages

SE Sem IV AoA Lab Experiment 1 202425

The document outlines an experiment to implement the Selection Sort algorithm, detailing its aim, theory, and complexity analysis. Selection Sort is an in-place comparison sort known for its simplicity and efficiency in memory-limited situations. The document includes an example of sorting an array, the recurrence relation for its time complexity, and concludes with a mention of code and output.

Uploaded by

Jagruti Chavan
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)
15 views5 pages

SE Sem IV AoA Lab Experiment 1 202425

The document outlines an experiment to implement the Selection Sort algorithm, detailing its aim, theory, and complexity analysis. Selection Sort is an in-place comparison sort known for its simplicity and efficiency in memory-limited situations. The document includes an example of sorting an array, the recurrence relation for its time complexity, and concludes with a mention of code and output.

Uploaded by

Jagruti Chavan
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/ 5

Experiment No.

1
To implement Selection Sort
Date of Performance: 20/01/2025
Date of Submission:

Experiment No. 1

Title: To implement selection sort.


Aim: To study, implement and Analyze Selection Sort Algorithm
Objective: To introduce the methods of designing and analyzing algorithms

Theory: Selection sort is a sorting algorithm, specifically an in-place comparison sort.


Selection sort is noted for its simplicity, and it has performance advantages over more
complicated algorithms in certain situations, particularly where auxiliary memory is
limited.

The algorithm divides the input list into two parts: the sub list of items already sorted,
which is built up from left to right at the front (left) of the list, and the sub list of items
remaining to be sorted that occupy the rest of the list. Initially, the sorted sub list is empty
and the unsorted sub list is the entire input list. The algorithm proceeds by finding the
smallest (or largest, depending on sorting order) element in the unsorted sub list,
exchanging it with the leftmost unsorted element (putting it in sorted order), and moving
the sub-list boundaries one element to the right.

Example:
Sort the given array using selection sort. arr[] = 64 25 12 22 11

11 25 12 22 64 Find the minimum element in arr[0...4] and place it at


beginning
11 12 25 22 64 Find the minimum element in arr[1...4] and place it at
beginning of arr[1...4]
11 12 22 25 64 Find the minimum element in arr[2...4] and place it at
beginning of arr[2...4]
11 12 22 25 64 Find the minimum element in arr[3...4] and place it at
beginning of arr[3...4]

Algorithm and Complexity:

Sem IV, Analysis of Algorithm Lab (CSL401) Department Of Computer Engineering


The recurrence relation for selection sort is:
T(n) = 1 for n=0
= T(n – 1) + n for n>0 ---- 1
From above equation,
T (n – 1) = T(n – 2) + (n – 1)
Use above in equation 1
T(n) = T(n – 2) + (n – 1) + n----2
Let T(n – 2) = T(n – 3) + n – 2
Use above in equation 2
T(n) = T(n – 3) + (n – 2) + (n – 1) + n
After k iterations,
T(n) = T(n – k) + (n – k + 1) + (n – k + 2) + ..… + (n – 1) + n
When k approaches to n,
T(n) = T(0) + 1 + 2 + 3 + … + (n –1) + n
T(0) = 0,
T(n) = 1 + 2 + 3 + … + n
= n(n + 1) / 2
= (n2 /2) + (n/2)
T(n) = O(max( (n2 /2) + (n/2) ))
= O(n2 / 2)
= O(n2)
T(n) = O(n2)

Sem IV, Analysis of Algorithm Lab (CSL401) Department Of Computer Engineering


Code:

Output:

Sem IV, Analysis of Algorithm Lab (CSL401) Department Of Computer Engineering


Conclusion:

Sem IV, Analysis of Algorithm Lab (CSL401) Department Of Computer Engineering

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy