Skip to main content

Command Palette

Search for a command to run...

About Array: What is array?

Published
•2 min read•View as Markdown
About Array: What is  array?
S

✨ 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

  1. Fast access to elements using index (O(1))

  2. Easy to use & understand

  3. Stores data in continuous memory

  4. Useful for fixed-size data

  5. Saves memory (no extra pointers) Disadvantages of Array

Disadvantage of Array

  1. Fixed size (cannot grow or shrink easily)

  2. Wastage of memory if size is not fully used

  3. Insertion & deletion are slow (elements must be shifted)

  4. Stores only same type of data

  5. 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)

FeatureArrayLinked List
MemoryContinuousNon-continuous
SizeFixedDynamic
AccessFast (index based)Slow (sequential)
Insertion/DeletionDifficult & slowEasy & fast
Memory usageLessMore (extra pointers)
ImplementationSimpleComplex
Data typeSame typeSame 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.