100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached 4.2 TrustPilot
logo-home
Summary

Summary Array Operations _ Deletion from Array _ Explanation with Code _ Data Structure.docx

Rating
-
Sold
-
Pages
1
Uploaded on
22-04-2023
Written in
2022/2023

Array Operations _ Deletion from Array _ Explanation with Code _ Data S

Institution
Course








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

Written for

Course

Document information

Uploaded on
April 22, 2023
Number of pages
1
Written in
2022/2023
Type
Summary

Subjects

Content preview

1.3 Array Operations | Deletion from Array |
Explanation with Code | Data Structure
Jenny's Lectures CS IT
I will discuss the deletion operation using the example I used in a previous video.

Understanding how to delete data from a specific position will also make it easier to

delete data from the beginning or end of the array. I declared an array of size 50 in the

previous code, and the memory manager allocated 200 bytes of memory for this array.

One variable, size, is used to determine the maximum size of the array. If the user

wants to insert only 10 or 5 elements, for example, I will ask them how much size they

want for the array, and this will allocate an additional 4 bytes of memory. The user

will then enter the elements of the array, which will be initialized at runtime. To

delete data from the array, I will ask the user from which position they want to delete

the data. For example, if they want to delete data from position 2, I will shift the

values from position 3 to 4 and reduce the size of the array by 1. I will start a loop from

the position to be deleted to the end of the array and shift the values to the left. To

print the updated array after deletion, I will use a for loop to print each element of the

array. It's important to check the validity of the position entered by the user before

deleting data from the array. If the position is invalid, such as -1 or greater than the

size of the array, I will print "invalid position". If there is no data in the array, it's also

an underflow condition and the data cannot be deleted. When deleting data from the

end of the array, I will simply decrement the size of the array. When deleting data

from the beginning of the array, I will shift all the elements to the left and decrement

the size of the array. The time complexity of the deletion operation depends on the

position from which the data is to be deleted. If the data is to be deleted from a specific

position, all the elements to the right of that position must be shifted to the left,

which takes O(n) time. However, if the array is unsorted, a quicker algorithm is to pick

the last element of the array and put it in the position to be deleted. The best

algorithm for this case takes constant time, which is O(1).
$8.49
Get access to the full document:

100% satisfaction guarantee
Immediately available after payment
Both online and in PDF
No strings attached

Get to know the seller
Seller avatar
pranavnawandar

Also available in package deal

Get to know the seller

Seller avatar
pranavnawandar mahindra university
Follow You need to be logged in order to follow users or courses
Sold
0
Member since
2 year
Number of followers
0
Documents
19
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

Frequently asked questions