Apr 302018One of the most important and overlooked parts of designing algorithms is choosing the right data types.
We often assume that the types of data an algorithm will use are determined by the inputs and the output — but it might help to use a temporary collection of some data, if that collection has useful operations.
Those operations are determined by the collection’s type.
In this post we’ll look at a couple of examples where using the right data types makes the problem simpler.
Feb 122018Before attempting these exercises, you should read the posts about abstract data types, arrays and stacks and queues.
Feb 122018Before attempting these exercises, you should read the posts about abstract data types, arrays and stacks and queues.
Feb 122018A list can do everything an array can do, and more; the array data type is strictly “less useful” than the list data type.
However, the array data structure is both faster and uses less memory than any list data structure.(1)
This is common: if a data type supports fewer operations, then programmers who use that type have less freedom, but programmers who implement it (or choose an implementation) have more freedom.
A data structure supporting fewer operations can often be more efficient in speed, memory use, or both; or, if you want more operations supported, expect a lower efficiency.
Feb 122018A type defines not just the possible values that some data can take, but also the operations which can be performed on that data.
For example, the int
type represents integers, and supports arithmetic operations, bitwise operations and comparison operations.