Findout The Function In The Pseudo Code

pankaj.sea's Avatar, Join Date: Apr 2009
Pro contributor
Follow The Following Pseudo Code :
Procedure 1:
MIN(A, K, N, LOC)
An Array A is in memory. This procedure finds the location LOC of the smallest element among A[K], A[K+1],...,A[N]
Quote:
1. Set MIN :=A[K] AND LOC := K. [Initializes pointers.]
2. Repeat for J=K+1, K+2,...,N:
If MIN>A[J], then: Set MIN :=A[J] and LOC :=A[J] and LOC := J. [End of Loop]
3. Return
Procedure 2:
FUNCTION (A,N)
Quote:
1. Repeat Steps 2 and 3 for K=1,2,...,N-1:
2. Call MIN(A,K,N,LOC).
3. [Intrechange A[K] and A[LOC].]
Set TEMP := A[K], A[K]:=A[LOC] and A[LOC]:=TEMP.
[End of step 1 loop]
4. Exit.
What is the function of procedure 2?
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Approved.
techgeek.in's Avatar, Join Date: Dec 2009
Skilled contributor
Quote:
Originally Posted by pankaj.sea View Post
Follow The Following Pseudo Code :
Procedure 1:
MIN(A, K, N, LOC)
An Array A is in memory. This procedure finds the location LOC of the smallest element among A[K], A[K+1],...,A[N]


Procedure 2:
FUNCTION (A,N)


What is the function of procedure 2?

No doubt it is a pseudo code of "selection sort"
techgeek.in's Avatar, Join Date: Dec 2009
Skilled contributor
In selection sort min element is obtained in a list and placed at an appropriate position. After that except the min element the remaining list is employed in finding next minimum element...This process continues until the list is ordered..
Nice question pankaj..otherwise last few questions were matter of timing..Today i m late but i hope i gave right ans...
pankaj.sea's Avatar, Join Date: Apr 2009
Pro contributor
yes! u r right!