DEV Community

Cover image for Developer Dictionary: Data Structures
Bhumi
Bhumi

Posted on • Updated on • Originally published at connectthedots.dev

Developer Dictionary: Data Structures

This post is part of a resource called Developer Dictionary. More about why I'm writing this here

When you go to the grocery store, do you make a list of things you need to buy? If it's a physical list on a piece of paper, likely you use that during the trip, mentally check off the items and then recycle the paper once you're done. The list serves as temporary storage of items from our working memory. A data structure serves a similar purpose for a program.

Imagine you're writing a program to keep track of books you've read. You'll eventually need to make a list. Maybe you'll want to go through the list and rate each book. For this you would store the book titles in the computer's working memory for the duration of your program (temporary storage).

Each value stored in a computer's memory has an address so that the operating system can find it later. It has a name as well – a variable name given by our program – so that our program can refer to its value. It looks something like this:

Alt Text

So 0x0001 is the address for the operating system. Within our program, instead of 0x0001 we can use book_one as the name. But typing book_one, book_two feels a bit clunky right. And if we can imagine that we're using a continuous block of addresses, could we just use one variable name but have a way to refer to the entire book list? Yes, that is called an array in most programming languages. If we created an array named books, we could refer to each book with book[1], book[2], book[10], etc. That's all there is to it. An array is one type of data structure. Data structures are a shorthand for referring to memory addresses on the computer.

In addition to being a convenient shorthand, most data structures also support useful operations for adding items, finding an item, removing an item, and going through the entire collection of items Keep reading

Top comments (0)