CHAPTER 4Arrays
Arrays are extremely common data structures. They are intuitive, easy to use, and supported well by most programming languages. In fact, arrays are so common and well understood that you may wonder whether there's much to say about them in an algorithms book. Most applications use arrays in a relatively straightforward manner, but special-purpose arrays can be useful in certain cases, so they deserve some attention here.
This chapter explains algorithmic techniques that you can use to make arrays with nonzero lower bounds, save memory, and manipulate arrays more quickly than you can normally.
Basic Concepts
An array is a chunk of contiguous memory that a program can access by using indices—one index per dimension in the array. You can think of an array as an arrangement of boxes where a program can store values.
Figure 4.1 illustrates one-, two-, and three-dimensional arrays. A program can define higher-dimensional arrays, but trying to represent them graphically is hard.
Get Essential Algorithms, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.