Array Data Structure

An array is a collection of similar types of elements arranged in contiguous memory allocation. An array is a compartment that can hold a fixed number of items, all of which must be of the same type. The majority of data structures use arrays to adopt their algorithms. The following are key terms to comprehend the notion of Array.

(i) Element – An element is any item that is stored in an array.

(ii) Index – Each element in an extensive range has an arithmetical index that serves to identify the aspect.

Basic Operations on array

Following are the basic operations supported by an array.

  • Traverse − print all the array elements one by one.
  • Insertion − Adds an element at the given index.
  • Deletion − Deletes an element at the given index.
  • Search − Searches an element using the given index or by the value.
  • Update − Updates an element at the given index.

Traverse – This operation is used to iterate over the parts of an array.

C program –

#include <stdio.h>
main() {
   int A[] = {1,3,5,7,8};
   int c = 12, k = 3, n = 7;
   int i = 0, j = n;   
   printf("The original array elements are :\n");
   for(i = 0; i<n; i++) {
      printf("A[%d] = %d \n", i, A[i]);
   }
}

Insertion – The insert operation is used to add one or more attribute values to an array. A feature can be inserted at the end, or even any given indicators of the array depending on the requirement.

C program –

#include <stdio.h>

main() {
   int A[] = {1,3,5,7,8};
   int item = 10, k = 3, n = 7;
   int i = 0, j = n;
   
   printf("The original array elements are :\n");

   for(i = 0; i<n; i++) {
      printf("A[%d] = %d \n", i, A[i]);
   }

   n = n + 1;
	
   while( j >= k) {
A[j+1] = A[j];
      j = j - 1;
   }

A[k] = item;

   printf("The array elements after insertion :\n");

   for(i = 0; i<n; i++) {
      printf("A[%d] = %d \n", i, A[i]);
   }
}

Deletion – It pertains to the removal of respective elements from the array.

#include <stdio.h>

void main() {
   int A[] = {1,9,11,17,18};
   int k = 9, n = 11;
   int i, j;
   
   printf("The original array elements are :\n");
	
   for(i = 0; i<n; i++) {
      printf("A[%d] = %d \n", i, A[i]);
   }
    
   j = k;
	
   while( j < n) {
A[j-1] = A[j];
      j = j + 1;
   }
	
   n = n -1;
   
   printf("The array elements after deletion :\n");
	
   for(i = 0; i<n; i++) {
      printf("A[%d] = %d \n", i, A[i]);
   }
}

Searching – You can search for arrays using either its value or rather its index.

#include <stdio.h>

void main() {
   int A[] = {1,3,5,7,8};
   int item = 5, n = 5;
   int i = 0, j = 0;
   
   printf("The original array elements are :\n");
	
   for(i = 0; i<n; i++) {
      printf("A[%d] = %d \n", i, A[i]);
   }
    
   while( j < n){
      if( A[j] == item ) {
         break;
      }
		
      j = j + 1;
   }
	
   printf("Found element %d at position %d\n", item, j+1);
}

Update – The refresh operation refers to adjusting an existing array element at a given index.

#include <stdio.h>

void main() {
   int A[] = {1,3,5,7,8};
   int k = 3, n = 5, item = 10;
   int i, j;
   
   printf("The original array elements are :\n");
	
   for(i = 0; i<n; i++) {
      printf("A[%d] = %d \n", i, A[i]);
   }
    
   LA[k-1] = item;

   printf("The array elements after updation :\n");
	
   for(i = 0; i<n; i++) {
      printf("A[%d] = %d \n", i, A[i]);
   }
}

0

39 thoughts on “Array Data Structure”

  1. Hi there, I found your website by means of Google whilst searching for
    a comparable matter, your site came up, it appears to be like
    great. I have bookmarked it in my google bookmarks.

    Hello there, just became alert to your weblog via Google, and located
    that it is truly informative. I am gonna watch out for brussels.
    I’ll appreciate should you proceed this in future. A lot of other people will be benefited out of your writing.
    Cheers!

    0
  2. I as well as my friends came following the nice tips from your website then suddenly I got a horrible suspicion I had not expressed respect to the website owner for those tips. My guys are already consequently joyful to read them and now have without a doubt been enjoying these things. I appreciate you for turning out to be simply helpful and for pick out varieties of smart themes most people are really desirous to understand about. Our sincere regret for not saying thanks to sooner.

    0
  3. I have been surfing on-line more than 3 hours as of late,
    yet I never discovered any interesting article like yours.
    It is pretty worth sufficient for me. In my view, if all webmasters and bloggers made excellent content material as you did, the web
    might be much more useful than ever before.

    0
  4. You can definitely see your enthusiasm in the paintings you write. The world hopes for even more passionate writers such as you who are not afraid to mention how they believe. All the time follow your heart. “No man should marry until he has studied anatomy and dissected at least one woman.” by Honore’ de Balzac.

    0
  5. Thanks so much for giving everyone an extremely brilliant possiblity to read in detail from this blog. It is usually very superb and also stuffed with a good time for me personally and my office friends to search your site really three times every week to read through the latest tips you have got. And lastly, I’m also certainly pleased with the good creative ideas you serve. Certain 1 ideas on this page are undeniably the most suitable we have had.

    0
  6. Hey very cool website!! Man .. Excellent .. Amazing .. I’ll bookmark your website and take the feeds also…I am happy to find numerous useful info here in the post, we need work out more techniques in this regard, thanks for sharing. . . . . .

    0
  7. Hey I am so delighted I found your weblog, I really
    found you by error, while I was researching on Askjeeve for something else, Nonetheless I am
    here now and would just like to say kudos for
    a remarkable post and a all round thrilling blog (I also love the theme/design),
    I don’t have time to browse it all at the minute but I have saved it
    and also included your RSS feeds, so when I have time I will
    be back to read a lot more, Please do keep up the excellent jo.

    0
  8. Do you have a spam issue on this website; I also am a blogger, and I was wondering your situation; we have created some nice methods and we are looking to exchange techniques with other folks, be sure to shoot me an e-mail if interested.

    0
  9. I was wondering if you ever thought of changing the page layout of your blog?
    Its very well written; I love what youve got to
    say. But maybe you could a little more in the way of content so people
    could connect with it better. Youve got an awful lot of text for only having 1
    or two pictures. Maybe you could space it out better?

    0
  10. Good day! This is kind of off topic but I need some help from an established blog.
    Is it very hard to set up your own blog?
    I’m not very techincal but I can figure things out pretty fast.
    I’m thinking about making my own but I’m not sure where to start.
    Do you have any points or suggestions? Cheers

    0
  11. I was curious if you ever thought of changing the structure of your site?
    Its very well written; I love what youve got to say. But maybe you could a little more in the way of content so people could
    connect with it better. Youve got an awful lot of text for only having one or 2 pictures.
    Maybe you could space it out better?

    0
  12. It’s in fact very complicated in this full of activity life to listen news on Television, so I just use internet for that purpose,
    and obtain the hottest information.

    0
  13. It’s a pity you don’t have a donate button! I’d definitely donate to this fantastic blog! I guess for now i’ll settle for book-marking and adding your RSS feed to my Google account. I look forward to fresh updates and will share this blog with my Facebook group. Talk soon!

    0
  14. What i do not realize is in truth how you are not actually a lot more neatly-appreciated than you might be right now. You’re very intelligent. You already know therefore considerably when it comes to this matter, made me for my part imagine it from so many various angles. Its like men and women are not interested unless it is one thing to accomplish with Lady gaga! Your own stuffs outstanding. Always take care of it up!

    0
  15. I have been surfing online more than three hours lately, but I never found any attention-grabbing article like yours. It?¦s beautiful price sufficient for me. Personally, if all webmasters and bloggers made just right content material as you probably did, the internet shall be much more useful than ever before.

    0
  16. I am curious to find out what blog platform you have been utilizing? I’m having some minor security issues with my latest website and I’d like to find something more safeguarded. Do you have any recommendations?

    0
  17. We are a group of volunteers and opening a new scheme in our community. Your web site provided us with valuable info to work on. You have done a formidable job and our whole community will be thankful to you.

    0
  18. Hello this is kind of of off topic but I was wanting to know if blogs use WYSIWYG editors or if
    you have to manually code with HTML. I’m starting a blog soon but have no
    coding know-how so I wanted to get guidance from someone with experience.

    Any help would be enormously appreciated!

    0

Leave a Comment

Your email address will not be published. Required fields are marked *