DEV Community

Cover image for DSA Series Part 1: Arrays
Sarah Chowdhury
Sarah Chowdhury

Posted on

DSA Series Part 1: Arrays

Hey everyone, I’m Sarah. This post will begin my journey of learning in public. To recap where I’m at: I’ve completed CS50 and I’m doing my undergrad in Computer Science. I made a simple web app and wanted to make more complicated stuff, but I couldn’t because you need algorithms to solve the complicated stuff.

I’ll be following Abdul Bari’s course on Udemy and Algorithms Part I by Princeton on Coursera. The reason why I picked these courses is because I want to go over the concepts thoroughly. I also enjoy using low level programming languages.

Now onto arrays themselves. Arrays are data structures that store a lot of the same type of thing. So an array will store a lot of integers, it will store a lot of booleans but it will not store booleans and integers. When you make an array of a certain size you can’t change the size in a whim. You have to make a new array of the size you want and then copy the elements of the old array into it.

Python complicates things here: arrays are not built into python. In Python the alternative is using an external library or a list. However, you can increase the size of a list easily and you can, unlike what I’ve said before, store different types of things together. So it isn’t acting exactly like an array. I’ve searched online and they act more like a dynamic array or a doubly linked list.

The main reason you cant usually change the size of an array is because the elements are stored right next to each other. After allocating that space we cannot hope that memory is free around the stored array.

A diagram showing an array as a sequence of boxes, there's a question mark next to the array to imply that we don't know whats there

Now why would you want to store a lot of the same type of thing? Because you can organize a bunch of information and you can make simple simulations. I once used a 2D array to stimulate flowing water. It wasn’t quite the same as beautifully animated water but it got the job done. That’s about all I can think of for arrays. See you guys on the next one.

Top comments (0)