Chapter 3. Algorithms and Data Structures: The Secret of a Great Performance
Data structures describe the shape of data. Algorithms describe what you do with that data. Store things one way, and an algorithm may be lightning fast. Store them another way, and an algorithm may crawl. So how do you choose a data structure? Well, first you have to have a good working knowledge of data structures and their runtime characteristics. In this chapter, we’ll meet some of the most basic data structures—arrays, dynamic arrays, and linked lists—and see how they perform. We’ll also see how they serve as a foundation for the more advanced data structures that are explored later in the book.
Let’s talk about data structures
The way you organize data doesn’t just affect speed; it can enable or rule out entire solutions. Take a coffee shop, for example, where the barista writes each customer’s name on a cup, and then makes drinks in the order the cups are placed on the counter. That simple structure makes “first-in, first-out” possible: the first cup down is the first cup delivered to the customer. But imagine if the cups were stacked instead: every new order goes on top of the stack, and the last cup placed is the first one the barista can grab. Suddenly the rule has changed, not because ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access