Hello everyone.
Welcome to the very first session where we will talk about what do we mean by an algorithm.
Right.
So, whenever we heard the term which is something called as algorithms, what does that mean?
The simple meaning is that, that it is something which is I would say is a combination of, it is a combination ofSequence of finite steps, right?
So here what we are trying to do is that we are trying to pass some sequence of finite steps.
Why?
In order to solve any problem, to solve any particular problem, right?
This is something which we called as a algorithms.
Now the very important thing here to understand is that that here what I am saying is that.
We are passing some finite steps.
Your steps can't be infinite otherwise your code will run into an infinite loop.
Right now here if you will see for example, let me try to give you one very simple example.
Suppose I want to multiply 2 numbers.
So what is the what algorithm you will write for that?
You will say that first of all if you want to multiply 2 numbers, so just do one thing.
So if you want to multiply 2 numbers, what you will say to me that what we can do is that if suppose I will say that tell me what is the algorithm for this.
So you will say step one is that you just take two numbers, right?
You just take two numbers, say the numbers are A&B.
After that what you can do is that you will just try to multiply these two numbers and store it in some.
Other variable which will try to solve the which will basically store the results of that.
So basically you can say that now take C which is storing the result of A B and finally what you can do is that you can simply return the value of C because that is something which I am saying is the multiplication of the two numbers.
So basically here if you will see.
I am having just three steps which are a finite number which is trying to solve the problem to multiply the any given 2 numbers.
Now these two numbers are something which is entered by the user, right?
So this is something where I want to solve one particular problem.
In our case.
In our example that problem is a multiplication of two numbers and that have the.
Some sequence like right.
First of all this thing will happen, then this thing and then finally we will get the result.
With this only let's talk about that what are the properties of an algorithm?
What are the important properties that we should know for an algorithm?
So first property.
Now I hope with the given definition itself you will be able to get a judgement that what should be the very first property that we have.
Very first property is that whenever you are writing any kind of algorithm, it should terminate.
It should terminate after finite amount of time, right?
It's not like that that your code is not terminating.
It should terminate after finite amount of time.
It should not be like that that it's running infinitely.
Second important property is that that whenever you are writing any algorithm, it should produce at least one output.
It should produce at least one output.
It should not be like that that your code is not producing any output.
It can produce more than one output as well.
But whenever you are writing any algorithm, it should produce anyone output.
For example in our example the output will be the value C.
The third important property is that that whatsoever code you are writing, it is independent of any programming language.
It is independent of any programming language.
Now this is very important thing, right?
This is very important.
Why is that so?
Because many students have used to ask to me that which programming language should I?
Try or should I start to understand algorithms?
Algorithms is something which will help you to solve the problem.
It's kind of a logic, but how you can implement that or what?
Tool you will use to implement that depends on you.
Because as I am telling you, this is independent of any programming language.
Means you can go with C, you can go with C, you can go with Java, you can go with Python, you can go with any of your favorite programming language, whatever you want.
So this is one of the most important thing that you have to keep in your head that whenever, whenever we are talking about algorithm, it is not dependent on any kind of programming language.
Very important point.
And the last important point is that that whenever you are writing any algorithm, the code that you are writing should be unambiguous.
The algorithm or the code that you are writing should be unambiguous.
Or in other words, I would say it should be deterministic.
What does that mean?
The simple meaning is that that suppose today I am running any code.
Today I am running any any logic that you have written, the algorithm that you have written.
For example, let me take the same example of multiplying the two numbers.
Now today the user is passing the input the value of A as five and the value of B as two and your code is returning the answer as five into two.
It is storing it.
In C which is 10 and it is giving me that the answer is something which is equals to 10 right?
Now in this example suppose the same algorithm whatever you have written here I have used the same code after may be 10 years.
So what happened when I am typing the same input it should produce the same output.
Or don't talk about years.
Let me talk about 10 days.
OK then also it means that whatever input you are passing today, you are getting some output and if you think that that output is correct.
After several years, after several days also, when you are using that code, it should produce the same output.
It's not like that today it is producing 10, but after some days it is producing 1215 or after some time, right?
So for every input, your output should remain same.
Then only you will say that you are writing a deterministic code, you are writing unambiguous code, right?
So, that's the important properties of an algorithm.
So, I think in today's session, what we have covered up.
First of all, we have seen what is the meaning of an algorithm.
Because this word algorithm you will heard a lot of times in the complete overall course.
So, it should be very much clear to you that what is the meaning of an algorithm.
So, it's a simple combination of sequence of finite steps.
Then we have took the example of the multiplication of two numbers.
And then we have seen what are the properties of an algorithm.
I hope that this part is pretty much clear to everyone.
If you still have any sort of doubt, do let me know.
With this, happy learning to all.
Bye bye everyone.
See you soon in the next upcoming session.
Comments
Post a Comment