4. WHAT IS ARRAY?
An array is a group of consecutive memory
locations with same name and data type.
The objects in an array are called elements of array.
The total number of elements in an array is called
length.
The element of an array is accessed by its subscript
value or index value.
5. ADVANTAGES OF ARRAYS
Arrays are used to process a large amount of data of
same type.
Arrays are used to reduce the size of program.
Arrays can store many values easily and quickly.
The searches process can be applied on array easily.
7. ONE D-ARRAY
One dimensional array is also called a list or linear
array. It consist of only one column or one row.
For example
the temperature of each hour of a day is
stored in an array. The name of array is “temp” and its
elements are temp[0],temp[1],………….temp[23].
8. DECLARATION OF 1-D ARRAY
Defining the name of array, its types and
total numbers of elements of an array is called
declaring of the array.
Syntax
data type array_name [n];
“n” represents the total number of elements of array.
e.g
Int xyz[5];
9. 1-D ARRAY INITIALIZATION
The process of assigning a values to array element at the
time of array declaration is called initialization of array.
Syntax
data type identifier[n]={list of values};
e.g
int mark[4]={70,56,84,64,23};
int arr[2]={‘p’,’a’,’k’}
Initializing values may be constant or character
type.
10. SEARCHING IN AN ARRAY
The process of finding the required data in array.
Searching become more important when length of
array is very large.
There are two techniques for searching:
1. Sequential search
2. Binary search
11. SEQUENTIAL SEARCH
It is also called linear or serial search. It follow the
following steps to search value:
1. Visit the first element of array and compare its with required value.
2. If the value of array matches with the desired value then search is
complete.
3. If value of array does not match then move to next element and
repeat the same process.
12. BINARY SEARCH
1. It is a quicker method to search value in array. But it can only search
for sorted array. Following steps are used:
2. It locate the middle element of array and compare it with desired
value.
3. If they are equal the search is complete.
4. If they are not equal, it reduce the search half an array.
5. If the required value is less than the middle value then it search for
first middle half otherwise second half.
6. If required number is not found then loop is complete without
successful search.
13. SORTING ARRAYS
The process of arranging the values in a particular
order. An array can be sorted in two ways:
a) Ascending order e.g 23, 34,56,78
b) Descending order e.g 78,56,34,23
14. TECHNIQUE OF SORTING ARRAY
There are two technique of sorting of array
1. Selection sort
2. Bubble sort
15. SELECTION SORT
It is a technique that sort an array. It selects an
element in array and move it to its proper position.
It works as follow:.
1. Find the minimum value in the list.
2. Swap it with value at first position.
3. Sorts the remainder of the list excluding the first value.
16. BUBBLE SORT
It is also known as exchange sort. It repeatedly
visits the array and compare two values at a time.it
works as follow:
1) It compare the adjacent element. If the first is greater
than second, swaps them.
2) Repeat this for each pair of adjacent element, starting
with the first two and ending with last two.
3) Keep repeating for one fewer element each time until
there is no pairs to compare.
17. TWO D-ARRAY
It is considered as table that consist of rows and
columns. Each element in an array is referred with
the help of two indexes. One indicates row and
second column.
19. 2-D INITILIZATION
It can also be initialized at the time of declaration. It
can be performed by assigning the initial values in
braces separated by commas.
Some important points:
1) The elements of each rows are enclosed within the braces
and separated by commas.
2) All rows are enclosed within braces.
3) For number arrays, if all elements are not specified , the un-
specified element are initialized by zero.
20. 2 D ARRAY
for example:
Int arr[4][3]={{12,5,22},
{95,3,41},
{77,6,53}
{84,59,62}}
12 5 22
95 3 41
77 6 53
84 59 62