Arrays

of 6

this gives you a total concept of arrays go through it you ll be done wd arrays ..all the best guys

Content

Arrays

1 of 6

https://campuscommune.tcs.com/communities/aspire-2016/content/arr...

CC Home (/home)

My Channels (/channels/my_channels)

Image Gallery (/image_gallery)

ExOP (/job_posts)

My Profile (/users/ct20131052920)

People (/users)

Logout (/logout)

Chapter 3: Basic Data Structures

Problem Solving - All Chapters (/communities/aspire-2016/course/problem-solving-6)
(/communities/aspire2016/aspire_dashboard)
Index
3.1.Introduction (/communities/aspire-2016/content/introduction-37)
3.2.Arrays (/communities/aspire-2016/content/arrays-6)
3.4.Stack (/communities/aspire-2016/content/stack-4)
3.5.Queue (/communities/aspire-2016/content/queue-4)
Go to Doubts

3.2. Arrays
Single Dimensional Array
An array data structure stores a number of elements of same kind in a specific order. Array elements are
accessed using an integer (subscript) to specify which element is required (although the elements may be of
almost any type). Arrays may be expandable or fixed-length. Let us consider some real world examples for
arrays.
Example 1
Most squash clubs operate a squash ladder (similarly chess clubs). This is physically a card with numbered
slits in. Each member of the ladder writes their name on a tabbed card that fits into the slots (as shown in Fig:
3.1). If you play someone higher than you on the ladder and beat them, you swap places, the aim being to be
the person at the top of the ladder. The labels on the slits thus give each player their current rank in the club.

The squash ladder is an array structure. All the entries are of the same kind: they are all names of squash
players. Each position is numerically labeled, so you can easily ask questions such as, who the current No 1 is
or who is three positions higher than me? The ladder also has a predetermined number of positions. If there

20-04-2016 13:29

Arrays

2 of 6

https://campuscommune.tcs.com/communities/aspire-2016/content/arr...

are more people wishing to be on the ladder than there are slots, a waiting list may be set up, or a second
(division) ladder may be created, but the original physical ladder cannot have new slots added as there is no
space. When a new person arrives who is known to be good, a new slot cannot be created in the middle of the
ladder to start them in a position close to their correct one. The best that could be done if this were required is
to shuffle each player down one position to create a gap. This would be time-consuming.
Example 2
At sports events such as ice-skating (gymnastics and boxing are similar), marks are awarded by a panel of
judges. The judges sit in a line of seats, with the seat labeled by their country. Before technology took over, the
judges would hold up cards with their scores. On the television screen each skater's scores are given in a row,
again with the marks. This is another example of an array- a fixed size list of things of interest (such as scores)
each with a label to identify them (such as the country).

In ice skating scores, the "things" are thus numbers and the labels are letter pairs that indicate the countries of
the judges (as shown in Fig: 3.2).
Example 3
A row of houses down one side of a street is also organized like an array. Each house is labeled by its postal
address: for example 1, 3, 5, 7, etc. assuming it is on the even side of the street in Hyderabad. When a
postman has a letter to deliver, they know where it goes from the number. The number is just a label; the actual
house is the thing it is labeling. In normal circumstances, new houses are not added in the middle. Once your
house is given a number, it is not changed.
A one-dimensional array such as the examples above is in many ways similar to a list. The difference is that
arrays are of fixed sizes, with each cell "named" by a subscript. An array consists of a fixed number of slots,
that things can be put in or taken out of. New slots cannot however be created. Since each element in the array
is referenced by a single subscript, it is called as one-dimensional array. The below example (Figure : 3.3) tells
how a list of marks scored by 10 students in one subject is represented by a one-dimensional array.

here, the name of the array is "marks". All the elements inside it are integers representing the marks of the
students. Usually an array is indexed as zero-based indexing; i.e. the first element of the array is indexed by
subscript of 0. In the above example (Figure : 3.3),
marks[0] represents the marks obtained by the first student i.e., 70
marks[1] represents the marks obtained by the second student i.e., 30
.
.
marks[9] represents the marks obtained by the 10th student i.e., 45
Multi-dimensional arrays
In addition to one-dimensional arrays, we also have two-dimensional and three-dimensional arrays where the
elements are pointed by two and three subscripts respectively. These will come under the category of Multidimensional arrays, since we require multiple subscripts to refer an element in them.
Two-dimensional arrays
A two-dimensional array data structure stores the elements in a rectangular form i.e., in rows and columns. See
the below real world example (Figure : 3.4).

20-04-2016 13:29

Arrays

3 of 6

https://campuscommune.tcs.com/communities/aspire-2016/content/arr...

If you observe the seating arrangement in a cinema theatre, you will find the seats arranged in rows and
columns. Here, a row is a horizontal list of elements i.e., seats in this example and a column is a vertical list of
elements. To address a seat, we need its row number i.e., in which row it is and it's column number i.e., in
which column it is present.
Example 1
Observe this time table of 10th class examinations.(Figure : 3.5).

Here, 12 different subject's dates are mentioned. In each row, we have two columns for "Date of examination"
and "subject name". One row is providing a date on which test for a specific subject is going to be conducted.
Like this, we have the details for 12 subjects in 12 different rows.
Example 2
The below example represents the monthly sales report of a particular company in four different countries India,
US, Germany and UK (Figure : 3.6).

20-04-2016 13:29

Arrays

4 of 6

https://campuscommune.tcs.com/communities/aspire-2016/content/arr...

Here, rows are representing the "months" and columns are representing the "countries". i.e.,
column[0] - India
column[1] - US
column[2] - Germany
column[3] - UK
and
row[0] - January
.
.
.
row[11] - December
sales[0][0] represents sales made in India (country) in the month of January (month).
sales[2][1] represents sales made in US (country) in the month of March (month) etc.,
http://courses.cs.vt.edu/~csonline/Algorithms/Lessons/SelectionCardSort/index.html
/~csonline/Algorithms/Lessons/SelectionCardSort/index.html)

(http://courses.cs.vt.edu

http://www.ee.ryerson.ca/~courses/coe428/sorting/selectionsort.html
/coe428/sorting/selectionsort.html)

(http://www.ee.ryerson.ca/~courses

http://www.ee.ryerson.ca/~courses/coe428/sorting/exchangesort.html
/coe428/sorting/exchangesort.html)

(http://www.ee.ryerson.ca/~courses

http://www.ee.ryerson.ca/~courses/coe428/sorting/bubblesort.html (http://www.ee.ryerson.ca/~courses/coe428
/sorting/bubblesort.html")
http://algs4.cs.princeton.edu/23quicksort/ (http://algs4.cs.princeton.edu/23quicksort/)

Related Videos:

20-04-2016 13:29

Arrays

5 of 6

https://campuscommune.tcs.com/communities/aspire-2016/content/arr...

Previous
Introduction
(/communities/aspire-2016/content/introduction-37) (/communities/aspire-2016/content/introduction-37)
Next

20-04-2016 13:29

Arrays

6 of 6

https://campuscommune.tcs.com/communities/aspire-2016/content/arr...

Misuse of 'Ask a Doubt' Section will be dealt as per the Terms & Conditions of Campus Commune
Note: Please do not use the doubts section for any quiz/quiz-content related queries.
Use the helpline (/feedbacks/new) ( ) located above in top right corner for problems/queries related to
quizzes.

Characters (including HTML): 0

Submit

Open Doubts

Closed Doubts

My Doubts

Souvik Chanda (/users/ct20131048480) • about 16 days ago
For insertion and deletion, how will be the array elements will be shuffled?

Preeti Kumari (/users/ct20141176532) • about 1 month ago

20-04-2016 13:29

Recommended

Arrays

Or use your account on DocShare.tips

Hide