Chapter 1
Why Data Structures Matter

Anyone who has written even a few lines of computer code comes to realize that programming largely revolves around data. Computer programs are all about receiving, manipulating, and returning data. Whether it’s a simple program that calculates the sum of two numbers, or enterprise software that runs entire companies, software runs on data.

Data is a broad term that refers to all types of information, down to the most basic numbers and strings. In the simple but classic “Hello World!” program, the string "Hello World!" is a piece of data. In fact, even the most complex pieces of data usually break down into a bunch of numbers and strings.

Data structures refer to how data is organized. Let’s look at the following code:

 x = "Hello! "
 y = "How are you "
 z = "today?"
 
 print x + y + z

This very simple program deals with three pieces of data, outputting three strings to make one coherent message. If we were to describe how the data is organized in this program, we’d say that we have three independent strings, each pointed to by a single variable.

You’re going to learn in this book that the organization of data doesn’t just matter for organization’s sake, but can significantly impact how fast your code runs. Depending on how you choose to organize your data, your program may run faster or slower by orders of magnitude. And if you’re building a program that needs to deal with lots of data, or a web app used by thousands of people simultaneously, the data structures you select may affect whether or not your software runs at all, or simply conks out because it can’t handle the load.

When you have a solid grasp on the various data structures and each one’s performance implications on the program that you’re writing, you will have the keys to write fast and elegant code that will ensure that your software will run quickly and smoothly, and your expertise as a software engineer will be greatly enhanced.

In this chapter, we’re going to begin our analysis of two data structures: arrays and sets. While the two data structures seem almost identical, you’re going to learn the tools to analyze the performance implications of each choice.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset