Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Class notes

Data Structures using Arrays

Rating
-
Sold
-
Pages
21
Uploaded on
19-03-2023
Written in
2022/2023

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. In the coming videos, 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. This is a course for data structures I do n't want to teach you how to print the elements of an array. So here I 'll make an int size=4; that shows that we are using 4 elements. And that it has the capacity to store 100 elements. If I want , in the future I can add more elements. If there is no space in your array, then what can you do? If your whole array is full; when your size is or = to the capacity , Then I ca n't take any more in it. If the capacity of your tank is 100 litres, and there are already 100 litres then the 101st litre can't fit in it ; no matter how much it tries. When there 's no space or capacity you 'll have to return -1. Assume that this is an array of 7,8,12,27 and 88. And ahead of this , there is a lot of space. So for that, a for loop will be working. So I 'm taking -1 as a representation because if you return. Then your insertion was n't successful. Okay ? Now I 'll do this. The insertion was. n't. successful here. Now if it does n't get returned , what does it mean ? So I want that index 4 should go ahead. Because there 's space in the array. If there was n't space then it would return it. So 88 will move ahead. I 'm starting from i=size -1. My size is 5 i. 'll have to do arr (i+1 ) =arr (i ). And along with that ; I 'll write arr here and either return the index or return 1. 1 for success. It 's done ; we 've successfully done an insertion in your array. I hope that this course must be helpful for you. So many people have accessed the playlist and I 'm so happy to see that. And many of you have downloaded the notes. So here you guys can do one thing , There 's a quiz for you guys and that is ; you have to modify this code Such that you should be able to find out whether the insertion was successful or not. If the insertion is successful, You will print the new , modified array. Otherwise, you will say that 'insertion failed' and that will be enough.

Show more Read less
Institution
Course










Whoops! We can’t load your doc right now. Try again or contact support.

Written for

Institution
Course

Document information

Uploaded on
March 19, 2023
Number of pages
21
Written in
2022/2023
Type
Class notes
Professor(s)
Nil
Contains
All classes

Subjects

$10.99
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
abhisekpaul20020

Get to know the seller

Seller avatar
abhisekpaul20020 Haldia Institute of Technology
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
3 year
Number of followers
0
Documents
10
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions