Operations on Arrays in Data Structures: Traversal, Insertion,
Deletion and Searching
ByAnonymous–
Today we 'll talk about some operations in array. The first primary operation is called traversal. It
's the easiest thing in array, it 's like 2x2=4. In traversal, every array element has to be visited
once. If you want to print all the array elements or you may want to set this array. If you 're
confused why 0, 1, 2, 3 etc. or similar doubts, then your situation is such that you need to write C
language. At home, do C language, 15 hours sleep a little less one day and complete it. At about
11 at night, you 'll be done with it. I 'm kidding, watch it in breaks whenever possible. I've
included practice in it. So here , we 've seen traversal. I'll tell you what I was going to say. In
traversal, we can use as many elements present. So, you can make two variables, one will be
capacity. The capacity here will be 100. You can make size , it will be 5. Size means how many
elements you are using. Capacity shows that this is the potential. If a pot can hold 10 liters and
you store only a liter in it, but you bought it to store more if needed in future. That's why you take
a higher capacity in array and the size is 5.
In school assembly, children used to stand in a line. The children are standing here and suppose
something is being given out like ice cream. If I want 5 to be at index 2 , I 'll have to shift them
first. Though in school you join the line first and shift later. You 'll make space first, add 15
blocks. This goes up to 99, 0, 1, 2, 3, 4. After that, what did I do for insertion ? I shifted the
elements. Now, if you 're a very lucky person , then you 'll get index number 5 for insertion. All
this is in the notes , nothing to worry about. I have provided everything , just download the notes.
Zipping is for your convenience, use a computer to unzip. I zip it so that all codes, source codes,
and pdfs are in one place. Comment below what the best case deletion run time is and what the
worst case is. It 'll be O ( 1) in best case, you had to delete the last one. In worst case, the
element order does n't matter. In both best case and worst case cases, the size does n' matter.
If we reach 99 while adding elements, what to do ? We ca n't insert after that , there 's only one
option then. There 's no other option , only prayers will work. You 'll have to copy it then. You do
n't want an overflow condition , it 's called overflow. You are breaking the array 's borders. You
can search in this way, one by one. If the array was sorted, you 'll use binary search. This is
called linear search. And binary search, okay. You 'll take its greatest integer and mid will be 2.
Your mid is 2 , so you come to it. You'll check if it 's greater or smaller than mid , it ''s smaller.
Now you 'll keep doing this till your array finishes or you find your element. After this
convergence, your search will be over. When the array is not sorted, use linear search.
Otherwise, binary search is the way to go. It 's computationally cheaper , that is quicker and
takes less space. we 'll code these operations in C language and C++ too. You can do it if you
know C and C ++ for obvious reasons which I stated initially. Python, Java etc. too you can
follow with those too as I said earlier but again I 'm C , C++ here. Majority of the people wanted
data structure algorithm in those languages.
Deletion and Searching
ByAnonymous–
Today we 'll talk about some operations in array. The first primary operation is called traversal. It
's the easiest thing in array, it 's like 2x2=4. In traversal, every array element has to be visited
once. If you want to print all the array elements or you may want to set this array. If you 're
confused why 0, 1, 2, 3 etc. or similar doubts, then your situation is such that you need to write C
language. At home, do C language, 15 hours sleep a little less one day and complete it. At about
11 at night, you 'll be done with it. I 'm kidding, watch it in breaks whenever possible. I've
included practice in it. So here , we 've seen traversal. I'll tell you what I was going to say. In
traversal, we can use as many elements present. So, you can make two variables, one will be
capacity. The capacity here will be 100. You can make size , it will be 5. Size means how many
elements you are using. Capacity shows that this is the potential. If a pot can hold 10 liters and
you store only a liter in it, but you bought it to store more if needed in future. That's why you take
a higher capacity in array and the size is 5.
In school assembly, children used to stand in a line. The children are standing here and suppose
something is being given out like ice cream. If I want 5 to be at index 2 , I 'll have to shift them
first. Though in school you join the line first and shift later. You 'll make space first, add 15
blocks. This goes up to 99, 0, 1, 2, 3, 4. After that, what did I do for insertion ? I shifted the
elements. Now, if you 're a very lucky person , then you 'll get index number 5 for insertion. All
this is in the notes , nothing to worry about. I have provided everything , just download the notes.
Zipping is for your convenience, use a computer to unzip. I zip it so that all codes, source codes,
and pdfs are in one place. Comment below what the best case deletion run time is and what the
worst case is. It 'll be O ( 1) in best case, you had to delete the last one. In worst case, the
element order does n't matter. In both best case and worst case cases, the size does n' matter.
If we reach 99 while adding elements, what to do ? We ca n't insert after that , there 's only one
option then. There 's no other option , only prayers will work. You 'll have to copy it then. You do
n't want an overflow condition , it 's called overflow. You are breaking the array 's borders. You
can search in this way, one by one. If the array was sorted, you 'll use binary search. This is
called linear search. And binary search, okay. You 'll take its greatest integer and mid will be 2.
Your mid is 2 , so you come to it. You'll check if it 's greater or smaller than mid , it ''s smaller.
Now you 'll keep doing this till your array finishes or you find your element. After this
convergence, your search will be over. When the array is not sorted, use linear search.
Otherwise, binary search is the way to go. It 's computationally cheaper , that is quicker and
takes less space. we 'll code these operations in C language and C++ too. You can do it if you
know C and C ++ for obvious reasons which I stated initially. Python, Java etc. too you can
follow with those too as I said earlier but again I 'm C , C++ here. Majority of the people wanted
data structure algorithm in those languages.