2

While writing array index in an algorithm $a[i]\gets v$ is conventionally used. Is the notation $a_{i}\gets v$ also used ?

If the algorithm uses struct or equivalent, some notation is required for property access. In some occasions $p(s)$ is used where $p$ is the property. Using $s \rightarrow p$ messes up with the assignment arrow. Using $s_{p}$ looks like $p$ is an index and $p\in \mathbb{Z}^{+}$. Should $s["p"]$ be used ? What is the convention to denote property access in algorithm ?

Is there any reference where I can check different notations of these two scenarios ?

Neel Basu
  • 141
  • 7

1 Answers1

3

Not everyone follows the same conventions, but I'll describe the ones I see most commonly. Your experience may vary.

  • If $a$ is an array, $a[i]$ is typically used, but not $a_i$.

  • If $(a_1,\dots,a_n)$ is a sequence, $a_i$ is typically used, but not $a[i]$. Usually sequences are not updateable.

  • If $a$ is a string, you might see either $a[i]$ or $a_i$; both are common, in my experience.

  • I have most commonly seen $s.p$ used for property access. Sometimes I have seen people use $p(s)$ used.

Different sources may follow different conventions. There is no one right answer. A good approach is to find a textbook that you like (e.g., CLRS), and then follow the same conventions they use. Odds are that they have put some thought into choosing consistent and understandable conventions, so they probably have chosen something reasonable.

D.W.
  • 167,959
  • 22
  • 232
  • 500