Sunteți pe pagina 1din 4

P Surendra Varma et al, International Journal of Research in computer ISSN (Online) 2278- 5841

and communication Technology , Vol 6, Issue- 3,March- 2017


ISSN (Print) 2320- 5156

SPRY Search - A Novel Algorithm

1*
P Surendra Varma, 2P.P.N.G Phani Kumar, 3B.H.V.S Narayana, 4D.V.S Ravi Varma
1,2,3,4
Asst. Professor
1,2,3,4
Dept. Of CSE, Raghu Engg. College

ABSTRACT II. PROPOSED PROCEDURE


Since the inception of algorithms, various Spry Search Algorithm assumes the data to be
searching procedures have already been developed to sorted before beginning the actual search procedure
sort a given list of values. Most of these algorithms and works best when the data is uniform(list of values
perform the searching procedure based on the index of with equal difference between them). But how does it
the integer array in which these values are stored. select the next data value to be compared with the
When the value at a particular index of the array does key?
not match with the key value, we move on to one more This selection is based on the equations given below:
index and compare the value at that particular index.
For any searching procedure we keep on selecting new acd = (element at index low + element at index
indices until we find the key element, but the only high) / (low +high)
difference is in the method of selecting the new index.
The time complexity of an algorithm depends New Index = key / acd
on the procedure by which we select the new index.
Efficient selection of the index value reduces the Where low and high are the starting and ending
complexity of an algorithm. Spry Search (Spry, a indices of the array respectively.
synonym of quick) focuses on efficient procedure to Variable acd represents Approximate Common
select the new index value, thereby results in finding Difference.
the key value at a faster rate. What are we actually trying to do by applying
these two equations? We are trying to find the
Key words- index, key based, array. approximate position of key value based on first and
last element of the array.
I. INTRODUCTION How does it Work? Consider the train
There are already many existing procedures coaches at a railway platform. You have a ticket
to perform searching. One of them searches the list reserved in Coach S6. You are at present 100 meters
sequentially. i.e., it selects the first element of the list, behind Coach S1 and 900 meters behind Coach S9. So
checks whether it is the required key value. If yes, the how many meters do you need to walk to reach your
problem is solved and the procedure terminates, Coach S6? 600 meters, Isnt it?.
otherwise select the next element of the list, repeat the How did we get 600? We get 600 from the two
same process until the required key value is found. calculations shown below:
On the other hand, there are various searching (100 + 900) / (1+9) = 100
algorithms which require the data to be sorted before 100 * 6 = 600.
the actual searching procedure begins. Then the idea is We implemented the same procedure in the form of
to compare the middle element of the list with the key. two equations shown above.
If the key is found, the procedure terminates, You are exactly 600 meters behind your required
otherwise we check if the key is lesser or greater than coach S6 provided:
the middle element. If it is greater, we search half of All the coach numbers are sorted
the list which is greater than this list, else if it is lesser, The length of all the coaches is same.
we search the other half. Typically, you would not assume one coach to be 100
In this way whenever the key value is not meters and the other to be 50 meters.
found, the further processing is done only on half of
the present list. So the list gets reduced to half every Applying the same two conditions:
time the key is not found. Here the basic idea is, the We already said that this searching algorithm
searching time reduces recursively just because the list operates only on sorted data. So the first
is halved every time. assumption is done.

www.ijrcct.org | *Corresponding Author 66


P Surendra Varma et al, International Journal of Research in computer ISSN (Online) 2278- 5841
and communication Technology , Vol 6, Issue- 3,March- 2017
ISSN (Print) 2320- 5156

Difference between the data need not be }


uniform in all the cases. When the length of
all the coaches is not the same, after walking In the program, we have used the statement
for 600 meters you would reach coach s6 or iteration++ to find out how many passes this
some other coach which is definitely nearer to algorithm takes to search for key value. The value of
the required S6. So you need not walk more variable iteration is incremented for every pass
to reach S6, it would be somewhere nearby. starting with 1.
The same concept applies to the list of data
values. When the data is not uniform, we V. ANALYSIS:
might reach a value which is nearer to the key While analyzing spry search, every time we
value. So we again start searching from there. try to find the new index value, we move nearer to the
As we are already nearer to the key value. required key value, but by how much nearer? It takes
This might not take much time to reach the us nearer to the key such that half of the unwanted
key value. array values are discarded every time.
To understand this, let us consider we have
III. ALGORITHM 32 values in the array. For the 1st pass of the algorithm
1. Consider indices of the array start from 1. At the array values are reduced to half if the key element
the start of algorithm, low = 1 and high is is not found. So now we are left with only 16 values.
the number of elements in the given list, Similarly for 2nd pass the array values are reduced by
key is the value to be searched. half again, so only 8 are left. And the process
2. Find the new index based on the below two continues until we find the required key value.
equations: There is a mathematical function present
a. acd = (element at index low + which can be represented for halving a particular value
element at index high) / (low every time. The function is a logarithmic function. A
+high) logarithmic function with base 2. Base 2 logarithmic
b. new_index = key / acd values of some values are given below:
3. Check whether a[new_index] is equal to the
key value.
a. If it is equal, we found the key 0 log 21
value. So terminate the algorithm
successfully. 1 log 22
b. Else if a[new_index] is less than key
value, then repeat the procedure 2 log 24
from Step 2 with low =
new_index+1. 3 log 28
c. Else repeat the procedure from Step
2 with high = new_index-1 4 log 216

IV. IMPLEMENTATION 5 log 232


int search(int a[],int low, int high, int key)
{ 6 log 264
int index,acd;
acd = (a[low]+a[high])/(low+high); 7 log 2128
index = key/acd;
iteration++; 8 log 2256
printf("\n Pass number: %d, searching at location:
9 log 2512
%d",iteration,index);
if(low>high)
10 log 21024
return 0;
else 20 log 21048576
{
if(a[index]==key) 21 log 22097152
return index;
else if(a[index]<key)
search(a,index+1,high,key); Here are the graphs showing logn vs n:
else
search(a,low,index-1,key);
}

www.ijrcct.org | *Corresponding Author 67


P Surendra Varma et al, International Journal of Research in computer ISSN (Online) 2278- 5841
and communication Technology , Vol 6, Issue- 3,March- 2017
ISSN (Print) 2320- 5156

In the above shown output, the data entered


10, 20, 30, 40, 50, 60 has uniform difference
between each pair of values which is 10. So we could
find the key value only within one pass.

Average Case:
This algorithm doesnt work too good nor
too bad when the data has approximately uniform
difference between each pair of values.

Screenshot for average case scenario:

So the time complexity of this algorithm can be said to


be O(logn).

Best Case: In the above output, look at the difference between


This algorithm works best when the list of each pair of a values. The differences are 9, 9, 7, 14, 6,
elements are uniform i.e. if they have equal difference 15 which are not equal differences and at the same
between each pair of values. time, they are not too unequal differences.
Screenshot for best case scenario: In such a case, we were able to find the key
value within 2 passes.

Worst case:
This algorithm works worst when the
difference between each pair of values is not common
at all i.e, the differences of each pair vary by a large
number.

Screenshot for worst case scenario:

www.ijrcct.org | *Corresponding Author 68


P Surendra Varma et al, International Journal of Research in computer ISSN (Online) 2278- 5841
and communication Technology , Vol 6, Issue- 3,March- 2017
ISSN (Print) 2320- 5156

11.http://www.tutorialspoint.com/data_structures_algo
rithms/interpolation_search_algorithm.htm

12.http://www.tutorialspoint.com/data_structures_algo
rithms/hash_data_structure.htm

13.https://en.wikipedia.org/wiki/Analysis_of_algorith
ms

14. http://discrete.gr/complexity/

15.http://www.cprogramming.com/tutorial/computersc
iencetheory/algorithmicefficiency2. html

16.https://www.cs.utexas.edu/users/djimenez/utsa/cs17
23/lecture2.html

17.https://www.cpp.edu/~ftang/courses/CS240/lecture
s/analysis.htm

In the above output, there is a lot of variation


between the differences which are 28, 9, 4, 30, 24.
They do not appear to be common at all.
In such a case, the algorithm took 3 passes to
locate the key value.

VI. REFERENCES:

1. Data Structure with C, Seymour Lipschutz, TMH

2. Data Structures using C,Reema Thareja, Oxford

3. Data Structures, 2/e, Richard F, Gilberg , Forouzan,


Cengage

4. Data structures and algorithm analysis in C, 2nd ed,


mark allen weiss

5. Data Structures and Algorithms, 2008,G.A.V.Pai,


TMH

6. Classic Data Structures, 2/e, Debasis


,Samanta,PHI,2009

7. Fundamentals of Data Structure in C, 2/e,


Horowitz,Sahni,Anderson Freed,University Press.

8.http://www.tutorialspoint.com/data_structures_algori
thms/algorithms_basics.htm

9.http://www.tutorialspoint.com/data_structures_algori
thms/linear_search_algorithm.htm

10.http://www.tutorialspoint.com/data_structures_algo
rithms/binary_search_algorithm.htm

www.ijrcct.org | *Corresponding Author 69

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