You are on page 1of 19

Arrays

By: Syed Muhammad Jamal


An Array is a collection of data elements of the same type.

Each element of array have same data type , storage class

What is an and same characteristics.

Array? Each element is stored in successive location of the main

store.

These are known as members of the Array.


An ice cube tray.

Tray is the array


Daily Life
Example:
Cubes in it are elements

Number of cubes in the tray is size of the tray(array)


Array is defined in the same way as a variable Is defined.

Syntax of array definition is

storage_class data_type array_name[size]


Defining an
Example: int marks[6]
Array
Marks is the name of Array.

[6] is the size of array.

Int is the data type.


Two Types of
Simplest form or Array.
Arrays.
It is a type of linear array.
Type one is
Items stored are stored in row from 0 to size of Array.
Single
dimensional One dimensional array consist of single list accessed by single

Array. index number.


Example of
Single
Dimensional
Array
Sometimes data has to be manipulated and stored in tabular

Type two is format or in the form of a matrix.

Multi- In the form of rows and columns data is displayed.

Dimensional- Subjects are listed in columns.

Array Names in rows


Syntax=

Array_arrMARKS[element1][element2]

Syntax of 2-D Array_arrMakrs[3][2]


Array 
Two Pairs of brackets are used in declaration and
length is specified within the square bracket.
Example Of 2-
D Array
 The default way to search for a specific item is to compare item

one by one.
Different
 In this search starts with first element and continues until the
Search
Techniques either element is found or end of the list is searched

1.Sequential Example: A phonebook to look some name.


Search
Will check the first name if found will print the name if not wil

check another name.


Best Search for sorted array.

Powerful item for searching an ordered list.

For Example: Dictionary. In dictionary people don’t start from first

2.Binary page

Search If they are lucky they would find the item

If not then they will have to search again.

In binary search the data is split into two half and middle item
value is compared.
Example of
Binary Search
 In internal sort sorting takes place in main memory of computer

 Data Collection is small accommodated in main memory

 Different Types of Internal sort are


Different Sort
 Selection Sort
Techniques
1.Internal Sort  Quick Sort

 Bubble Sort

 Insertion Sort
Find the minimum value in the list by iterating over whole list
Swap this value with the first value
Repeat these two steps
1.Selection
Sort
Divides the List into two Sub-List.

Pick an element from the list, element is called pivot value.

Reorder the list so that all elements smaller than pivot value
Quick Sort positioned before the pivot value.
Works Repeatedly iterating through a list.
Comparing two elements at a time and swapping them wherever
necessary.

Bubble Sort
Builds final Sorted array (or-list)

One item at a time

Less efficient when the list is large


Insertion Sort
When file size is large and not accommodated by main memory.

Data needs to be stored in external disks.


External
Sorting Sorting With Disks.

Sorting with tapes.


Thankyou

You might also like