Computer Science and Problem Solving
Transcript
Hey everyone, I am Shivam Shakya. Welcome to the DSA Brain Training Series where you can train your brain and crack any problem. Let me ask you a question. What is Computer Science? What actually is Computer Science? We have seen many definitions in textbooks. But what actually is it? Computer Science is nothing but a toolbox. Just a toolbox. What is inside this toolbox? Many ideas. Lots of ideas. We use these ideas to solve real life problems. That is all.
Nothing more. So how do we solve problems? We first give input to the computer. Then the computer does something with it. It processes it. And then it gives us output. What is this input? The input is our problem. The computer applies techniques and ideas from Computer Science on it and gives us output. What is the output? The goal and result we want. And this is what we call problem solving. What happens in problem solving? We have a problem. We apply ideas and techniques
that we learn from Computer Science and from DSA. And then we generate an output and result. This is what we call problem solving. Now the question is — this computer right here — how does input go inside it? How does it understand the input? Does the computer know English? No. Does the computer know Hindi? No. The computer knows nothing. So how does it understand all of this? And after processing, how does it give output? How does all of this happen?
We will find out in today's video. Let us start. Let us begin. Our computer is made of an electronic component. We call it a transistor. We call it a transistor. Inside our computer there are billions of transistors. Billions of transistors. When current flows through them, our computer runs. How does the computer run? How does it get energy? When it is charged, when current flows inside it, these transistors come into play and our computer runs.
A transistor has only two states. At any given time it is either ON or OFF. Just like a switch in our home. A switch has only two states — ON or OFF. ON means let the current pass. OFF means stop the current. Exactly the same way — the billions of transistors inside a computer are either ON or OFF. So what do these represent? They represent electrical state. What are they representing? They represent electrical state — is there current or not? So how do we show this?
When there is current inside the transistor, we represent that state with 1. And if there is no current inside the transistor, we represent it with 0. Zero. If 1 is showing — it means there is current in the transistor. If 0 is showing — it means there is no current in the transistor. And in computer language we call this a bit. We call this a bit. What is a bit? A bit simply represents the state inside one transistor — whether there is current in that transistor or not.
This is the reason. You must have heard that computers only understand zeros and ones. This is why — because computers have transistors and a transistor at any time is either ON or OFF — either current is there or not. And how is that represented? With 0 and 1. Now we know that computers only understand 0 and 1. But how does it understand everything else like 1, 2, 3? Let us see. Look — this is one transistor. What are its possibilities? Either ON or OFF. ON means 1. OFF means 0.
So how many possibilities are there? Only two. So how many things can we represent? Only two — zero and one. But we have much more data — 2, 3, 100, 500 and more. How do we represent all of that? If we have one transistor — only two possibilities. If we need to represent more data — we increase the possibilities. How? Simple — add more transistors. Now the possibilities double. Before it was two — now it is four. We need even more? Add another one.
Possibilities increase again. Keep adding transistors — possibilities keep growing and you can represent more data. You may have studied this in school — the coin example. One coin — heads or tails. Two coins — four possibilities. Three coins — eight possibilities. Same concept here. One transistor — two possibilities. Two transistors — four possibilities. Three transistors — eight possibilities. As we keep adding transistors, the possibilities keep growing. Simple.
But how do we actually represent data? We saw how possibilities increase. But how do we represent numbers? Let us understand with an example — a very beautiful example. Imagine there are many bulbs in front of you. Many bulbs placed in front of you. Like this. These are the bulbs. For now, imagine these bulbs are transistors. These bulbs are transistors.
Now if a bulb is glowing — what does that mean? Current is there. And how do we represent that state? With 1. And if a bulb is off — that means no current. And we represent that state with 0. Now what do you do? Take one bulb from the many in front of you and place it down. Just place it. You placed it. Now this bulb — is it OFF? Yes it is OFF. No current. And we represent that with? Zero. So this becomes — zero. Zero. Now turn this bulb ON. You turned it ON.
Now it is ON. Current is there. And we represent that with? One. Simple. We already know this. Now if we need to represent more data — I said increase possibilities. How? Add more transistors. What do you do? Keep placing bulbs to the left of existing ones. Keep adding transistors to the left. Now here is the most important rule — when you add a new transistor or bulb, first turn OFF all bulbs that are currently ON. Turn off all bulbs that are ON. You turned them off.
Done. Now what to do? Take the new bulb, turn it ON, and place it. It is ON now. When a bulb is ON we represent it with 1. When OFF — 0. So this combination becomes 1 0. Before we had 0 and 1. Now we need to represent 2. So we represent this combination as 2. 2. Now the simple rule — always start from the rightmost bulb. Start checking possibilities from the rightmost bulb. Simple rule — if the rightmost bulb is OFF, turn it ON. You turned it ON. You turned this one ON too.
Simple. Now both bulbs are ON. What combination is this? 1 and 1. A new combination — 1 1. And we represent this as 3. We represent this as 3. Now once all bulbs are ON — all the transistors, all the bulbs you have — all are ON. That means we have used all possibilities. To represent new data we need a new bulb — a new transistor. And we always add to the left. So let us add one. Before adding a new bulb — what do we do? Turn OFF all bulbs that are currently ON.
Then take the new bulb, turn it ON and place it. We turned the old ones OFF and turned the new bulb ON. A new combination is forming. What is it? 1 0 0. A new combination — 1 0 0. And we represent this as 4. Now we need to check all possibilities. How? Very simple. Start from the rightmost bulb. If it is OFF — turn it ON. And always remember — whenever you turn a new bulb ON, that means a new unique possibility is formed. You can represent a new number. So we turn a new bulb ON.
What combination is this? 1 0 1. We represent this as 5. Now rule number two. Rule one was — always start from rightmost bulb. Check possibilities. If it is OFF — turn it ON. And whenever any new bulb turns ON — that is a new possibility. Rule two — if the rightmost bulb is ON, turn it OFF and turn ON the one to its left. Simple — we turned this OFF. Now we turn the second one ON. A new possibility is formed. What is it? 1 1 0. And we call this 6.
We represent this as 6. Now check the next possibility. Start from the rightmost bulb again. If it is OFF — turn it ON. Turn it ON. Done. Now what possibility is formed? 1 1 1. We represent this as 7. Now all bulbs are ON. Once all bulbs are ON — that means there are no more possibilities. Simple — to represent more data we need to add another bulb — another transistor. And these combinations of zeros and ones — we call them in computer language
binary numbers. We call them binary numbers or binary digits. Binary — Bi means two. Any number made from two digits is called binary. Which two digits? Zero and one. So these combinations are called binary numbers. And we saw how by turning bulbs ON and OFF we represent numbers. This is how computers understand numbers and data. Now the rule we saw — always start from the rightmost bulb. Start from rightmost. If the rightmost bulb is OFF — turn it ON. Simple. If it is OFF — turn it ON.
That is a new possibility. And if it is ON — first turn it OFF and turn ON the one to its left. And whenever any bulb turns ON — that means we have a new possibility. Second rule — if it is ON, turn it OFF.
Turn it OFF and turn ON the one to the left. Simple. And if all bulbs are ON — that means all possibilities are covered. To represent more data we need to add a new bulb. Simple. This is how computers understand numbers. Now let me add one more bulb to give you complete clarity. How many numbers have we represented so far? Up to 7. Now if you want to check how many numbers you can represent with a given number of bulbs — the formula is: 2 to the power n minus 1. If we have three bulbs — 2 to the power 3 minus 1 = 8 minus 1 = 7.
See — we covered up to 7. If I add one more — 2 to the power 4 minus 1 = 16 minus 1 = 15. We can cover up to 15 numbers. Let us see how. This will be more fun now. What am I going to do here? Add a new transistor. So whenever we add a new bulb — turn OFF all bulbs that are currently ON. So first I need to turn these OFF. Let me turn them OFF. All bulbs turned OFF. Now what to do? Simply take one of the bulbs in front of you, turn it ON and place it. Just turn it ON. Just leave it ON.
I picked one more bulb and turned it ON. It is forming a new combination. What? This one is ON so 1. These are 0 0 0. What is this combination? Eight. Eight. Now to check new possibilities — start from the rightmost bulb. If it is OFF — turn it ON. I turned this one ON. Now this forms a new possibility. What? 1 0 0 1. We already used 8 — so this is nine. Now to check the next possibility — start from rightmost again. This was ON. This was ON. Rule — if rightmost is ON, turn it OFF.
I turned it OFF. And turn ON the one to its left. Let me turn the next one ON. A new possibility is formed. What? 1 0 1 0. We call this ten. We call this 10. Let us check the next possibility. Always start from the rightmost bulb. Always start from the rightmost. This is OFF — turn it ON. Turn it ON. Done. This was already ON too. So now a new possibility formed. What? 1 0 1 1 — that is 11. Right? Now check the next possibility. Start from rightmost. What is it? It is ON. So turn it OFF.
Then go left. This is also ON — turn it OFF too. Then go left again. So turn both of these OFF and turn this ON. I turned this ON. A new possibility — 1 1 0 0 — that is 12. Now check the next one. Start from rightmost — what is it? OFF. If OFF — turn it ON. I turned it ON. 1 1 0 1 — that is 13. Right? Check next. Rightmost is ON. If ON — turn it OFF. I turned it OFF. And this was already ON. New possibility — 1 1 1 0. I call this 14. Now check again. Rightmost is OFF — turn it ON.
This was already ON. These two were already ON. What is the new possibility? 1 1 1 1. And we represent this as 15. Now all bulbs are ON. All possibilities are used. We represent this as 15. To represent more data we need to add more transistors. I think you understand now. When you write code — you do not need to worry about how the computer converts it to zeros and ones. That is not your problem. The computer does it automatically. Who does it for the computer? The compiler.
The compiler. What is a compiler? A compiler is a software program that converts whatever code you write into machine code. This zero and one — we call it machine code. Machine code — the computer is a machine and what does it understand? Zero and one. Simple.

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