00 - Course Intro
00 - Course Intro
[T]he difference between a bad programmer and a good one is whether [s]he
considers his[/her] code or his[/her] data structures more important. Bad
programmers worry about the code. Good programmers worry about data
structures and their relationships.
-Linus Torvalds, creator of the Linux kernel, in a message to the Git mailing list
● As the Torvalds quote above suggests, the way data is stored and organized
within a running program is one of the most important elements of that program
and will largely determine how good the user’s experience of the program is.
Well-structured data leads to programs that are efficient (i.e. consume fewer
resources) and are easier to understand and maintain.
● To understand the impact of data storage and organization, think for a few
minutes about the following problem. Try to come up with a good solution to the
problem, and importantly, try also to characterize the way your solution behaves
in terms of resource consumption (e.g. how much processing time is needed to
perform particular operations in your solution, and how much space is consumed
by the structures in your solution as more and more data is added to them?).
○ Imagine you’re a developer on a team implementing an exciting web
application. One of the most important features of your application is its
search functionality. Specifically, at the top of every page within the
application is a search box, where users can type a search query to find
content in your application related to that query.
○ Your team lead has asked you to add an autocomplete feature to this
search box. This feature will behave much like Google’s autocomplete
feature. Specifically, as the user types in the search box, the application
will present to them a set of suggested ways to complete the query they’re
typing, and instead of finishing typing out their whole query, the user can
just select one of the suggestions presented to them. If there are a lot of
possible suggested completions that match the query being typed, only
the top ones will be presented.
○ The data for this feature is already compiled and provided to you in an
alphabetically-sorted text file that contains one completion per line.
○ Now it’s up to you to figure out how you are going to store and use that
data in your running web application. How will you do it?
● Data structures, broadly, are general-purpose mechanisms for storing,
organizing, and managing data within a running program.
○ The term “data structure” also encapsulates the operations associated
with a particular structure, for example the way data is inserted, accessed,
and manipulated within the structure.
● Importantly, a given data structure represents not only the stored data itself, but
also often represents the relationships between specific data elements.
● None of the data structures we’ll see in this class (nor any that we won’t see in
class) is a perfect data structure for all situations. Each one involves trade-offs in
terms of the following things:
○ How long its operations take to run.
○ How much space it requires to store a collection of data of a given size.
○ How hard it is to implement.
● With the understanding you’ll gain in this class about data structures and how to
analyze them, you’ll be able to compare data structures and choose/design the
best one for a particular task.