Abstract
The next several chapters will be describing the basic data structures that every programming language provides, their usage, and the most important algorithms relevant to them. And we’ll start with the notion of a data structure and tuples or structs that are the most primitive and essential ones.
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Notes
- 1.
Moreover, Python has special syntax for destructuring such tuples: dec, rem = truncate(3.14). However, this is not the optimal way to handle returning the primary and one or more secondary values from a function. Lisp provides a more elegant solution called multiple values: all the necessary values are returned via the values form (values dec rem) and can be retrieved with (multiple-value-bind (dec rem) (truncate 3.14) ...) or (rtl:with ((dec rem (truncate 3.14))) ...). It is more elegant because secondary values may be discarded at will by calling the function in a usual way: (+ 1 (truncate 3.14)) => 4. This is not possible in Python, because you can’t sum a tuple with something.
- 2.
Actually, the complexity here is O(n^2) due to the use of the function member that performs set membership test in O(n), but it’s not essential to the general idea. If uf-disjoint is expected to be called with tens or hundreds of points, the roots structure has to be changed to a hash-set that has a O(1) membership operation.
Author information
Authors and Affiliations
Rights and permissions
Copyright information
© 2021 Vsevolod Domkin
About this chapter
Cite this chapter
Domkin, V. (2021). Data Structures. In: Programming Algorithms in Lisp. Apress, Berkeley, CA. https://doi.org/10.1007/978-1-4842-6428-7_4
Download citation
DOI: https://doi.org/10.1007/978-1-4842-6428-7_4
Published:
Publisher Name: Apress, Berkeley, CA
Print ISBN: 978-1-4842-6427-0
Online ISBN: 978-1-4842-6428-7
eBook Packages: Professional and Applied ComputingApress Access BooksProfessional and Applied Computing (R0)