GiBiT
GiBiT

Reputation: 321

Writing an Algorithm in Pseudocode

I am having a hard time with writing pseudocode.

Question: Consider an array A[1..n], where n>= 3. Write an algorithm (using pseudocode) that computes the minimum value among all the elements with index a multiple of 3 (e.g. A[3], A[6], A[9], …so on).

for i=1 to A.length
    while n>= 3
       A[n] = A[n*i]

I took an attempt at writing the code. Can somebody provide some insight on what I have written.

Upvotes: 1

Views: 5315

Answers (1)

yakiro
yakiro

Reputation: 763

It should look like this

min = A[3]    
for i=3 to A.length
    if min > A[i]
       min = A[i]
    i += 3

Upvotes: 1

Related Questions