I am not from cs background and I am trying to make sense of what is used for what. In pseudocode I see a lot of this:
for i <--- 1 to n-1 do
j <--- find-Min(A,i,n)
A[j] <-> A[i]
end for
What are <---
and <->
used to refer to?
<---
means "assign the right-hand side to the left-hand side" (it is somewhat strange to see this used in the for
case, as it might easily have been omitted there).
<->
means "swap". A[j] value is swapped with A[i].
EDIT:
It just occurred to me that the first line might be missing i
and should instead read:
for i <--- 1 to n-1 do
This becomes a legitimate use case of <---
described above: i
is assigned values from 1
to n-1
sequentially, and the loop body (down to end for
, which denotes the end of loop) is executed for each of these i
values.
There's nowhere close to universal agreement about the notation used in pseudocode.
In this case I'd guess that <---
means "assign the right side to the left side", and <->
means 'swap the right and left sides."
In the first case, however, I think you're missing a character. It's probably supposed to be:
for i <--- 1 to n-1 do
So it's a normal for
loop that would be written as:
for i = 1 to n-1
in BASIC, or:
for (i=1; i<n; i++)
in a C-like language.
is used to make it obvious that the variable receives a new value, e.g.
for i <- 1 to n-1 do
I have seen this in:
is also used to make the operation obvious in a symbolic way.
I can't think of anything but pseudo code right now.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With