Skip to content

Latest commit

 

History

History
40 lines (26 loc) · 3.75 KB

File metadata and controls

40 lines (26 loc) · 3.75 KB

What Are Data Structures?

Now that we've done some challenges and looked at time complexity and Big O notation, I want to start to look at data structures. Data structures are used in every programming language. All a data structure is is a way of storing and organizing data so that it can be used effectively. They're not only used for storing data but they're also used for accessing and manipulating data. If we have a list of 1000 items, and we want to find a specific item in that list, we can use a data structure to store the data in a way that makes it easy to find the item we're looking for.

Built-In Data Structures

Every language has data structures built in. JavaScript has arrays and objects as well as maps and sets. Python has lists, tuples, dictionaries, and sets. Java has arrays, lists, maps, and sets. And so on. This is a JavaScript course, so I'm looking at data structures from a JavaScript perspective, but the concepts are the same no matter what language you're using.

More Targeted Data Structures

In addition to the built-in data structures, we have more targeted structures that work in a specific way. When look at an array in JavaScript, it can be used in many different ways using all types of methods and properties. A linked list, on the other hand, is a very specific data structure that has a very specific way of working. It's not as flexible as an array, but it's more efficient in certain situations. When creating a linked list or a stack or a queue, we can use a JavaScript array as the base and then only expose specific methods and properties that make sense for that data structure. This is what we'll be doing in this course.

You probably haven't seen a linked list used in everyday code very often. You've seen arrays and objects as they're built in and very flexible. Linked lists can be used in certain situations where they're more efficient than arrays. Also, data structures are a huge topic when it comes to technical interviews. You'll be asked to implement a linked list or a stack or a queue in an interview. You'll also be asked to use a specific data structure to solve a problem. So, it's important to know how they work and when to use them.

Data Structures and Algorithms

Data structures and algorithms go hand in hand. An algorithm is a set of instructions for solving a problem. You can look at the challenges that we've so far as algorithms. A data structure is a way of storing and organizing data so that it can be used effectively. We've used arrays, objects and maps in the challenges that we've done so far. What I want to start to do now is create our own custom classes that implement specific data structures. We'll start with some built in data structures like maps and sets as well as a custom hash table. Then we'll move to stacks, queues, linked lists and some of the more difficult to grasp like trees, and graphs. We can then use these data structures to solve problems.

Common Data Structures

These are some of the most common data structures that you'll see in programming. We'll be looking at each of these in this course.

  • Arrays
  • Objects
  • Maps
  • Sets
  • Stacks
  • Queues
  • Linked Lists
  • Trees
  • Binary Trees
  • Binary Search Trees (BST)
  • Graphs
  • Hash Tables

Linear vs Non-Linear Data Structures

Data structures can be linear or non-linear. A linear data structure is a structure where data is organized sequentially, where each element is attached to its previous and next adjacent element. Some examples are arrays, stacks, queues and linked lists. A non-linear data structure is a structure where data is not organized sequentially. Some examples are trees and graphs. We'll be looking at both linear and non-linear data structures in this course.

In the next lesson, we'll look at hash tables including maps and sets.