Question

In: Computer Science

please summarize the basic concept of how data can be contained and manipulated effectively in an...

please summarize the basic concept of how data can be contained and manipulated effectively in an array

Solutions

Expert Solution

Here is the solution. Please do upvote thank you.

An array is defined to be an index sequence of values of the same type.

So here's an example of an array, it's 52 playing cards in a deck. That's the example that we're going to work with for a lot here So, some cards in the first position, other cards in the second position, the ace of hearts in the third position, and so forth.

Given an index then we can immediately get to the card that's in that position in the deck. But there's many other ideas where you might use an array.

So, you might have a lot of students in an online class, and again, you can get to each one quickly through an index. We're going to look at digital images. There might be a billion pixels in a digital image, and we want to be able to quickly get to each one of them. Or Biologists studying DNA, there might be nucleotides in the DNA strand. Many other examples showing that you've got data, elements of the same type, and you have a huge amount of them, and you need to structure them so that you can process them efficiently.

Syntax

Data type arrayname[ranger] ;

Example

int student_marks 100];

So, our main purpose of the array is to facilitate the storage and the manipulation of this kind of data. So, what does it mean about processing many values of the same type? So here's an example that we could write without using arrays at all. In this case, maybe we have 10 items of data, and we just named them a zero through a nine. If we want to refer to the fifth one, we can say a4 equals 3.0, or the ninth one a8 equals 8.0, and so forth, and even use them in arithmetic expressions. Now, but after a while, you can see that it would be very tedious and error-prone to have code of this sort.

A much simpler way to do it, is using an array. Instead of declaring all those things of the same type separately, we just declare in one statement that we're going to access Then if we want to refer to the fifth one, we just put that index inside square brackets, or the eighth one whichever one we want, and we can use those that array name followed by an index in square brackets just the same way we use any other variable of that type.

int r=student_marks [6];

Since they're all the same type, the compiler can keep track of them and check the type. That's convenient enough with 10 values, but what this does immediately, is it scales say to a million values. We have a huge amount of data. It would be indeed tedious to give them each one of them a different name. With an array, we have the shorthand where we just use the brackets to refer to individual pieces of the data. It scales to handle huge amounts of data.

A simple example of manipulating data in an array of n elements. Increase every element in array by 4.

for (int i=0;i<n;i++)

{

student_marks[i] +=4;

}


Related Solutions

How can marketers reach the Millennials effectively?
How can marketers reach the Millennials effectively?
In a short summary, please explain how governments can effectively protect businesses in the cryptomarkets so...
In a short summary, please explain how governments can effectively protect businesses in the cryptomarkets so that they are not subject to high levels of speculation. Explain with your knowledge of government regulations regarding currencies.
discuss how nurses can assist in effectively managing patient care within an evolving health system? please...
discuss how nurses can assist in effectively managing patient care within an evolving health system? please give references
Please explain the basic characteristics of preferred stock, warrants, and convertible debt, how these can be...
Please explain the basic characteristics of preferred stock, warrants, and convertible debt, how these can be viewed as providing both a comparable basic investment and an option, and how these additions or benefits impact the cost of capital for the issuing company.
How can addictions be stressful? Please relate the concept of screen addictions to the bigger problem...
How can addictions be stressful? Please relate the concept of screen addictions to the bigger problem of stress and addictions.
Indentify and summarize the basic elements of expectancy theory and discuss how they relate to one...
Indentify and summarize the basic elements of expectancy theory and discuss how they relate to one another
how can a company manage information on specfic customers more effectively .
how can a company manage information on specfic customers more effectively .
Shortly explain how you can determine if a company is effectively using leverage?
Shortly explain how you can determine if a company is effectively using leverage?
Discuss the process of negotiation and how sales force members can use it effectively.
Discuss the process of negotiation and how sales force members can use it effectively.
describe the basic concept of biological evolution and apply it to examples (for instance, how giraffes...
describe the basic concept of biological evolution and apply it to examples (for instance, how giraffes could have evolved a long neck)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT