Introduction to Data Structures & Algorithms
This course is primarily for placement preparation and will be using C and C++ for the
algorithms and data structures. The notes for the course will be provided in PDF format for
convenience. Data structures are essential for developing efficient algorithms that arrange
data in main memory for optimal usage. It's important to note that algorithms and data
structures are two different things. C is a bare-bones programming language that requires
you to do everything yourself, but Java can also be used to implement algorithms. This
course is ideal for those looking to switch jobs or prepare for interviews, and there is a 15-
hour video on C programming available on the channel with notes.
should be able to use it in your work or in your projects or in your courses or in your projects
that you are doing in the future or in your work that you are doing right now so if you want to
use something then you should be able to use it in your work or in your projects or in your
courses or in your future work or in your projects that you are doing right now . So data
structures and algorithms are things that help us in our work or in our projects or in our
courses or in our future projects or in our work or in our projects that we are doing right now
so if you want to use something then you should be able to use it in your work or in your
projects or in your courses or in your future work or in your projects that you are doing right
nowwater in a pot and you put the tea bag in the cup and you make the coffee Now what is
the difference between data structures and algorithms? Algorithms are specific steps that
need to be taken in order to solve a problem.I have been in the industry for a long time now
and I have seen a lot of people learning C , C++ and when they start to learn it they get very
lost & confused & they don't know what they are doing & they don't know how to use the
language properly & eventually they stop learning it & they end up becoming a beginner again
& that is not good for the industry & it is not good for the learners either so I would say learn
C , C++ & don't get lost in the language learning process
Data structure is the arrangement of data in main memory, and the concept of database,
data warehouse, and big data will be covered in the course. The fuel of big algorithms is
data, and keeping it properly in the hard disk is essential for efficient retrieval, updating, and
deletion. Although data warehousing is beyond the scope of this course, it's still important to
understand it. Data structures and algorithms are best learned from C and C++, which
provide a good picture of memory usage. The concepts of stack and heap are essential in
understanding how C programs work, and space and time complexity will be covered in
future videos. Overall, this course will cover many data structure concepts, such as linked
lists, arrays, binary search trees, and more.
Time Complexity and Big O Notation
So the input size didn't increase and the runtime of the algorithms didn't increase either .No ,
it doesn't depend on the size of the input . When we ask questions like as the input will
increase, Then the runtime will change as per what? And after that Now you will go to aunty's
house You will be treated. Consider there are different routes to come and go.
,I want to tell you guys one story. It happened like this , I was bored in my house. I was so
bored that I needed some entertainment. This guy has amazing games like Pubg and GTA5.
So he has a collection of games. He likes playing games a lot. And you can get every type of
game from him. But there is one problem , I also use jio. He also uses jio and we get just 1
Gb for one day. And with more internet , we ca n't sell files and all. So for me , what is the
fastest way to take the game from this friend. So what will I do ? I will take my bike As the
size of this input will get increased, the runtime of the algorithms will increase. This means
that as the input size is increasing like that The time required to send the file , That is also
increasing. There is a hard disk then there is your motorcycle. You will go on that bike. And
you will take it and in hard disk whether you bring 250kb or Tb. As the input size of algo2
increased like that what happened ? For that , there was no change in the runtime. Runtime
remained the same. So we say as the size of the input keeps on increasing , Similarly, what
is the effect of the algorithm on runtime. We are to trying to remove the time complexity of
them.
is the algorithm that runs in constant time . K1 n to the power 0+k2+k3+k4 This time is
required in algo 2 .The sentence is: Run time of it, there are some things that we will recite.
Because we won't constantly use our brains again and again, as we see Big O of 1 it is
constant. Now, come here and listen to another story. If we do an analysis of the first
algorithm, If I do T algo1 Then what will happen here? And along with consider that game is
of L3 kb. If the game is of N kb then how much time will you need? The sentence is: Run time
of it, there are some things that we will recite.There are polynomial algorithms and there are
exponential algorithms and there are logarithmic algorithms and there are exponential
functions and there are logarithmic functions. There are also algorithms that are not linear in
time.
We are not studying algorithms, we are listening to a story. We are doing a real-world
analysis of things. Big O is called a constant runtime algorithm. Because it was constant we
remove n to power 0 and make it 1. So this is Big O of n to the power 0. If I do T algo1 then
what will happen here ? What do I have to do ? When I am sending data then I must upload
and send. My main time is required in that ok. Now, considering I turn on my computer In
that , I will need time L1 After that what happened ? Consider all preparation I required L1
which will be a constant 5 secs,2 secs , 10 secs. If there is an SSD in your computer then it
will open in 4 secs If you are using a supercomputer then it can even open in 1 sec. L1+
consider your speed is L2. Ok, so it takes a constant speed of your This is not equal to.
Writing equal to is wrong here. So here I will say that The most difference that will be visible
It will be because of this term. Because n to power 1 , if I increase input and make it 10 lakh.
So this was of 2 lines but this will become 10 lakhs. So the higher degree term in the
polynomial In any equation The most impactful term It is taken ok. So I picked this because
in comparison with n to the power 0 it is big. And I want to see things in a simple way.
Big O of n square. Big O is a log that scales according to the time required to run your
algorithm. Linearly if your time scales with the input size. If it runs in linear time Big O. If your
time runs in constant time, Big O is 1 ok. O in the industry means the order of And its
mathematical definition that I will tell you. Industry definition is a minimum of this. But when
you are answering in industry Then industry definition is used. When I use its mathematical
definition then I say Big O But when I give industry definition Or I am answering any interview.
Then I will say an order of because big O has a different definition. But they are used
interchangeably. The graph of Big O of 1 is plotted like this. It does not mean it is 1 's graph.
,Do n't confuse it with the x=1 graph. This is the graph of x=k. Constant , whatever constant
was there in constant time it was running. And this y=mx+c It can be somewhat distorted.
Time complexity is the study of the efficiency of algorithms. How time taken to execute an
algorithm Grows with the size of the input. Time will increase and time will increase or
decrease. Here I am giving a real-world example because the examples we took were very
naive. They were very simple. Shubham 's algorithm took 180ms. And over there Rohan's
algorithm was around 120-130ms. It took 121 ms. After that when I gave 1000 elements for
their algorithms , Then shubham's algorithm got busted over there. But Rohan "s algorithm
did it in 800 ms. Both are better in their places. In this way we analyze algorithms. take the
highest order term. After that, we will add in Big O. And Big O n square square is here. And
here n whatever it is , Like here it was 5 size n. In the next video we will solve problems & see
other concepts.
Asymptotic Notations: Big O, Big Omega and Big Theta
Explained
We 'll talk a little bit about asymptotic notation. we talked about order. We talked about
ordering. We have primarily 3 types of asymptic notation big O, big Theta (Θ ) and big Omega
(Ω) big O is represented by capital (O), which is in our English. Big O is set to be O ( g ( n ) ) if
and only if there exist a constant ( c ) and a constant n -node such that 0 ≤ f ( n) ≤ cg (n) is O (g
(N) If you watch this video completely then I guarantee that you will understand these three
notations. Mathematically, mathematically this function can be anything. When we do analysis
of algorithms comparing any 2 algorithms then f ( n ) will be time and what is n , it 's input ok ,
size of input. G ( n) is your function which will come inside the big O. O ( n²) is Anything Can
Be Algorithm it is g (n) that will be here and which is your algorithm. If you guys can find any
such constant ( C ) and ( n ) -node , then f ( n) is O ( g ( n)" This is the mathematical definition
of big O. If you ca n't find it then its is not f (n ) is O. This question is its own truth , it has
validity , it will remain valid.
This passage discusses the complexity of an algorithm, which is measured in terms of the
size of its big O graph. THe author states that the complexity of an algorithm is
automatically O(n^5.), O(n^30), and O(n^100).& G ( n ) is intersecting with f ( n ). So you will
get some complex function Alright so this is the solution to the problem So. What we have
done is WE have taken a big function and we have made it so that it is always below the
original function and that's what [UNK] means THe definition of [UNK] for a function. F(n) is
the largest value of G(n) that is bigger than f(n)..
, Best Case, Worst Case and Average Case Analysis of an
Algorithm
To define an algorithm, To define the events in the life of an algorithm , We have , Best Case
Worst Case and Expected Case. And along with that, I 've packed one more thing into this
video : The definition of Log. If you watch this video till the end , Then you will find out what
this 'Log ' really is. 1. . . 5. . . 7. . . 9 and 24 are the numbers in it; They 're in ascending order ,
You can see for yourself. If you know even a bit of maths, You 'll know that it is in an
ascending order. Now what I say is that I 'll give a number : 'A' And I 'd like you to tell me If
this number exists within the array , or not. Suppose the value of A is 8. So what will be your
answer ? Yes. Meaning 1. If A is. . . Sorry, your answer will be no , because it is n't there. If
the value is 9, What will the answer be ? Your answer will Algo 1 is a simple person. It does
n't have much of a brain. It is comparing it with all the numbers. Is this the best way to do
this work ? Obviously not. Because Algo. 1 is lucky , He will get A=1. It will tell us in the first
comparison itself. In one comparison only.
If Algo 1 is in luck, The time needed is ' k ' - T=k. This means that it does n't depend on 'n '.
Take a 10-element array, take a single element array or take a 10,000 element array. It only
has to make one comparison because it is only searching for the first element in the array.
Now, AlGo 1 's luck is bad. Till now, he was fortunate ; But now he 's not so lucky anymore.
Average Case complexity is equal to. . . the sum of the run time for the total number of
possibilities. The O ( Sum of all possible run times divided by the number of possibility ) is O
( n ) The average case complexity is the sum. Average Case is equal. to. . . The sum of all.
possible run. times divided. by the total. number of possible run time. So for an array size of
5, We saw six cases. 't ' ; I 'll calculate ' O ' later. n+1 If 'n ' is the size of the array , Then there
is 'n+1 '' number of possibilities. 'n' possibilities is when there is 1st element, 2nd element,
3rd element, 4th element, 5th element and 6th element. If the element is here, How many
comparisons will it have to make ? It will have to do. . . 1. . . 2. . . 3 comparisons. I 've taken '
k ' as common out of everything. I removed this because this is different. And this I have
added separately.
K is an integer ) SO now I 'll write it like this K n ( K is an integer ) So now I 'll write it Like this
K n ( K is an integer ) So now I 'll write it like this. K n ( K is an integer ) And now what will
happen? The value of 'k ' will become very large And so 2n will be going down. The graph of (
n^2+n ) ; graph of n ; graph of ( N^2+n ) will go below 2n. THe Average Case Complexity for a
given algorithm is the time it takes to run through all possible cases, divided by the total
number of possibilities..?" This passage discusses Algo 2, which is a cunning person who is
smart. Birbal. Algo 2 says that he will not make useless comparisons, and provides an
example. An example of how he does this.. Algo 2 first takes the first and last element of an
array, and then compares them. IF. They match, Algo 2 is good; if they don't match., Algo 2
will find the mid--point of the array and be okay..
AP is Arithmetic Progression and GP is a geometric progression. AP is used in 'O ' a lot. APs
are made as well as GPs sometimes. When there are questions on 'O' APs and GPs are used
in the answers to questions on O. The formula of Average Case Complexity is All possible
run times divided by the total number of possibilities. The Average Case Time is not
generally asked for a unique algorithm. It can be asked for this type of algorithm , A simple
algorithm that compares all of these. So what is the Average Case. Complexity ? O ( n ). Algo
This course is primarily for placement preparation and will be using C and C++ for the
algorithms and data structures. The notes for the course will be provided in PDF format for
convenience. Data structures are essential for developing efficient algorithms that arrange
data in main memory for optimal usage. It's important to note that algorithms and data
structures are two different things. C is a bare-bones programming language that requires
you to do everything yourself, but Java can also be used to implement algorithms. This
course is ideal for those looking to switch jobs or prepare for interviews, and there is a 15-
hour video on C programming available on the channel with notes.
should be able to use it in your work or in your projects or in your courses or in your projects
that you are doing in the future or in your work that you are doing right now so if you want to
use something then you should be able to use it in your work or in your projects or in your
courses or in your future work or in your projects that you are doing right now . So data
structures and algorithms are things that help us in our work or in our projects or in our
courses or in our future projects or in our work or in our projects that we are doing right now
so if you want to use something then you should be able to use it in your work or in your
projects or in your courses or in your future work or in your projects that you are doing right
nowwater in a pot and you put the tea bag in the cup and you make the coffee Now what is
the difference between data structures and algorithms? Algorithms are specific steps that
need to be taken in order to solve a problem.I have been in the industry for a long time now
and I have seen a lot of people learning C , C++ and when they start to learn it they get very
lost & confused & they don't know what they are doing & they don't know how to use the
language properly & eventually they stop learning it & they end up becoming a beginner again
& that is not good for the industry & it is not good for the learners either so I would say learn
C , C++ & don't get lost in the language learning process
Data structure is the arrangement of data in main memory, and the concept of database,
data warehouse, and big data will be covered in the course. The fuel of big algorithms is
data, and keeping it properly in the hard disk is essential for efficient retrieval, updating, and
deletion. Although data warehousing is beyond the scope of this course, it's still important to
understand it. Data structures and algorithms are best learned from C and C++, which
provide a good picture of memory usage. The concepts of stack and heap are essential in
understanding how C programs work, and space and time complexity will be covered in
future videos. Overall, this course will cover many data structure concepts, such as linked
lists, arrays, binary search trees, and more.
Time Complexity and Big O Notation
So the input size didn't increase and the runtime of the algorithms didn't increase either .No ,
it doesn't depend on the size of the input . When we ask questions like as the input will
increase, Then the runtime will change as per what? And after that Now you will go to aunty's
house You will be treated. Consider there are different routes to come and go.
,I want to tell you guys one story. It happened like this , I was bored in my house. I was so
bored that I needed some entertainment. This guy has amazing games like Pubg and GTA5.
So he has a collection of games. He likes playing games a lot. And you can get every type of
game from him. But there is one problem , I also use jio. He also uses jio and we get just 1
Gb for one day. And with more internet , we ca n't sell files and all. So for me , what is the
fastest way to take the game from this friend. So what will I do ? I will take my bike As the
size of this input will get increased, the runtime of the algorithms will increase. This means
that as the input size is increasing like that The time required to send the file , That is also
increasing. There is a hard disk then there is your motorcycle. You will go on that bike. And
you will take it and in hard disk whether you bring 250kb or Tb. As the input size of algo2
increased like that what happened ? For that , there was no change in the runtime. Runtime
remained the same. So we say as the size of the input keeps on increasing , Similarly, what
is the effect of the algorithm on runtime. We are to trying to remove the time complexity of
them.
is the algorithm that runs in constant time . K1 n to the power 0+k2+k3+k4 This time is
required in algo 2 .The sentence is: Run time of it, there are some things that we will recite.
Because we won't constantly use our brains again and again, as we see Big O of 1 it is
constant. Now, come here and listen to another story. If we do an analysis of the first
algorithm, If I do T algo1 Then what will happen here? And along with consider that game is
of L3 kb. If the game is of N kb then how much time will you need? The sentence is: Run time
of it, there are some things that we will recite.There are polynomial algorithms and there are
exponential algorithms and there are logarithmic algorithms and there are exponential
functions and there are logarithmic functions. There are also algorithms that are not linear in
time.
We are not studying algorithms, we are listening to a story. We are doing a real-world
analysis of things. Big O is called a constant runtime algorithm. Because it was constant we
remove n to power 0 and make it 1. So this is Big O of n to the power 0. If I do T algo1 then
what will happen here ? What do I have to do ? When I am sending data then I must upload
and send. My main time is required in that ok. Now, considering I turn on my computer In
that , I will need time L1 After that what happened ? Consider all preparation I required L1
which will be a constant 5 secs,2 secs , 10 secs. If there is an SSD in your computer then it
will open in 4 secs If you are using a supercomputer then it can even open in 1 sec. L1+
consider your speed is L2. Ok, so it takes a constant speed of your This is not equal to.
Writing equal to is wrong here. So here I will say that The most difference that will be visible
It will be because of this term. Because n to power 1 , if I increase input and make it 10 lakh.
So this was of 2 lines but this will become 10 lakhs. So the higher degree term in the
polynomial In any equation The most impactful term It is taken ok. So I picked this because
in comparison with n to the power 0 it is big. And I want to see things in a simple way.
Big O of n square. Big O is a log that scales according to the time required to run your
algorithm. Linearly if your time scales with the input size. If it runs in linear time Big O. If your
time runs in constant time, Big O is 1 ok. O in the industry means the order of And its
mathematical definition that I will tell you. Industry definition is a minimum of this. But when
you are answering in industry Then industry definition is used. When I use its mathematical
definition then I say Big O But when I give industry definition Or I am answering any interview.
Then I will say an order of because big O has a different definition. But they are used
interchangeably. The graph of Big O of 1 is plotted like this. It does not mean it is 1 's graph.
,Do n't confuse it with the x=1 graph. This is the graph of x=k. Constant , whatever constant
was there in constant time it was running. And this y=mx+c It can be somewhat distorted.
Time complexity is the study of the efficiency of algorithms. How time taken to execute an
algorithm Grows with the size of the input. Time will increase and time will increase or
decrease. Here I am giving a real-world example because the examples we took were very
naive. They were very simple. Shubham 's algorithm took 180ms. And over there Rohan's
algorithm was around 120-130ms. It took 121 ms. After that when I gave 1000 elements for
their algorithms , Then shubham's algorithm got busted over there. But Rohan "s algorithm
did it in 800 ms. Both are better in their places. In this way we analyze algorithms. take the
highest order term. After that, we will add in Big O. And Big O n square square is here. And
here n whatever it is , Like here it was 5 size n. In the next video we will solve problems & see
other concepts.
Asymptotic Notations: Big O, Big Omega and Big Theta
Explained
We 'll talk a little bit about asymptotic notation. we talked about order. We talked about
ordering. We have primarily 3 types of asymptic notation big O, big Theta (Θ ) and big Omega
(Ω) big O is represented by capital (O), which is in our English. Big O is set to be O ( g ( n ) ) if
and only if there exist a constant ( c ) and a constant n -node such that 0 ≤ f ( n) ≤ cg (n) is O (g
(N) If you watch this video completely then I guarantee that you will understand these three
notations. Mathematically, mathematically this function can be anything. When we do analysis
of algorithms comparing any 2 algorithms then f ( n ) will be time and what is n , it 's input ok ,
size of input. G ( n) is your function which will come inside the big O. O ( n²) is Anything Can
Be Algorithm it is g (n) that will be here and which is your algorithm. If you guys can find any
such constant ( C ) and ( n ) -node , then f ( n) is O ( g ( n)" This is the mathematical definition
of big O. If you ca n't find it then its is not f (n ) is O. This question is its own truth , it has
validity , it will remain valid.
This passage discusses the complexity of an algorithm, which is measured in terms of the
size of its big O graph. THe author states that the complexity of an algorithm is
automatically O(n^5.), O(n^30), and O(n^100).& G ( n ) is intersecting with f ( n ). So you will
get some complex function Alright so this is the solution to the problem So. What we have
done is WE have taken a big function and we have made it so that it is always below the
original function and that's what [UNK] means THe definition of [UNK] for a function. F(n) is
the largest value of G(n) that is bigger than f(n)..
, Best Case, Worst Case and Average Case Analysis of an
Algorithm
To define an algorithm, To define the events in the life of an algorithm , We have , Best Case
Worst Case and Expected Case. And along with that, I 've packed one more thing into this
video : The definition of Log. If you watch this video till the end , Then you will find out what
this 'Log ' really is. 1. . . 5. . . 7. . . 9 and 24 are the numbers in it; They 're in ascending order ,
You can see for yourself. If you know even a bit of maths, You 'll know that it is in an
ascending order. Now what I say is that I 'll give a number : 'A' And I 'd like you to tell me If
this number exists within the array , or not. Suppose the value of A is 8. So what will be your
answer ? Yes. Meaning 1. If A is. . . Sorry, your answer will be no , because it is n't there. If
the value is 9, What will the answer be ? Your answer will Algo 1 is a simple person. It does
n't have much of a brain. It is comparing it with all the numbers. Is this the best way to do
this work ? Obviously not. Because Algo. 1 is lucky , He will get A=1. It will tell us in the first
comparison itself. In one comparison only.
If Algo 1 is in luck, The time needed is ' k ' - T=k. This means that it does n't depend on 'n '.
Take a 10-element array, take a single element array or take a 10,000 element array. It only
has to make one comparison because it is only searching for the first element in the array.
Now, AlGo 1 's luck is bad. Till now, he was fortunate ; But now he 's not so lucky anymore.
Average Case complexity is equal to. . . the sum of the run time for the total number of
possibilities. The O ( Sum of all possible run times divided by the number of possibility ) is O
( n ) The average case complexity is the sum. Average Case is equal. to. . . The sum of all.
possible run. times divided. by the total. number of possible run time. So for an array size of
5, We saw six cases. 't ' ; I 'll calculate ' O ' later. n+1 If 'n ' is the size of the array , Then there
is 'n+1 '' number of possibilities. 'n' possibilities is when there is 1st element, 2nd element,
3rd element, 4th element, 5th element and 6th element. If the element is here, How many
comparisons will it have to make ? It will have to do. . . 1. . . 2. . . 3 comparisons. I 've taken '
k ' as common out of everything. I removed this because this is different. And this I have
added separately.
K is an integer ) SO now I 'll write it like this K n ( K is an integer ) So now I 'll write it Like this
K n ( K is an integer ) So now I 'll write it like this. K n ( K is an integer ) And now what will
happen? The value of 'k ' will become very large And so 2n will be going down. The graph of (
n^2+n ) ; graph of n ; graph of ( N^2+n ) will go below 2n. THe Average Case Complexity for a
given algorithm is the time it takes to run through all possible cases, divided by the total
number of possibilities..?" This passage discusses Algo 2, which is a cunning person who is
smart. Birbal. Algo 2 says that he will not make useless comparisons, and provides an
example. An example of how he does this.. Algo 2 first takes the first and last element of an
array, and then compares them. IF. They match, Algo 2 is good; if they don't match., Algo 2
will find the mid--point of the array and be okay..
AP is Arithmetic Progression and GP is a geometric progression. AP is used in 'O ' a lot. APs
are made as well as GPs sometimes. When there are questions on 'O' APs and GPs are used
in the answers to questions on O. The formula of Average Case Complexity is All possible
run times divided by the total number of possibilities. The Average Case Time is not
generally asked for a unique algorithm. It can be asked for this type of algorithm , A simple
algorithm that compares all of these. So what is the Average Case. Complexity ? O ( n ). Algo