asked 19.6k views
4 votes
Suppose an array has n elements. we visit element #1 one time, element #2 two times, element #3 three times, and so forth. how many total visits will there be?

1 Answer

6 votes
The number of visits is an arithmetic sequence.
There are ' n ' terms. They're just the counting numbers from 1 to 'n' .
The first term is 1, the second term is 2, ... , the last term is 'n' .

The formula for finding the sum of an arithmetic sequence is

Sum = n (first term + last term)/2 .

This formula is indicating that the sum of the arithmetic sequence
is just equal to the average of the first and last term, multiplied by
the number of terms.

So the number of visits is

n (1 + n)/2 .
answered
User Nili
by
8.6k points
Welcome to Qamnty — a place to ask, share, and grow together. Join our community and get real answers from real people.