December 13, 2021
In these new series of blogs we will start learning DSA.
Many new developers have difficulty learning data structures and algorithms. This problem is mainly because data structures and algorithms are more technical than basic HTML/CSS. Before continuing, I think it would be helpful to first understand how DataStructure & Algorithm is useful.
Data structures and algorithms help you understand how your libraries and frameworks work internally. This knowledge will help you to use them more efficiently and correctly. To develop your skills as a developer, you need at least a basic understanding of the algorithm.
Also when you start maintaining larger applications and need to scale a good understanding of datastructures & algorithms will be very crucial to your success. When your application starts servicing thousands of users and speed becomes important a very good understanding of datastructures will help you in scaling your website to meet the demands of users. Knowledge of algorithms will also help you in solving complex business & computer problems in an efficient manner.Your knowledge of data structures and algorithms is sometimes tested in technical interviews.
before starting it will be sencefull to define Algorithm.
A simple and complete defination of algorithm would be A set of steps or instruction for completing a task. thats it, isn’t it simple?😎
In CS algorithm specifically means :- A set of steps a program takes to finish a task. Like in python to print Hello world an instruction could be given as
print("Hello world")
Where print is an instruction.
Part of understanding algorithm is not just knowing that an algorithm exist but understanding when to apply it, this is called algorithmic thinking.
Let’s suppose we play simple game where I will decide a number and let my 2 friends guess the number that I choose. When they guess a number I will tell them if their guess is too high or low.
🥇 The winner is one with fewest tries.
Suppose I choosed - 3 and Jhon started playing.
First question which Jhon asked Does the range include 1 & 10.To which my answer is Yes it includes 1 & 10,
Now moving to next step. Jhon starts guessing the number :-
Playing same game with Ana (player 2), with all codition as in previous case.
Now Ana starts guessing :-
It’s a tie both Jhon and Ana guessed the number in 3 tries. Let’s play again, this time I choose 10.
Again starting with Jhon :-
Now Ana’s turn:-
When the answer was ‘3’ both Jhon and Ana took the same number of turns this is important. When the number was larger but not that much larger (in this case 10) we start to see that Ana’s strategy did better, Ana took 4 tries while Jhon took 10 tries.
Let’s play the game for one more time for a range between 1 & 100 including 1 & 100
This time I choose 5.
Starting the game with Jhon again:-
Now Ana’s turn:-
This time Jhon took 5 tries where as Ana took 7 tries.
🤯 Jhon’s approach is called Linear Search or Sequential search or Simple Search. While Ana’s approach is called Binary Search.
Next part coming soon! Till then Code hard try learning basics of python.