www.theurbannerdbrand.com

TUN’s ELI5 CS Degree Series: Arrays

Shane Austrie
The Urban Nerd

--

Everything learned in a Computer Science degree explained in simple (Explain-Like-I’m-5) terms.

This is the first article of many in this series. In this article, we’ll talk about how primitive/simple arrays in programming languages work in memory.

Memory in a computer can be thought of as seats in a room.

The more memory you have, the bigger the room and the more seats we have in that room. We’ll briefly touch on RAM vs storage.

Credits: https://fredgonsowskigardenhome.com/2013/11/29/its-easy-to-arrange-furniture-in-a-square-living-room-some-ideas-that-will-inspire-you/

Random Access Memory (RAM) is a room that was designed specifically so people can enter , leave, and be found in in the quickest way possible.

Because of this design, it is harder to build large rooms while still being fast. When thinking about RAM, think about the “R” and the “A” in the acronym. You want to randomly get to any seat as fast possible. Similar to how a class room is small and arranged, in order for the teacher to be able to reach any student in a reasonable amount of time.

Storage (e.g. SSD, HDD, USB drive) is a type room that focuses primarily on how many seats that room can hold with speed being an afterthought.

Similar to a concert where audience stands to watch the presentation. That type of concert doesn’t technically have “seats,” but it has locations where fans can stand. Additionally, it takes a while to find a person, because the concert is large and there isn’t a specific methodology to go to specific location.

Your computer uses storage to store your operating system files and your personal information/data. However, your computer uses RAM when running applications, because those active applications affect the user’s experience at the current time.

Credits to Wikimedia

For example, when you use Spotify, all the information it needs to run is loaded into RAM, because you are directly interacting with the application and expect fast response time while using it (e.g. clicking a button causes an immediate action).

To go into more detail with our previous example (Spotify), the Spotify application isn’t just one person taking up one seat. The Spotify app is an entire organization, it has many people inside of it. Every time Spotify does something internally, it’s most likely creating a new, reorganizing an existing, or firing a previous person inside it’s organization. When a person is created, Spotify have to place that person in a seat. Then when Spotify wants to do something with that person, it has to find that person in RAM.

Sometimes Spotify wants people to be grouped together (e.g. Human Resources department). There are various ways of grouping people in memory. These various ways are called “Data Structures” in Computer Science. In the literal sense, we are structuring and organizing data/people in memory. One way, and also the simplest way, of grouping people is using an array.

An array can be thought of as either series of seats that are directly next to each other, or simply a couch.

When you create an array, a certain amount of seats are reserved so that only the person who own the entire array (the series of seats) can use those seats. We use arrays in programming languages, because we want a fast way to access and group objects/data (“people”). When the person you’re looking for is in the same row or column as you, in addition to arrays existing in RAM which make the process faster overall, look up time is dramatically shortened.

Spotify has five people that they want to group together, so they create an array of size five (a series of five seats). However, what if they want to add one more person to this group? Well they cant just take the next seat before or after their array. There might be a person in or have reserved that seat. So Spotify has to ask the room manager (the computer) to ask to reserve six completely new seats.

This process is called resizing the array.

The room manager then has to guide each person from their current seat to their new seat. Unfortunately, the room manager can only guide one person at a time, so this is very time extensive the bigger the group is. It’s also very likely that Spotify might add several new people to this group in the near future. Knowing this time-extensive fact, instead of reserving six seats, Spotify reserves ten seats. It’s convention to double your current number of seats: too little then you might end up resizing a lot, too much and you run out of seats for your organization and every other organization.

Thanks for reading! For more articles covering coding, music, dating, and the overall urban nerd lifestyle follow The Urban Nerd publication or follow me on Snapchat (https://snapchat.com/add/the-urbannerd) or Twitter (https://twitter.com/TheUrbanNerd). Preferably SC!

--

--

Shane Austrie
The Urban Nerd

Gen Z AdTech Expert | ML/AI Consultant | SiliconValleyConsulting.io | Casual writer about techy & non-techy things | Connect with me on LinkedIn!