Go4Expert

Go4Expert (http://www.go4expert.com/)
-   $1 Daily Competition (http://www.go4expert.com/contests/daily-competition/)
-   -   Findout The Function In The Pseudo Code (http://www.go4expert.com/contests/findout-function-pseudo-code-t20768/)

pankaj.sea 26Jan2010 16:53

Findout The Function In The Pseudo Code
 
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?
:crazy: :crazy: :crazy:

shabbir 26Jan2010 17:00

Re: Findout The Function In The Pseudo Code
 
Approved.

techgeek.in 26Jan2010 18:58

Re: Findout The Function In The Pseudo Code
 
Quote:

Originally Posted by pankaj.sea (Post 63404)
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?
:crazy: :crazy: :crazy:


No doubt it is a pseudo code of "selection sort"

techgeek.in 26Jan2010 19:06

Re: Findout The Function In The Pseudo Code
 
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 27Jan2010 10:04

Re: Findout The Function In The Pseudo Code
 
yes! u r right!


All times are GMT +5.5. The time now is 10:52.