Findout The Function In The Pseudo Code

Pro contributor
26Jan2010,16:53   #1
pankaj.sea's Avatar
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?
Go4Expert Founder
26Jan2010,17:00   #2
shabbir's Avatar
Approved.
Skilled contributor
26Jan2010,18:58   #3
techgeek.in's Avatar
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"
Skilled contributor
26Jan2010,19:06   #4
techgeek.in's Avatar
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...
Pro contributor
27Jan2010,10:04   #5
pankaj.sea's Avatar
yes! u r right!