Data structures and algorithms are important, but it is not always easy to grasp their main ideas. This “I’m Preparing for FAANG “series will help you not just learn data structures and algorithms but also dive into their philosophy. The final purpose of this series is to help you achieve your goal: To pass FAANG interviews.
This is the first and most foundational lesson from the series. In this tutorial, you’ll understand what exactly a data structure is and how we interact with it.
Getting started with Data structures
Data structure is simply a way of structuring data. What does it mean? It means they are essentially how data is stored, retrieved, and organized.
Data is always important. In software development, we usually work with different data structures, and using different algorithms, we interact with this data. Whether it is a small application like a utility tool, a huge web application that serves billions of people, or a machine learning model, the manipulation and management of data is a crucial process of our system.
The purpose of interacting with data defines its structure. You may need the fastest way of getting data, or you don’t care about retrieving it, but your focus is on storing the data/ writing the data.
When you first learn data structures, you may come up with a foundational question: Why do we have so many data structures out there?
Well, the choice of a data structure depends heavily on how the data will be used. So, The actual reason is your business/requirements. Consider the following cases:
- If you need the fastest way of retrieving data, you can pick tables or arrays
- If your main focus is storing the data, linked lists or compressed tries may be a relevant choice for you
- If you need to maintain the order, data structures like binary search trees or sorted arrays are often used.
- If your data grows unpredictably, you may pick dynamic arrays or linked lists. As you might guess, the requirement for the data structure is the main case here. That is why we have a lot of data structures, and that is why you should deal with so many data structures throughout your learning and working process.
Getting started with Algorithms
Data structures alone are not sufficient. What is the purpose of picking up the most suitable data structure if you don’t have a way of interacting with it? Well. That is why we need algorithms to interact with this data effectively.
We encapsulate the following logic inside our algorithms:
- How quickly can new data be inserted into the structure? For example, inserting data into an array is faster than inserting it into a sorted linked list.
- Can we remove elements efficiently?
- How about sorting and searching? Algorithms like binary search, merge sort, and quicksort are important when it comes to large datasets.
- How fast can we access the element? Searching for an element in a table is faster than a sequential search through an array. Random Access memory We mostly structure data inside a RAM. RAM stands for Random Access Memory. The performance of our application heavily depends on how well the data structure is utilized by RAM. There is no single way of interacting with RAM when it comes to data structure and RAM communication. Almost every data structure interacts with RAM in a unique way that affects performance, memory usage, and system efficiency.
We temporarily store data and instructions inside RAM for quick access to the CPU.
Data structures stored in RAM are accessed faster compared to other storage like hard drives, etc. So, RAM’s speed and organization directly affect how effectively data structures perform operations like read, search, delete, etc.
As you already know, RAM is measured in bytes (e.g. 16 GB RAM or 32 GB RAM), which represents the total amount of data it can hold at once.
All data in RAM, whether text, numbers, or instructions, is stored in binary format. For example, the symbol “A” ( in ASCII) is stored as 01000001 (1 byte). Each byte in RAM is associated with a unique memory address. In the end, the CPU uses these addresses to locate and interact with the data stored there.
In our next tutorial, we will talk about arrays, but let’s focus on storing the name ‘Tural’ in RAM. When it comes to storing the ASCII symbols, we all know that every ASCII symbol is 1 byte. Almost in all programming languages, when you specify a string, it acts like an array of chars, so they are the contiguous block of information. In RAM, the system will represent it sequentially. Every symbol of the string is one byte, so the next address in RAM will be increased to 1.
But byte is not the smallest representation of data. Originally, RAM stored a combination of 0 and 1, which we call binary representation.
After getting the binary representation, let’s see how it will be displayed in RAM.
Oh, yes, I forgot to mention, that preparing for FAANG doesn’t start from the exact questions, it starts from the foundations. When you move forward, you will understand that the fundamentals are the most important ones. Well, let’s wrap up what we have learned so far:
A bit is the smallest unit of data, and a byte is a combination of 8 bits. RAM is a temporary data storage where we store our arrays, linked lists, hash tables, and other data structures. Efficient use of RAM is crucial for optimized data handling.
Don’t worry. We will learn all these data structures in more detail.
Data, such as the name “Tural” is represented in memory as binary sequences. In ASCII, every symbol is 1 byte, so the name “Tural” will be 5 bytes. In total, we have 8*5=40 bits for this name.
Understanding binary representation in most cases helps to optimize our software design, whether working with low-level memory or preparing for interviews with FAANG companies.
See you in our next lessons. If you like my content, you can follow me on Linkedin too.
Want to dive deeper?
Regularly, I share my senior-level expertise on my TuralSuleymaniTech YouTube channels, breaking down complex topics like .NET, Microservices, Apache Kafka, Javascript, Software Design, Node.js, and more into easy-to-understand explanations. Join us!
Top comments (0)