Professional Documents
Culture Documents
2. Arrays (4)
2. Arrays (4)
1
Operation on Arrays
2
Insertion
3
Insertion : Algorithm
• LA is a linear array with N elements and K is a positive integer. Following
algorithm inserts new element ITEM at Kth position in LA.
• Exit
4
Deletion
5
Deletion: Algorithm
• This method finds out whether the data entered by the user
is present in an array or not.
• There are two searching method:
7
Search: Linear Search
• It compares each element with the value being searched for and stops
when that value is found or the end of the array is reached.
8
Algorithm steps
Given array A containing N elements. This algorithm search an Item with location
LOC. If Item is not there in A then it return unsuccessful search.
4. If LOC==-1 then
Item not found
else
Item= A[LOC] // return item
5.Exit
Algorithm Efficiency
• The binary search is much more efficient than the linear search.
6. Exit
Which search method is better
• Linear Search is slower, inefficient and works on unsorted list. If
the data we are searching is not present in the list, we come to
know at the end of the operation.
• The advantage of Binary search is that each search cuts the list in
to half. A list of 10,000 names can be searched in just 12 searches.
13