0% found this document useful (0 votes)
4 views2 pages

AI Exp 3

This document outlines an assignment focused on implementing the greedy search algorithm for selection sort. It details the objective, prerequisites, and the theory behind selection sort, including its algorithm and time complexity analysis. The assignment also includes questions for further understanding and concludes with the goal of sorting an unsorted list of numbers.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

AI Exp 3

This document outlines an assignment focused on implementing the greedy search algorithm for selection sort. It details the objective, prerequisites, and the theory behind selection sort, including its algorithm and time complexity analysis. The assignment also includes questions for further understanding and concludes with the goal of sorting an unsorted list of numbers.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Group A

Assignment No: 03
Title: Implement Greedy search algorithm for Selection Sort.

Prerequisite: Basic knowledge of Greedy algorithm and sorting concept.


Objective:
In this experiment, we will be able to do the following:
● Study how selection sort works under greedy search algorithm.

Outcome: Successfully able to sort, unsorted list of numbers.

Software and Hardware Requirement:


Open Source C++ Programming tool like G++/GCC, python, java and Ubuntu.
Theory:
In Selection Sort, we take the simplest, most intuitive approach to sort an array.
Choose the smallest number, place it in the first position. Then choose the next
smallest number out of the remaining elements, and place it in the second position and
so on till the end.
Selection Sort Algorithm

We will perform N-1 iterations on the array (N is the number of elements in the
array). In iteration i (1≤i≤N-1):
● We will traverse the array from the ith index to the end and find the smallest
number among these elements. Note that if there are two smallest elements of
the same value, we choose the one with the lower index.
● We will swap this smallest element with the i element.
● Hence at the end of the ith iteration, we have found the ith smallest number,
and placed it at the ith position in the array.
In the (N-1)th iteration, we will place the (N-1)th smallest element, which is the 2nd largest
element in the array, at the second last position. This will leave us with one element which
would already be at its correct place. This completes our sorting! Selection Sort Algorithm.
Running Time of Selection Sort

Let's assume that we are sorting N elements of a given array using Selection Sort.
To complete one iteration, we traverse a part of the array (from index i to the end) exactly once
(while keeping track of the smallest element encountered so far). Since the longest length we
ever traverse in any given iteration is N (in the first iteration when i=1 -> from first to last
element), time complexity of completing one iteration is O(N).

In Selection Sort, we run N iterations, each of which takes O(N) time. Hence overall time
complexity becomes O(N*N).

Questions:

1. What is the time and space complexity of selection sort?


2. If an array is [5,1,7,15] , sort the list by selection sort, step wise.
3. What is a Stable Sort Algorithm? Whether selection sort is a stable algorithm?

Conclusion:
In This way we have studied how to sort, unsorted list of numbers using selection sort.

You might also like