What is the difference between a bitset and an array?
From NCERTAsked by Anonymous from London, United Kingdom24 Oct 2026, 8:31 AM ISTUpdated
In one line
A bitset stores only 0s and 1s using single bits, while an array stores bigger values (like numbers or letters) using more memory.
The rule
An array is a collection of elements (of the same type) stored in order, each at its own memory location. A bitset is a special data structure that stores only bits (0 or 1), packing them tightly so each bit uses just one binary digit.
Let's understand it simply
Imagine you have a row of boxes. Each box can hold a cricket ball (array), or just a small marble (bitset). An array is like these boxes, each big enough to hold any ball you want—red, blue, or green (numbers, letters, etc.). A bitset is like a row of tiny boxes, each can only hold a marble (0 or 1). So, a bitset is great if you only need to remember yes/no, on/off, true/false for many things, but not their actual values.
Bitset vs Array
Bitset
Array
What it stores
Only 0 or 1 in each spot
Any value of a fixed type (like 10, 20, 'A')
Memory used
Very little (1 bit per value)
More (like 8, 16, 32 bits per value)
Example use
Track on/off, yes/no, present/absent
Store marks, names, numbers
Can store big numbers?
No
Yes
How it works
Array:
You decide the type (like int, float, char) and size (how many elements).
Each element gets its own space in memory (like a separate box for each item).
You can store any value of that type in each spot.
Bitset:
You decide how many bits you need (like 8, 16, or 100).
Each bit is just a 0 or 1 (on/off).
All bits are packed tightly together, using very little space.
The story behind it
Arrays have been used since the early days of computers to store lists of data. Bitsets were invented to save memory when you only need to track yes/no for many things, like which seats in a stadium are taken. They became popular as computers needed to handle more data with less memory.
Where you see it in real life
Attendance register: Marking present (1) or absent (0) for 100 students — a bitset can store this in just a few bytes, while an array would use much more space.
Light switches in a building: Each switch is on (1) or off (0) — a bitset can track all switches efficiently.
Storing exam marks: You need an array, as each student can have marks from 0 to 100, not just 0 or 1.
Chessboard squares: Tracking which squares are occupied (1) or empty (0) — a bitset is perfect.
Mobile SIM contacts: Storing names and numbers needs arrays, as each entry is more than just yes/no.
Why it matters
Saves memory: Bitsets use much less memory than arrays when you only need 0/1 values.
Faster operations: Checking or changing a bit is quick, useful in games or apps.
Used in programming contests: Bitsets help solve problems with large yes/no lists.
Arrays are flexible: Needed when you want to store real data, not just on/off.
Common mistakes
Thinking a bitset can store any number — it can only store 0 or 1 in each spot.
Using an array for yes/no data — wastes memory if you only need on/off.
Forgetting that bitsets are not good for storing big numbers or words.
Remember it
Bitset = only 0/1, saves space. Array = stores any value, uses more space.
Check yourself
Can you store the number 25 in a bitset? Why or why not?
No, because a bitset can only store 0 or 1 in each spot.
Which is better for tracking which students are present: array or bitset? Why?
Bitset, because you only need to store present/absent (1/0), saving memory.
If you need to store the marks of 50 students, which should you use?
An array, because marks are numbers from 0 to 100, not just 0 or 1.
Quick recap
A bitset stores only 0 or 1 in each position.
An array can store any value of a chosen type (like numbers or letters).
Bitsets save memory when you only need yes/no data.
Arrays are needed for storing real data, like marks or names.
Bitsets are faster and smaller for large on/off lists.