100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached
logo-home
Class notes C Program /Data structure Tutorials $7.99   Add to cart

Class notes

Class notes C Program /Data structure Tutorials

 1 view  0 purchase
  • Course
  • Institution

Complete notes on Class notes C Program /Data structure Tutorials by professor Jenny from Jenny's Lectures CS IT. It is an in detail class notes of DSA classes about C program

Preview 1 out of 1  pages

  • April 28, 2023
  • 1
  • 2018/2019
  • Class notes
  • Dr. jenny
  • All classes
avatar-seller
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).

The benefits of buying summaries with Stuvia:

Guaranteed quality through customer reviews

Guaranteed quality through customer reviews

Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.

Quick and easy check-out

Quick and easy check-out

You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.

Focus on what matters

Focus on what matters

Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!

Frequently asked questions

What do I get when I buy this document?

You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.

Satisfaction guarantee: how does it work?

Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.

Who am I buying these notes from?

Stuvia is a marketplace, so you are not buying this document from us, but from seller rohitarjunraj. Stuvia facilitates payment to the seller.

Will I be stuck with a subscription?

No, you only buy these notes for $7.99. You're not tied to anything after your purchase.

Can Stuvia be trusted?

4.6 stars on Google & Trustpilot (+1000 reviews)

83225 documents were sold in the last 30 days

Founded in 2010, the go-to place to buy study notes for 14 years now

Start selling
$7.99
  • (0)
  Add to cart