array vs linked
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Why Data Structures Matter Before we delve into each one, here’s the “why” behind the question. When we code, we are always dealing with data: lists of users, products, hospital records, patient details, transactions, etc. But how that data is organized, stored, and accessed determines everything: sRead more
Why Data Structures Matter
Before we delve into each one, here’s the “why” behind the question.
When we code, we are always dealing with data: lists of users, products, hospital records, patient details, transactions, etc. But how that data is organized, stored, and accessed determines everything: speed, memory usage, scalability, and even user experience.
Data structures give us the right “shape” for different kinds of problems.
1. Array The Organized Bookshelf
For example, if you have:
You can pick up a book immediately if you know the slot number.
Pros:
Cons
Example: Storing a fixed list, such as hospital IDs, or months of a year.
In human words:
Lusiads Pros:
Cons
Real-world example: A playlist where each song refers to the next — you can insert and delete songs at any time, but to access the 10th song, you need to skip through the first 9.
3. Stack The Pile of Plates
In human terms:
Imagine a stack of plates-you add one on top, push, and take one when you need it from the top, which is pop.
Key Operations:
Pros:
Cons:
Real-world example:
4. Queue The Waiting Line
In human terms:
Operations important to:
Pros:
Cons:
Real-world example:
5. Tree Family Hierarchy
In human terms,
Pros:
Cons:
Real-world example:
6. Graph The Social Network
In human words:
Think of Facebook, for example every user is a node, and each friendship corresponds to an edge linking two of them.
Graphs can be:
Directed (A → B, one-way)
Undirected (A ↔ B, mutual)
Weighted (connections have “costs,” like distances on a map)
Pros:
Cons
Real-world example:
Human Takeaway
Each of these data structures solves a different kind of problem:
In real life, a good developer doesn’t memorize them — they choose wisely based on need:
“Do I need fast lookup?” → Array or HashMap.
“Do I need flexible growth?” → Linked list.
“Do I need order?” → Stack or Queue.
“Do I need structure or relationships?” → Tree or Graph.
That’s the mindset interviewers are testing: not just definitions, but whether you understand when and why to use each one.
See less