Storage Basics - potatoscript/dsa GitHub Wiki
๐ง Why Do We Need to Store Data?
Imagine you wrote a story on paper, but then lost it the next day. ๐ข Thatโs what happens if a computer doesnโt store data.
So computers store:
- Your games ๐ฎ
- Photos ๐ธ
- Videos ๐ฅ
- Apps ๐ฑ
- Words you type ๐
They organize it so you can find it quickly โ like a super tidy robot assistant! ๐คโจ
๐งฑ The Building Blocks of Data
1๏ธโฃ Bits and Bytes
| Concept | Emoji | Description |
|---|---|---|
| Bit | ๐ข or โซ | Smallest piece of data. A 1 or a 0. |
| Byte | ๐ | Group of 8 bits. Stores one letter (like "A")! |
๐ง Example: The letter "A" is stored as 01000001 in binary. That's 1 byte!
๐๏ธ Memory Types
| Memory Type | Emoji | Use |
|---|---|---|
| RAM (Random Access Memory) | ๐ง | Short-term memory. Fast but forgets when power is off. |
| HDD/SSD (Hard Drive) | ๐พ | Long-term storage. Like your notebook. |
| Cache | ๐โโ๏ธ๐จ | Super fast! For storing important stuff temporarily. |
| ROM (Read-Only Memory) | ๐ | Fixed memory. Stores instructions for booting up. |
๐ How Data is Organized
Computers donโt just throw your files in a giant pile. They use special data structures to keep things neat.
๐ File System
Like folders on your desk ๐:
๐ MyComputer
โฃ ๐ Documents
โ โ ๐ homework.docx
โฃ ๐ Pictures
โ โ ๐ธ vacation.jpg
โ ๐ Music
โ ๐ต song.mp3
Each folder = a place to keep related files organized.
๐ Arrays โ Fixed Rows of Stuff
Imagine lockers in a row ๐งฐ:
[๐][๐งธ][๐ช][๐]
0 1 2 3
Arrays store data in a straight line. You can quickly grab data by its number (called index).
๐ Linked Lists โ Holding Hands ๐ค
Each item points to the next, like a conga line of people!
[๐] โ [๐จ] โ [๐ฎ] โ [๐งฉ] โ null
Easier to add/remove items in the middle.
๐ฅ Stacks โ Last In, First Out (LIFO)
Just like a pancake stack ๐ฅ:
Top โ [๐ฅ]
[๐ฅ]
[๐ฅ]
Take from the top first!
๐ถ Queues โ First In, First Out (FIFO)
Like a line at school lunch ๐:
Front โ [๐][๐][๐][๐] โ Back
First person in = First person out!
๐บ๏ธ Hash Tables โ Quick Lookups
Imagine labeled drawers ๐๏ธ:
"apple" โก ๐
"banana" โก ๐
"cat" โก ๐ฑ
You give a name (key) and get the item instantly!
๐ง How Data is Stored on Disk (HDD/SSD)
| Term | What It Means | Example |
|---|---|---|
| File | A saved thing | A photo, a document |
| Block | A chunk of disk | Like a page in a notebook ๐ |
| Sector | Smallest unit | Like one line on the page |
| Directory | Folder | Like your drawer label |
๐ Files are stored in blocks, and a file can be split across many!
๐จ When You Open a File...
- ๐ฅ Computer checks the file system
- ๐ Finds the location of the file blocks
- ๐ง Loads them into RAM
- ๐๏ธ You see the content on screen!
๐ Table: Data Storage Analogy
| Computer Term | Real-Life Example |
|---|---|
| RAM | Table youโre working on ๐๏ธ |
| HDD | Filing cabinet ๐๏ธ |
| Cache | Your shirt pocket ๐ |
| File | A document ๐ |
| Folder | A drawer ๐ |
| Sector | A line on a page ๐ |
๐ Letโs Look Inside a Picture File
Letโs say you save a photo of your cat ๐ฑ named "cutie.jpg":
- Your computer compresses it (squish to save space)
- It breaks it into blocks:
[block1] [block2] ... - It saves the blocks on your hard drive
- It updates the folder to remember where those blocks are
Later, when you open "cutie.jpg", the computer:
- Finds the blocks
- Puts them back together
- Shows you the picture! ๐ผ๏ธ
๐งช Mini Quiz Time!
-
Whatโs the smallest piece of data?
- A. Byte
- B. Bit โ
-
What stores data even when the power is off?
- A. Hard Drive (HDD/SSD) โ
- B. RAM
-
Whatโs faster than RAM?
- A. Disk
- B. Cache โ
๐ฆ Summary Recap
- Bits and bytes are the tiniest pieces of data
- RAM is fast memory, but forgets when off
- File systems help organize folders/files
- Data structures like arrays and stacks keep data neat
- Computers store files in blocks and sectors