Two Way Linear Search Algorithm: International Journal of Computer Applications December 2014
Two Way Linear Search Algorithm: International Journal of Computer Applications December 2014
net/publication/284494241
CITATIONS READS
11 7,156
3 authors, including:
Nitin Arora
Indian Institute of Technology Roorkee
63 PUBLICATIONS 179 CITATIONS
SEE PROFILE
Some of the authors of this publication are also working on these related projects:
An Efficient System for Early Diagnosis of Breast Cancer using Support Vector Machine View project
All content following this page was uploaded by Nitin Arora on 20 February 2019.
ABSTRACT the array and if the element has been found, if will display the
Linear search is the basic search algorithm used in data particular element and the index value of that element in that
structures. If is also called as sequential search. Linear search array[4].
is used to find a particular element in an array. It is not If we declare an array of size 8 and we initialize the array with
compulsory to arrange an array in any order (Ascending or the values (either static or dynamic declaration of values). In
Descending) as in the case of binary search. Linear search that if we mention the particular element to be identified, then
starts by sequentially scanning the elements in the array and if the two way linear search will start to search the array from
the element has been found, if will display the particular the index 0. If the value is found at its first position itself, then
element and the index value of that element in that array. In it will return the value. If the value is not found, the search
this paper we present a novel searching algorithm Two Way will increment the index value by 1 and then check the
Linear Search, which modified version of linear search element. This process continues till the element has been
algorithm and is based on comparing the elements from both identified.
ends.We have also compared the Two Way Linear search
algorithm with Linear Search Algorithm. We used MATLAB Algorithm LinearSearch(x, L, n)
8.0 for implementation and Analysis of CPU time taken by Input: Array L, value x, and number n of elements in L
both the algorithms. We have checked the algorithms
with input sequences of lengths10000, 50000, 100000, Output: Position i, 0 ≤ i < n such that L[i] = x, or −1 if x does
and 5000000.Result shows that Two Way Searching not belongs to L
Algorithm is working well for all input values and it takes
1. i←0
lesser time if the element to be search is after the middle of
the array, otherwise it takes same time as in case of linear 2. while (i < n) and (L[i] 6= x)
search. 3. do
4. i←i + 1 //end while
Keywords 5. if i < n thenreturn i
Searching, Algorithms, Linear Search, Two Way Linear 6. elsereturn -1
Search.
3. TWO WAY LINEAR SEARCH
1. INTRODUCTION ALGORITHM
An iterator traverses sequentially the array from left to right. In Two Way Linear Search we initialize the array with the
When it encounters an element which is equal to the key the values (either static or dynamic declaration of values). In that
search stops and the index of that element is returned. If the if we mention the particular element to be identified, then the
key is not present in the array the size of the array will be two way linear search will start to search the array from the
returned. Linear search is the basic search algorithm used in index 0 as well as from the index n-1. If the value is found at
data structures [1]. If is also called as sequential search. its position from the left or from the right, then it will return 1.
Linear search is used to find a particular element in an array. If the values is not found the value returned is -1.
It is not compulsory to arrange an array in any order
(Ascending or Descending) as in the case of binary search. Algorithm TwoWayLinearSearch(A, num, n)
Linear search starts by sequentially scanning the elements in Input: Array A, value num to be search and n total number n
the array and if the element has been found, if will display the elements in A
particular element and the index value of that element in that
array[2][3]. Output: 1 if num belongs to A, or -1 if num does not belongs
A
Rest of the paper is organized as follows: section 2 describes
the Related work in this we have discussed Linear search 1. p ← 0;
algorithm. Section 3 describes our new Two Way Linear 2. q ← n-1;
Search algorithm. Proof of correctness for Two Way Linear
Search is described in section 4 and comparison between 3. a ← 0;
Linear Search and Two Way Linear Search is described in
4. while (p<q)
section 5. Followed by conclusion and future scope in section
6, acknowledgement in section 7 and used references are 5. do
described in section 8.
6. if (L[p] ≠ x or L[q] ≠ x)
2. RELATED WORK 7. then p ← p + 1; q ← q - 1; a ← 0;
Linear search is used to find a particular element in an array.
It is not compulsory to arrange an array in any order 8. else
(Ascending or Descending) as in the case of binary search.
9. then a ← 1; //end while;
Linear search starts by sequentially scanning the elements in
6
International Journal of Computer Applications (0975 – 8887)
Volume 107 – No. 21, December 2014
6. CONCLUSION AND FUTURE SCOPE [4] Frank M.C. (2004) Data Abstraction and Problem
Searching is a technique that is used to find a particular Solving with C++. US: Pearson Education, Inc.
element in an array. In Linear Search it is not compulsory to [5] Cormen T.H., Leiserson C.E., Rivest R.L. and Stein C.
arrange an array in any order (Ascending or Descending) as in (2003) Introduction to Algorithms MIT Press,
the case of binary search orderly. Result shows that new Two Cambridge, MA, 2nd edition.
Way Searching Algorithm is working well for all input values
and it takes lesser time if the element to be search is after the [6] Seymour Lipschutz (2009) Data Structure with C,
middle of the array, otherwise it takes same time as in case of Schaum Series, Tata McGraw-Hill Education.
linear search.
9. ABOUT THE AUTHORS
7. ACKNOWLEDGEMENT Nitin Arora received B. Tech. (Computer Science &
This research paper is made possible through the help and Engineering) from MNNIT Allahabad in 2008 and M. Tech.
support from everyone, including: Dr. Sandeep Goel (Computer Science & Engineering) from Govind Ballabh Pant
(Director WIT), all the faculty members of Computer Science Engineering College, Pauri, Garhwal, Uttarakhand in 2012.
& Engineering Department, all the students and friends. He is the member of IANEG (USA), ISOC (USA) and
Especially, we would like to give extremely thanks to our IACSIT (USA) and has published over several research
family because without their support this work was not papers in National and International journals/conferences
possible. in the field of Mobile Ad-Hoc Networks, Data Structures
and Algorithms. He started his career as a Lecturer from
8. REFERENCES Shobhit Institute of Engineering and Technology,
[1] Arora, N., Tamta, V., and Kumar S. 2012. A Novel Saharanpur and later on promoted as an Assistant
Sorting Algorithm and Comparison with Bubble Sort and Professor in the Department of Computer Science &
Selection Sort. International Journal of Computer Engineering at Women Institute of Technology (WIT)
Applications. Vol 45. No 1. 31-32 Constituent college of Uttarakhand Technical University
(UTU), Dehradun. He qualified National Eligibility Test
[2] Herbert Schildt Tata McGraw-Hill [2005], “The (NET) in Computer & Application in June – 2012.
Complete Reference C fourth Edition”.
Garima Bhasin received Diploma in Computer Science &
[3] Alfred V., Aho J., Horroroft, Jeffrey D.U. (2002) Data Engineering from Government Polytechnic Dehradun and
Structures and Algorithms. currently pursuing B. Tech in Computer Science &
Engineering from Women Institute of Technology, a
7
International Journal of Computer Applications (0975 – 8887)
Volume 107 – No. 21, December 2014
Constituent College of Uttarakhand Technical University, currently pursuing B. Tech in Computer Science &
Dehradun. Her area of interest includes C, C++, .Net, Java, Engineering from Women Institute of Technology, a
Database and Data structures and Algorithms. constituent Institute of Uttarakhand Technical University,
Dehradun. Her area of interest includes Computer
Neha Sharma received Diploma in Computer Science & Networking, .NET and Java.
Engineering from Government Polytechnic Dehradun and
IJCATM : www.ijcaonline.org
8