Sunteți pe pagina 1din 1

ARRAY NOTES

Array - An Array is a collection of variables (elements) of the same type that are referenced by a
common name. It is a set of contiguous block of memory locations having a single name and data
type. Each individual memory location contained in the array is referred to as its element.
Array can be of 2 types, Single-Dimensional & Double-Dimensional array.

Array element – An Array is a set of contiguous block of memory locations having a single name
and data type. Each of these individual memory locations is called array element. Each element
of an array can be referred by the array name with the subscript (index no.) enclosed in square
brackets representing the position of the element in the array. The array subscript always starts
with zero.

2 types of Searching technique —


Linear / Sequential Search – Linear search is used to scan the array in a sequential manner. In
this type of searching technique, each and every element of the array is compared with the
item to be searched, one by one sequentially, until it is found or all elements have been
compared.

Binary Search – Binary Search is a searching technique that works on sorted array and uses
the “divide and conquer” method to search an item in the array. It repeatedly divides the
array into two pieces and focuses on the piece that could contain the target value. [Here the
item to be searched is compared with the middle element of the array. If the match found,
search is finished. If search-item is lesser than middle element (in ascending array), it
performs binary search in the first half of the array, otherwise performs binary search in
the latter half of the array.]

Difference between Binary Search & Linear Search -


Binary Search Linear / Sequential Search
This method uses the “divide & conquer” This method compares the value of each
method to repeatedly divide the array into two element of the array with the search key until
pieces and perform the searches for the search it is found or the end of the array is reached.
key on the piece that could contain the target
value.
It can work only on sorted arrays. It can work on both sorted & unsorted arrays.
Binary search is faster & more efficient than Linear search is slower than the Binary search.
the Linear search.

Bubble Sort - This sort method is based on comparing and exchanging pairs of adjacent
elements, until all the elements in an array are sorted. Assuming that the array elements are
arranged vertically, the largest item bubbles up to the top of an array (for ascending order). The
algorithm begins by comparing the bottom-most element with its adjacent element and an
exchange of two elements takes place only then if bottom element is higher than the adjacent
element. After one pass (one round of scanning through the set of elements) leaving the last
element, the remaining elements are scanned to find the next highest element. This continues till
the array is sorted.

Selection Sort - In this sorting technique, from all the elements of the array it searches the
smallest element (for ascending order) and that element is exchanged with the first element of
the array. Next, the second smallest element is searched from in the rest of the elements and
exchanged with the second element of the array and so on.

S-ar putea să vă placă și