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 ?

  • 1
    $\begingroup$ Pseudocode is not a programming language. The exact notation doesn't matter as long as it's clear and concise. You might want to use dot notation for properties. $\endgroup$ Mar 8, 2018 at 16:31
  • $\begingroup$ Yes I am asking about conventions and references. Writing something too unconventional makes things hard to read. $\endgroup$
    – Neel Basu
    Mar 8, 2018 at 16:33
  • 2
    $\begingroup$ $a[i]$ and $a_i$ are commonly used. Dot notation is commonly used. C-style $s \rightarrow p$ is not, in my experience. $\endgroup$ Mar 8, 2018 at 16:33

1 Answer 1


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.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.