Computer Science and Problem Solving


Computer Science and Problem Solving

Corey
Welcome to the DSA Brain Training Series. Let’s begin with a big question: what is computer science? One useful way to think about it is as a toolbox full of ideas and techniques for solving problems.

Maria
So the basic pattern is: we give a computer an input, it processes that input using techniques, and it produces an output. The input represents the problem, and the output is the result we want. Applying computer science and DSA ideas to get that result—that’s problem solving.

Corey
Exactly. But that raises another question: how does a computer understand the input? It doesn’t understand English or Hindi the way people do. To see how it works, we need to look inside the computer.

Maria
A computer contains billions of electronic components called transistors. In this explanation, think of each transistor like a switch: it can be ON or OFF. When it’s ON, current can pass; when it’s OFF, current is stopped.

Corey
Those two electrical states can be represented using two digits. We write 1 for ON, meaning current is there, and 0 for OFF, meaning current isn’t there. A single 0-or-1 value is called a bit.

Maria
That’s the reason people say computers work with zeros and ones: their transistors have two states, and bits represent those states. One transistor gives us just two possibilities—0 or 1. But we need to represent far more than two values.

Corey
Adding more bits gives us more possible combinations. With one bit, there are two combinations. With two bits, there are four; with three bits, there are eight. It’s like flipping coins: one coin has two outcomes, two coins have four combinations, and three coins have eight.

Maria
So with n bits, there are 2 to the power n possible patterns. To picture how those patterns can represent numbers, let’s use the example of bulbs: a glowing bulb stands for 1, and an unlit bulb stands for 0.

Corey
With one bulb, OFF represents 0 and ON represents 1. Add a second bulb to the left, and now there are four patterns: 00, 01, 10, and 11. In the counting system we’re building, those represent 0, 1, 2, and 3.

Maria
The bulbs are arranged with the newest one added on the left, and we read the pattern from left to right. When every pattern with the current bulbs has been used, we add another bulb on the left. The source’s demonstration resets the existing bulbs before placing the new leftmost bulb in the ON state.

Corey
Let’s make the counting rule practical. Start at the rightmost bulb. If it’s OFF, turn it ON; that creates the next pattern. With two bulbs, after 10 comes 11, which represents 3.

Maria
And when the rightmost bulb is already ON, turn it OFF and move left to make the next change. So after 11, turn the right bulb OFF and the one to its left ON: that gives 10, representing 2 in the two-bit pattern sequence if counting in ordinary binary order would be 10 after 01; let's keep the example's pattern order carefully.

Ask anything
We've read this whole study set, so questions about it get the best answers.