### Introduction

The basic idea of a **data structure** is to store data in a way that meets the needs of your particular application. You might be inclined to store a particular kind of data in one giant array, but it would be rather time consuming to locate a specific value if you had a significant number and depth of items. So you need to look to other options.

Depending on the application, there are a batch of other basic data structures available to help you out. The differences between them typically have to do with trade-offs between how long it takes to first populate the structure, how long it takes to add or find elements, and how large the structure is in memory.

We’ll save the specifics of data structures for more computer-science-oriented courses, but this introduction should again expand your toolbox slightly so you can identify and solve certain problems where plain old Arrays, Hashes and Sets don’t quite cut it. New structures and strategies will be particularly relevant, for instance, when you’re trying to search through a large batch of data for a particular value or plan out a strategy several moves in advance.

You’ve already had a brief introduction to **algorithms** over some of the other lessons and you even got to write your own Merge Sort algorithm in the last project. You’ll find that sorting algorithms are quite common. Another major area for algorithms is in search, where milliseconds count. When you’re searching through enormous troves of data, the quality of your search algorithm is incredibly important. Traversing a data tree looking for a particular element is a related problem that’s common in data intensive applications.

Luckily for you, these complex algorithmic problems have all been solved many times in the past. Understanding *how* they are solved will give you some great tools to apply to other (similar) problems on your own. Algorithms are really just ways of solving problems systematically. In this brief introduction, we’ll focus on a couple of algorithms that you may run into when coding on your own – breadth-first-search and depth-first-search.

### Lesson overview

This section contains a general overview of topics that you will learn in this lesson.

- What is a data structure?
- What are stacks and queues?
- What’s the best way to implement stacks and queues in JavaScript?
- Why bother having many different search algorithms?
- What are breadth-first-search (BFS) and depth-first-search (DFS)?
- What situations would you want to use BFS?
- What situations would you want to use DFS instead?

### Assignment

- Glance over the Wikipedia entry on Data Structures for a high level overview of things.
- Learn about basic algorithms from Coursera’s Algorithms course. The first 10 minutes are really the meat of the introduction to algorithms, the rest gets more mathematical (if you’re so inclined).
- Read What is an Algorithm and How Does it Make You a Better Programmer for another basic look at what algorithms are.
- Learn about how binary search works from Harvard’s CS50 on YouTube.
- Now, we’re going to focus on learning about binary search trees. Start by watching this video to learn how a binary search tree is constructed from an unordered array.
- Next, learn about the principles of queues and stacks, which are concepts used in breadth-first search and depth-first search respectively.
- Finally, learn about breadth-first search and depth-first search of binary search trees from this series of videos on YouTube:

### Knowledge check

The following questions are an opportunity to reflect on key topics in this lesson. If you can’t answer a question, click on it to review the material, but keep in mind you are not expected to memorize or master this knowledge.

- What is the difference between a stack and a queue?
- What are the enqueue and dequeue properties?
- What is a linked list? What is a node?
- Which recursive problem-solving method/algorithm design principle does binary search implement?
- What abstract data type would you use to defer/store nodes in a breadth-first tree traversal?
- What abstract data type would you use to defer/store nodes in a depth-first tree traversal?

### Additional resources

This section contains helpful links to related content. It isn’t required, so consider it supplemental.