Skip to main content Accessibility help
×
Hostname: page-component-586b7cd67f-gb8f7 Total loading time: 0 Render date: 2024-11-26T04:09:59.981Z Has data issue: false hasContentIssue false

Appendix: Algorithm and Pseudocode Conventions

Published online by Cambridge University Press:  30 April 2024

Deepak Khemani
Affiliation:
IIT Madras, Chennai
Get access

Summary

The algorithms presented in this book assume eager evaluation. The values of primitive types (integers, reals, strings) are passed by value, and tuples, lists, arrays, sets, stacks, queues, etc., are passed by reference, similar to how Java treats primitive values and objects.

The data structures (container types) like sets, arrays, stacks and queues, and the operations on those structures carry their usual meaning, and their usages in the algorithms are self explanatory.

Tuple

A tuple is an ordered collection of fixed number of elements, where each element may be of a different type. A tuple is represented as a comma separated sequence of elements, surrounded by parenthesis.

tuple → ( ELEMENT 1 , ELEMENT 2 , … , ELEMENT k)

A tuple of two elements is called a pair, for example, (S, null), ((A, S), 1), (S, [A, B]) are pairs. And a tuple of three elements is called a triple, for example, (S, null, 0), (A, S, 1), (S, A, B) are triples. A tuple of k elements is called a k-tuple, for example, (S, MAX, −∞, ∞), (A, MIN, LIVE, ∞, 42).

Note: parenthesis is also used to indicate precedence, like in (3+1) * 4 or in (1 : (4 : [ ])), its usage will be clear from the context.

List

A list is an ordered collection of an arbitrary number of elements of the same type. A list is read from left to right and new elements are added at the left end. Lists are constructed recursively like in Haskell.

list → ELEMENT : list

list → [ ]

The ‘:’ operator is a list constructor; it takes an element (HEAD) and a list (TAIL) and constructs a new list (HEAD : TAIL) similar to cons(HEAD, TAIL) in LISP. Using head:tail notation, a list such as [3, 1, 4] is recursively constructed from (3 : (1 : (4 : [ ]))), similar to cons(3, cons(1, cons(4, nil))) in LISP. The empty list [ ] has no head or tail.

Type
Chapter
Information
Publisher: Cambridge University Press
Print publication year: 2024

Access options

Get access to the full version of this content by using one of the access options below. (Log in options will check for institutional or personal access. Content may require purchase if you do not have access.)

Save book to Kindle

To save this book to your Kindle, first ensure [email protected] is added to your Approved Personal Document E-mail List under your Personal Document Settings on the Manage Your Content and Devices page of your Amazon account. Then enter the ‘name’ part of your Kindle email address below. Find out more about saving to your Kindle.

Note you can select to save to either the @free.kindle.com or @kindle.com variations. ‘@free.kindle.com’ emails are free but can only be saved to your device when it is connected to wi-fi. ‘@kindle.com’ emails can be delivered even when you are not connected to wi-fi, but note that service fees apply.

Find out more about the Kindle Personal Document Service.

Available formats
×

Save book to Dropbox

To save content items to your account, please confirm that you agree to abide by our usage policies. If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your account. Find out more about saving content to Dropbox.

Available formats
×

Save book to Google Drive

To save content items to your account, please confirm that you agree to abide by our usage policies. If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your account. Find out more about saving content to Google Drive.

Available formats
×