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

Array Operations | Deletion from Array

Rating
-
Sold
-
Pages
1
Uploaded on
01-05-2023
Written in
2022/2023

Array Operations | Deletion from Array

Institution
Course

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 del ete 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 th e 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).

Written for

Institution
Course

Document information

Uploaded on
May 1, 2023
Number of pages
1
Written in
2022/2023
Type
Class notes
Professor(s)
Jenny
Contains
All classes

Subjects

$8.49
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
nithinrosarieo

Also available in package deal

Get to know the seller

Seller avatar
nithinrosarieo SRM UNIVERSITY
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
3 year
Number of followers
0
Documents
3
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