About Array: What is array?

⨠About Me Hi š, Iām Sakshi, a tech enthusiast and beginner blogger passionate about learning and sharing technology in a simple way. TechNotes by Sakshi is a place where I write easy-to-understand notes and blogs on: š» Programming basics š Web development (HTML, CSS, basics)
An array is simply:
A list of item sorted together in order:
Think of it like s row of boxes , where:
Each box hold one value.
Each box has a number(position/index).
you can quickly pick any box if you know its number.
Everyday example:
imagine a fruit basket list:
apple
banana
guava
mango
This is a array of fruits.
Programming example(simple)
[10,20,33,48,89]
whereas :
10 is at position 0
20 is at position 1
33 is at position 2
48 is at position 3
89 is at position 4
Why we use arrays?
* Without array:
ā marks1, marks2, marks3, marks4
* With array:
ā marks[ ] = {50, 60, 70, 80}
KeyLine :
Stores many values
Values are of same type
Uses index (number) to access data
Index usually starts from 0
Advantages of Array
Fast access to elements using index (O(1))
Easy to use & understand
Stores data in continuous memory
Useful for fixed-size data
Saves memory (no extra pointers) Disadvantages of Array
Disadvantage of Array
Fixed size (cannot grow or shrink easily)
Wastage of memory if size is not fully used
Insertion & deletion are slow (elements must be shifted)
Stores only same type of data
Not efficient for dynamic data
Types of Arrays
1) One-Dimensional Array (1D)
Stores data in a single line
Uses one index
Example:
A=[89,90,44,65,56]
Use: List of marks, roll numbers2)
2) Two-Dimensional Array (2D)
Stores data in rows and columns
Looks like a table
Example:
A=([2:4],[4:9])
Use: Matrix, tables, images
Array vs Linked List (Easy Table)
| Feature | Array | Linked List |
| Memory | Continuous | Non-continuous |
| Size | Fixed | Dynamic |
| Access | Fast (index based) | Slow (sequential) |
| Insertion/Deletion | Difficult & slow | Easy & fast |
| Memory usage | Less | More (extra pointers) |
| Implementation | Simple | Complex |
| Data type | Same type | Same type |
__________________________________________________________________________________________________
One-line definition :-
An array is a data structure that stores multiple values of the same type in a single variable, using indexed positions.