Data Structures For The Girlies PDF
Data Structures For The Girlies PDF
Introduction
Foreword
How to Use This Book
The Basics of Data Structures
1.1 What are Data Structures?
1.2 Types of Data Structures
1.3 How to Visualize Data Structures
Chapter 2: Arrays
2.1 What is an Array?
2.2 Understanding Array Indexing
2.3 Operations on Arrays
2.4 Arrays in Real Life
Chapter 3: Linked Lists
3.1 What is a Linked List?
3.2 Types of Linked Lists
3.3 Operations on Linked Lists
3.4 Linked Lists in Real Life
Chapter 4: Stacks and Queues
4.1 Understanding Stacks
4.2 Operations on Stacks
4.3 Understanding Queues
4.4 Operations on Queues
4.5 Stacks and Queues in Real Life
Chapter 5: Trees
5.1 What is a Tree?
5.2 Tree Terminologies
5.3 Types of Trees
5.4 Operations on Trees
5.5 Tree Traversals (Pre-, In-, and Post-Order)
5.6 Traversal Tricks
5.7 Trees in Real Life
Chapter 6: Graphs - The Wardrobe Web
6.1 What is a Graph?
6.2 Types of Graphs
6.3 Operations on Graphs
6.4 Graphs in Real Life
Chapter 7: Hashing
7.1 What is Hashing?
7.2 Understanding Hash Functions
7.3 Collision Handling
7.4 Understanding Hash Maps
7.5 Hashing in Real Life
Conclusion
Final Thoughts
Glossary
About the Author
Introduction
Foreword
Hello Girlies, it's me, @michellexcomputer , your fave Comp Sci girly.
Five years ago, I started studying Computer Science. I found it both
exciting and...well, simple. This was because I had amazing teachers who
taught the concepts in ways I could easily understand and digest.
Do you feel like learning data structures is like trying to decode a foreign
language? That's probably because sometimes the way these concepts are
explained is unnecessarily complex and confusing. This intimidates so
many of the girlies from even trying to learn. That makes me sad, because
learning Computer Science has been one of the most exciting and
exploratory journeys I’ve ever had.
That's when I decided to mix fashion and beauty with all this Computer
Science stuff on TikTok. I explained data structures like I would discuss the
ultimate closet organization or makeup routine. I wanted to make linked
lists feel like a basic lip combo tutorial that you just need two minutes to
understand.
And that's what this book is about - it's a guide to understanding data
structures as easily as you would pick the perfect outfit for the day. Okay,
picking the perfect outfit is hard… as easily as you would pick a great outfit
for the day.
So, get comfy, grab a cup of hot cocoa (or iced latte if that's more your
style), and let's unravel the world of Computer Science, one beauty analogy
at a time. Who said we couldn't conquer tech and look good doing it?
Welcome to "Data Structures for the Girlies". Let's get this party started!
Take it slow: Don't rush through the chapters. Each concept is explained
with an analogy to help you understand better. Take your time to understand
the analogy and how it relates to the concept. If a chapter gets you curious,
search up the topic on Youtube to go into a deeper dive, or email me at
mlawsy525@gmail.com and let’s have a random midnight convo about
Stacks! Way better than a girls’ night out.
Code: Each chapter comes with a set of operations that can be performed
on the data structure described. I have included Java code to show how
these operations can be performed in Java. Although the idea is similar, the
syntax is different in different languages, so note this is in Java, and you
would not use the same code in C or Python or any other programming
language.
Ask questions: If something is not clear, ask. You can reach out to me on
my social media platforms ( @michellexcomputer everywhere). I'll be more
than happy to help.
Have fun: This is not your typical computer science book. It's designed to
be fun and engaging. So, enjoy the process of learning.
Well, data structures are like your jewelry box. They're a way of organizing
and storing data so that they can be used efficiently. Just like how a well-
organized jewelry box can help you find your accessories quickly, a good
use of data structures can help a computer find and use data more efficiently.
Definition: A data structure is a storage space used to store and organize
data. It is a way of arranging data on a computer so that it can be accessed
and modified efficiently.
For example, let's say you're building a virtual makeup app. You might have
an object called "Lipstick" that holds data such as its color, brand, and finish.
The "Lipstick" object can also have functions like "apply" or "remove" that
simulate the actions you can perform with real lipstick. By using objects,
you can organize and represent data in a way that feels familiar and human-
like.
There are several types of data structures, just like there are different ways to
organize your makeup. You could sort your lipsticks by color, your
eyeshadows by brand, or your brushes by size. Similarly, data can be
organized in different ways depending on what you want to do with it.
Arrays: Think of these like your makeup palette. Just like how each color in
your palette has a specific spot, each data item in an array has a specific
location, or index. An array is a data structure consisting of a collection of
objects, each identified by an array index or key.
Linked Lists : These are like charm bracelets, where each charm (or object)
is linked to the next one. A linked list is a linear data structure where each
element is a separate object. Each element, or node, contains a reference to
the next node in the sequence.
Stacks and Queues: Stacks are like a stack of clothes you've picked out for
the week. You take the top item off the stack when you're getting dressed.
Queues, on the other hand, are like the line at the makeup counter. The first
person in line is the first one to get served.
A stack is a collection of objects with two main operations: push, which adds
an element to the collection, and pop, which removes the most recently
added element. A queue is a collection of objects that supports two
operations: enqueue, which adds an element to the end of the queue, and
dequeue, which removes an element from the beginning of the queue.
Trees: These are like family trees, but for data. There's one root item, and
each item can have one or more children. A tree is a data structure that
simulates a hierarchical tree structure, with a root value and subtrees of
children with a parent node.
Graphs : These are like social networks. Each object (or person) can be
connected to any other object. A graph data structure consists of a set of
vertices (or nodes) and a set of edges. Each edge connects a pair of vertices.
Hashing: This is like a magic wardrobe organizer that can instantly find any
item you're looking for. Hashing is a technique that is used to uniquely
identify a specific object from a group of similar objects.
For example, you can imagine an array as a row of lipstick tubes, where each
tube has a number. A linked list could be a set of charms on a bracelet, each
linked to the next. A tree could be a fashion hierarchy, with haute couture at
the top and streetwear at the bottom (oops).
Remember, the goal is not to memorize all these details right away, but to
start getting comfortable with the concepts. Just like you didn't learn to
perfect your winged eyeliner in one day, you won't become a data structures
expert overnight. But with practice and application of the concepts in
programming, you'll get there!
So, buckle up, girlies! We're about to dive deeper into the fabulous world of
data structures. Let's get this party started!
Chapter 2: Arrays
2.1 What is an Array?
Definition: An array is a simple data structure consisting of a collection of
elements (values or variables), each identified by at least one array index or
key.
Picture your favorite makeup palette. It's a sleek case filled with an array of
colors, each in its own little compartment. You can pick any color you want,
whenever you want, right? Well, in the world of programming, an array is
kind of like your makeup palette.
An array is a collection of items, all of the same type, and each with a unique
index, just like each color in your palette has a specific spot. The items could
be anything - numbers, strings, other arrays, or even objects. The key idea is
that each item has a specific location, or index, which you can use to access
it directly, just like you can pick any color from your palette without having
to go through all the others.
Now, let's talk about array indexing. You know how in some makeup
palettes, each color has a number or a name? Array indexing works
similarly. Each item in an array has a unique index, starting from 0. So, the
first item is at index 0, the second item is at index 1, and so on.
This is what we mean when we say arrays have "direct access". Just like you
can pick any color from your palette directly without having to go through
all the others, you can access any item in an array directly using its index.
Now, let's talk about a special value that you might encounter when working
with data structures - the NULL value.
Access an item: This is like picking a color from your palette. You use the
index to directly access any item.
Update an item: This is like mixing colors in your palette. You can change
the value of an item using its index.
Loop through an array: This is like swatching all the colors in your palette.
You can go through each item in the array, from the first to the last.
Find an item: This is like looking for a specific color in your palette. You
can search for an item by its value.
Note: There are many ways to search for an item in an array. Different ways
of searching can be more or less efficient depending on the data and the data
structure. You can learn more about this in an Algorithms course or in our
book “Algorithms for the Girlies”.
Social media feeds: Each post in your feed can be thought of as an item in an
array. The newest post is at index 0, and older posts have higher indexes.
So, there you have it, girlies! Arrays are like the makeup palettes of data
structures - organized, direct, and super useful. So, the next time you're
picking a color from your palette, remember - you're using an array!
Chapter 3: Linked Lists
3.1 What is a Linked List?
Definition: A linked list is a linear data structure where each element is a
separate object. Each element, or node, contains a reference to the next node
in the sequence.
Imagine your bestie gives you a new charm bracelet. Each charm is linked to
the next, creating a chain that's easy to add to or remove from. In the world
of programming, a linked list is a lot like your charm bracelet.
A linked list is a collection of items, called nodes, each pointing to the next.
Just like each charm on your bracelet is linked to the next, each node in a
linked list contains a reference to the next node. Unlike an array, items in a
linked list are not accessed by their position or index. Instead, you start at the
first item (or head) and follow the links to the item you want.
The items in a linked list are called "nodes" because they're like individual
stops on a path. Each node holds some information and points to the next
node in the list, just like charms on a bracelet that are connected to each
other. By using the term "nodes," we can imagine each item as a separate
piece that is linked together, forming a chain-like structure. This helps us
understand how the linked list works and how we can follow the connections
between nodes to access the desired information.
Singly linked list: This is like a charm bracelet that's linked in one direction.
Each node has a reference to the next node, but not the previous one.
Doubly linked list: In a doubly linked list, each node has a reference to both
the next node and the previous one.
Circular linked list: This is like a charm bracelet that's linked in a circle. The
last node in the list points back to the first node, allowing for continuous,
bidirectional traversal of the list.
3.3 Operations on Linked Lists
Just like you can add or remove charms from your bracelet, there are several
operations you can perform on linked lists:
Insertion: This is like adding a new charm to your bracelet. You can add a
new node to the list, either at the beginning, at the end, or after a specific
node.
Deletion: This is like removing a charm from your bracelet. You can remove
a node from the list, either the first one, the last one, or a specific one.
Traversal: This is like admiring each charm on your bracelet one by one.
You can go through each node in the list, from the first to the last.
Search: This is like looking for a specific charm on your bracelet. You can
search for a node in the list by its value.
Music player: When you're playing music on shuffle, the player could use a
linked list to keep track of which songs have been played and what comes
next.
Web browsing: Your web browser uses a linked list to implement the back
and forward buttons. Each web page you visit is added to the list, and you
can move forward and backward through the list to navigate your browsing
history.
Image viewer: When you're viewing photos in a slideshow, the application
could use a linked list to move from one photo to the next.
So, there you have it, girlies! Linked lists are like the charm bracelets of data
structures - flexible, dynamic, and super useful. So, the next time you're
adding a charm to your bracelet, remember - you're using a linked list!
Chapter 4: Stacks and Queues
4.1 Understanding Stacks
Definition: A stack is a linear data structure that stores items in a Last-
In/First-Out (LIFO) or First-In/Last-Out (FILO) manner.
Imagine a stack of clothes you've picked out for the week. Each day, you
take the top item off the stack to wear. In the world of programming, a stack
is a lot like your stack of clothes.
A stack is a collection of items, with two main operations: push, which adds
an item to the top of the stack, and pop, which removes the item at the top.
Just like you can add or remove clothes from your stack, you can add or
remove items from a stack in programming.
4.2 Operations on Stacks
Just like you can add or remove clothes from your stack, there are several
operations you can perform on stacks:
Push: This is like adding a new piece of clothing to your stack. You can add
a new item to the top of the stack.
Pop: This is like removing the top piece of clothing from your stack. You
can remove the item at the top of the stack.
Peek: This is like checking the top piece of clothing in your stack without
removing it. You can check the item at the top of the stack without removing
it.
Now, imagine the queue at the Hermes store. The first person in line is the
first one to get served. In programming, a queue is a lot like the queue at the
store.
A queue is a collection of items, with two main operations: enqueue, which
adds an item to the end of the queue, and dequeue, which removes an item
from the front.
Dequeue: This is like the person at the front of the queue leaving the store.
You can remove the item at the front of the queue.
Peek: This is like checking the person at the front of the queue without
serving them. You can check the item at the front of the queue without
removing it.
Stacks:
- Back button in web browsers: Web browsers track the URLs that you have
visited in a stack. Each time you visit a new page, it is pushed onto the stack.
When you press the back button, the URL at the top of the stack is popped
off.
Queues:
- Printers: Printers use queues to manage print jobs. When you send a
document to the printer while it's already printing, the document is placed in
the queue.
- Call centers: Call centers use queues to manage calls. When all operators
are busy, incoming calls are placed in a queue until an operator is available.
So, there you have it, girlies! Stacks and queues are like the stacks of clothes
and queues at the store - organized, efficient, and super useful. So, the next
time you're picking an outfit from your stack or waiting in a queue,
remember - you're using a stack or a queue!
Chapter 5: Trees
5.1 What is a Tree?
Definition: A tree is a hierarchical data structure that stores elements or
nodes connected by edges. The topmost node is called the root, and every
node (excluding the root) is connected by a parent node.
Picture this: you're getting ready for a big event, and you're considering
different hairstyles. You can imagine a tree structure where the root node
represents the main hairstyle category, like "Updos," "Braids," "Ponytails,"
or "Curls." Each branch then represents variations within that category, such
as "French Braid," "Fishtail Braid," "Messy Bun," "Sleek Ponytail," "Beach
Waves," and so on.
In programming, a tree is a lot like your hairstyle options. It's a hierarchical
structure with a topmost node, called the root, and several levels of
additional nodes, each connected by a "parent" node.
- Binary Tree: A tree where each node has at most two children, which are
referred to as the left child and the right child.
- Binary Search Tree (BST): A tree that keeps its values in sorted order, so
that lookup and other operations can use the principle of binary search.
- Heap: A special tree-based data structure that satisfies the heap property.
- B-Tree and B+ Tree: These are tree data structures that keep data sorted
and allow for efficient insertion, deletion, and search operations.
- Insertion: This is like adding a new hairstyle option to your list. You can
add a new node to the tree.
The following Java code operates on a binary search tree which is one of the
most commonly used types of trees.
- Deletion: This is like removing a hairstyle option from your list. You can
remove a node from the tree.
- Traversal: This is like going through all your hairstyle options one by one.
You can visit each node in the tree.
- Searching: This is like looking for a specific hairstyle option in your list.
You can search for a node in the tree.
5.5 Tree Traversals (Pre-, In-, and Post-Order)
Tree traversals are a way of visiting each node in the tree once. There are
three common types of depth-first traversals: preorder, inorder, and
postorder. The names of these traversals indicate the order in which the root
of a subtree is visited relative to its children.
Preorder Traversal (Root, Left, Right): In a preorder traversal, you visit the
root node first, then the left subtree, and finally the right subtree.
Inorder Traversal (Left, Root, Right): In an inorder traversal, you visit the
left subtree first, then the root node, and finally the right subtree.
Postorder Traversal (Left, Right, Root): In a postorder traversal, you visit the
left subtree first, then the right subtree, and finally the root node.
5.6 Traversal Tricks
Here's a fun trick to remember the order of tree traversals. Imagine a vertical
line starting from the root and going around the nodes in a counter-clockwise
direction. Place three pointers for each node: one to the left of the node, one
at the bottom, and one to the right.
- For preorder traversal, note the nodes in the order that the line passes the
left pointers (Root, Left, Right).
- For inorder traversal, note the nodes in the order that the line passes the
bottom pointers (Left, Root, Right).
- For postorder traversal, note the nodes in the order that the line passes the
right pointers (Left, Right, Root).
This trick should help you remember the order of tree traversals and make it
easier to perform them on paper. Happy traversing, girlies!
- File System: The file system on your computer is a good example of a tree
structure. The folder is a node and the files inside the folder are its children.
Sub-folders are also nodes, with files and other sub-folders as their children.
- Website Navigation: Websites use tree structures for navigation. The home
page is the root, and each link is a child node. When you click on a link,
you're taken to a new node with its own set of child nodes (links).
- Organizational Structure: Many organizations structure their teams in a
tree-like hierarchy, with the CEO at the root, managers as the children, and
so on.
So, there you have it, girlies! Trees are like the hairstyle options of data
structures - organized, hierarchical, and super versatile. So, the next time
you're picking a hairstyle for the day, remember - you're using a tree!
Chapter 6: Graphs – The Wardrobe Web
6.1 What is a Graph?
Definition: A graph is a non-linear data structure that consists of nodes (or
vertices) and edges. Each edge connects two nodes and can be used to
represent the relationship between them.
- Undirected Graphs: These are like a group of friends hanging out. There's
no specific direction to the relationships - if A is friends with B, then B is
friends with A.
- Weighted Graphs: These are like shipping routes. Each route (edge) has a
cost (weight) associated with it, like the shipping cost.
- Unweighted Graphs: These are like undirected graphs, but without any
costs associated with the edges.
- Cyclic Graphs: These are like a circular fashion trend. You can start at one
node and follow the edges to eventually come back to the starting node.
- Acyclic Graphs: These are like a one-way fashion trend. Once you leave a
node, you can't come back to it.
- The Internet: Each web page is a node, and each link is an edge.
- Roads: Each intersection is a node, and each road is an edge.
So, there you have it, girlies! Graphs are like the wardrobe web of data
structures - complex, interconnected, and super useful. So, the next time
you're picking an outfit from your wardrobe, remember - you're using a
graph!
Chapter 7: Hashing
7.1 What is Hashing?
Hashing is a technique used in programming for quickly retrieving specific
data from a large dataset. The key idea behind hashing is to use a function
(the hash function) to convert a key (like the name of an item) into an index
of an array or a table (the hash table). This index is then used to find the
desired data quickly.
Think of it like a magical wardrobe organizer. You tell it what item you're
looking for, and it instantly finds it for you. No need to rummage through
piles of clothes or search through drawers. That's what hashing is like in the
world of programming.
In more technical terms, hashing is a process that transforms a big amount of
data (like a long string) into a small integer that represents the original data.
This small integer, called a hash, can then be used to find the original data in
a hash table.
In programming, a hash function takes a key and returns an index where the
item can be found. The key could be anything - a number, a string, or even
an object. The important thing is that the hash function always returns the
same index for the same key.
A good hash function has the following properties:
- It is deterministic, meaning that the same input will always produce the
same output.
- It is fast to compute the hash value for any given input.
- It uniformly distributes the data across the array or table to minimize
collisions (more on this later).
- It should result in a low rate of collision (situations where different keys
produce the same hash).
Another way is open addressing, where if a spot is already taken, the hash
table looks for another spot. This can be done in several ways, such as linear
probing (looking for the next open spot in the table), quadratic probing
(looking for an open spot a certain distance away), or double hashing (using
a second hash function to find an open spot).
Let's extend our magical wardrobe organizer analogy a bit further. Imagine if
your organizer could not only find your clothes but also remember specific
details about them. You tell it you want your pink sweater, and it not only
finds the sweater but also tells you that it's made of cashmere and needs to
be dry-cleaned. That's what a hash map does in programming.
A hash map is a data structure that stores key-value pairs. It uses a hash
function to compute an index into an array of buckets or slots, from which
the desired value can be found.
In the context of our wardrobe organizer, the key would be the name of the
item (like "pink sweater"), and the value would be the details about the item
(like "cashmere, dry-clean only").
Hash maps are like the ultimate version of our magical wardrobe organizer -
not only can they find our items quickly, but they can also remember
important details about them.
- Databases: Hashing is used to quickly find data. Each piece of data has a
unique key, and the hash function gives the location of the data in the
database.
- Password verification: When you enter your password, it's hashed and
compared to the stored hash of your password. This way, the system doesn't
need to store your actual password for verification.
So, there you have it, girlies! Hashing is like the magic wardrobe organizer
of data structures - fast, efficient, and super useful. So, the next time you're
looking for an item in your wardrobe or doing any programming, remember
- using a hash would make everything so much quicker!
Conclusion
Final Thoughts
Dear Girlies,
We've come to the end of our introduction to the world of data structures,
and what a journey it's been! We've navigated through arrays, linked lists,
stacks, queues, trees, graphs, and hashing, all while keeping our style game
strong.
Remember, the world of computer science is not a foreign land. It's a place
where we can express our creativity, solve problems, and make our mark.
And just like in fashion, there are no limits to what we can create when we
understand the basics.
Don't worry if you don't grasp everything at once. Just like mastering the
perfect winged eyeliner or finding your signature style, it takes time and
practice. Keep exploring, keep learning, and keep coding.
Remember, you're not just a girl in the world of tech. You're a trailblazer, a
problem solver, a creator. You're a girl who can code, and that's a
superpower.
So, keep that chin up, put on your favorite lipstick, and conquer the world
of tech. You've got this, girlie!
Digital Besos,
@michellexcomputer
Glossary
**Glossary**
2. **Binary Search Tree (BST)**: A tree that keeps its values in sorted
order, so that lookup and other operations can use the principle of binary
search.
3. **Binary Tree**: A tree where each node has at most two children,
which are referred to as the left child and the right child.
4. **B-Tree and B+ Tree**: Tree data structures that keep data sorted and
allow for efficient insertion, deletion, and search operations.
6. **Circular Linked List**: A linked list where the last node in the list
points back to the first node, allowing for continuous, bidirectional traversal
of the list.
8. **Doubly Linked List**: A linked list where each node has a reference
to both the next node and the previous one.
13. **Heap**: A special tree-based data structure that satisfies the heap
property.
15. **Node**: An entity that holds information on its data and functions it
can perform.
21. **Singly Linked List**: A linked list where each node has a reference
to the next node, but not the previous one.
25. **Weighted Graphs**: Graphs where each route (edge) has a cost
(weight) associated with it, like the shipping cost.
About the Author
Hello, Girlies! I'm your favorite Computer Science girly and the author of
this book. But before we dive into that, let's take a step back. As a college
freshman, I found myself immersed in the world of computer science, with a
particular fascination for the finance industry. I was eager to use technology
to develop innovative solutions that could transform the financial sector, and
I was ready to make a meaningful impact.
But let's be honest, the world of computer science can sometimes feel like
trying to decode a foreign language. That's when I realized that the beauty of
computer science is not in its complexity, but in its simplicity. It's about
breaking down complex problems into manageable parts, just like creating
the perfect makeup look or planning an outfit for a big event.
But above all, I believe in the power of continuous learning. I'm a self-
motivated individual, always ready to take on new challenges and expand
my skill set. This book is a product of that belief in continuous learning. It's
a journey through the world of data structures, with a twist of fashion and
beauty.