(IJCSIS) International Journal of Computer Science and Information Security, Vol. 8, No.

4, July 2010

Multiple Values Bidirectional Square Root Search

Syed Zaki Hassan Kazmi
Department of Computer Science IQRA University Islamabad Campus, Pakistan zaki.mzd@gmail.com

Syeda Shehla Kazmi
Department of Computing & Mathematics Manchester Metropolitan University, United Kingdom shehla_kazmi@hotmail.com

Jamil Ahmad
Department of Computer Science IQRA University Islamabad Campus, Pakistan jamil@iqraisb.edu.pk
Abstract—The research in hand is an effort to introduce a new efficient searching technique known as Multiple Values Bidirectional Square Root Search. In this technique, a sorted list of values can be searched from another sorted list very efficiently. The overall time for sorting the values to be searched and searching is less than the time taken by the Linear Search and Binary Search. In this technique, the size of targeting list is reduced for every next value to be searched. As a result the searching time of remaining values to be searched is reduced, while in linear search and binary search the size of target list remains same for every value to be searched. In other words, we can say that the targeting list is traversed completely each time for every value to be searched from beginning to end. Running Cost analysis and the result obtained after implementation are provided in the graphical form with an objective to compare the efficiency of the technique with linear search as well as binary search, as binary search is consider as an efficient and fast one. Keywords-Searching; Linear Search; Binary Search.

Syeda Sobia Hassan Kazmi
Department of Computer Science University Of Azad Jammu And Kashmir Muzaffarabad A.K, Pakistan fajar_zara@hotmail.com its efficiency. Searching is of considerable importance as the human is possessed in searching the information/knowledge. To search the information efficiently the efficient searching technique is very important. To facilitate the human, computers consume a substantial time in searching the data. This paper is organized as follows; Section II presents a brief review of existing searching algorithms. Section III presents the description of proposed solution. Section IV presents the proposed algorithm. Section V presents Running Cost Analysis. Section VI present comparison between multiple values bidirectional square root search with linear search and binary search. Section VII ends with concluding remarks. II. A BRIEF REVIEW OF EXISTING SEARCHING ALGORITHMS

I.

INTRODUCTION

Algorithms have a vital and key role in solving the computational problems, informally an algorithm is a well defined computational procedure that takes input and produces output. Algorithm is a tool or a sequence of steps to solve the computational problems [1]. In computer science, a searching algorithm, broadly speaking, is an algorithm that finds a particular data from a data set. Searching takes a problem as input and returns a solution to the problem, usually after evaluating a number of possible solutions. Efficient searching is important to optimizing the use of other algorithms (such as sorting algorithms) that require searching the location of new item in sorted list such as in insertion sort. There are a lot of searching techniques, currently used in industry and academia, to find the data of various forms and from different areas. The study in hand proposes a new searching technique that is tested and analyzed against binary search to provide

A number of searching techniques are currently used in the field of computer science. This section will briefly discuss some of the trendy searching techniques among them. These are following: A. Linear Search It is the simplest method to find the particular element in the list. It checks all of the elements in the list and particularly checks in sequence and one at a time to reach the particular value. It is the special case of Brute Force Search. Its worst case cost is proportional to the number of elements in the list. It is O (n) [9]. B. Binary Search “In computer science, a binary search is an algorithm for locating the position of an element in a sorted list. It inspects the middle element of the sorted list: if equal to the sought value, then the position has been found; otherwise, the upper half or lower half is chosen for further searching based on whether the sought value is greater than or less than the middle element. The method reduces the number of elements needed to be checked by a factor of two each time,

157

http://sites.google.com/site/ijcsis/ ISSN 1947-5500

(IJCSIS) International Journal of Computer Science and Information Security, Vol. 8, No. 4, July 2010

and finds the sought value if it exists in the list or if not determines "not present", in logarithmic time. A binary search is a dichotomic divide and conquer search algorithm. Its running time complexity is O(logn)”[5]. III. MULTIPLE VALUES BIDIRECTIONAL SQUARE ROOT SEARCH

IV.

ALGORITHM : PSEUDO CODE

"arr" list of data element and "Data" is the list of value to be search. Multi Values Bidirectional Square Root Search (arr,Data) Sqr:=square root of "len" Len:=length[arr]-1 i:=0 l:=len f:=0 for f = 0; f <length[Data]; f++ { item = data[f]; j = len; temp = i; sqr = square root of "l" while arr[i] != item && arr[j] != item && sqr != 1 { if arr[i] < item && arr[j] > item { i = i + sqr j = j - sqr } else { if arr[i]>item { j=i-1 i = i - sqr + 1 sqr = square root of "sqr" } else { i=j+1 j = j + sqr - 1 sqr = square root of "sqr" } } } if arr[i] == item { Found Item at "i" while arr[i] == item && i!=temp { i=i-1 } if i==temp { i=i+1 } else i=i+2 } else

In this technique, a sorted list of values can be searched from another sorted list very efficiently. The overall time for sorting the values to be searched and searching is less than the time taken by the Linear Search and Binary Search. In this technique, the size of targeting list is reduced for every next value to be searched. As a result the searching time of remaining values to be searched is reduced, while in linear search and binary search the size of target list remains same for every value to be searched. In other words, we can say that the targeting list is traversed completely each time for every value to be searched from beginning to end. The steps of the proposed Multiple Values Bidirectional Square Root Search algorithm are as follows: Take 1st element from the item list and assign it to "item" 2. Assign 1st element of the Data list to left pointer and last element of the Data list to right pointer. 3. Take square root of list length and assign to "sqr". 4. If value on the left pointer is less then item ,increment left pointer .The new location of left pointer is getting by adding left pointer current location with "sqr". 5. If value on the left pointer is greater then item, change the location of right pointer by calculating new location as subtracting 1 from current location of left pointer. Also change the location of left pointer by subtracting left pointer current location with "sqr" and increment by 1. The new value of "sqr" is calculated by taking square root of "sqr". 6. Similarly If value on the right pointer is greater then item, decrement right pointer .the new location of right pointer is getting by subtracting right pointer current location with "sqr". 7. If value on the right pointer is less then item, change the location of left pointer by calculating new location as adding 1 with current location of right pointer. Also change the location of right pointer by adding right pointer current location with "sqr" and decrement by 1. The new value of "sqr" is calculated by taking square root of "sqr". 8. Repeat step 3 to 6 until value of left pointer or right pointer match with item, or the value of "sqr" become 1. If the value of right pointer match with the item then assign right pointer to left pointer. Assign data list length to right pointer and next element in item list to item, go to step 3.Repeat this process till all the element in the item list will be processed. 1.

158

http://sites.google.com/site/ijcsis/ ISSN 1947-5500

(IJCSIS) International Journal of Computer Science and Information Security, Vol. 8, No. 4, July 2010

{ if arr[j] == item { Found Item at "j" while arr[j]==item { j=j-1 } i=j+2 } else { if arr[i+1] == item { Found Item at "i+1" i=i+2 } else Not Found } } l = len – i } V. RUNNING COST ANALYSIS

Inner Loop Runs: n1/2 + n1/4+ n1/8………………+ n1/k Where n1/k ≥1 Comparison Statements: c So the running time of Multiple Values bidirectional square root search can be written as, T (n) = r*(n1/2 (c+c+c)+ n1/4 (c+c+c) + n1/8(c+c+c)+ ……+ n1/k (c+c+c) ) T (n) = r*(n1/2 (3c)+ n1/4 (3c) + n1/8(3c)+ ………………+ n1/k (3c) ) Ignoring Constants and smaller values we can write it as T (n) =O (r√n) VI. COMPARISON OF MULTIPLE VALUES BIDIRECTIONAL SQUARE ROOT SEARCH WITH LINEAR SEARCH AND BINARY SEARCH Table 1 shows the comparison of the proposed algorithm (Multiple Values Bidirectional Square Root Search) with the traditional searching algorithms on the basis of no. of iterations. Graphical view of the same analysis is presented in the Figure 1.

A. Best Case: The main structure of the algorithm depicts that there is an outer main loop within which there lies another inner loop , after number of inner while loop iterations, we will have found our item or concluded that it was not found. Multiple Values Bidirectional Square Root Search Best Case Occur when items are 1st or last element of the Data List. Let T (n) be the running time of Multiple Values Bidirectional Square Root Search on an input list of size n. then running time of Multiple Values Bidirectional Square Root Search Can be calculated as Length of input array: n Length of items array: r Outer Loop runs: r Inner Loop Runs: 1 so the running time of Multiple Values bidirectional square root search can be written as, T (n) = O (r * 1) B. Average and Worst Case: The main structure of the algorithm depicts that there is an outer main loop within which there lies another inner loop , after number of inner while loop iterations, we will have found our item or concluded that it was not found. Let T(n) be the running time of Multiple Values Bidirectional Square Root Search on an input list of size n. then running time of Multiple Values Bidirectional Square Root Search Can be calculated as Length of input array: n Length of items array: r Outer Loop runs: r

Table 1: Multiple Values Bidirectional Square Root Search Vs Binary Search and Linear Search

159

http://sites.google.com/site/ijcsis/ ISSN 1947-5500

(IJCSIS) International Journal of Computer Science and Information Security, Vol. 8, No. 4, July 2010

36 31
No. of  Comparisons

120000 100000 80000 60000 40000 20000 0
Multiple Values Bidirectional Square Root Search Binary Search Linear Search

26
No. of Iteration

Multiple Values Bidirectional Square Root Search Binary Search

21 16 11 6 1 59 85
Data Values

Linear Search

56 0

12

88 89 8

1

10 1

50

91

Data Values

Figure 1: Multiple Values Bidirectional Square Root Search v/s Binary Search and Linear Search

FIGURE 2: MULTIPLE VALUES BIDIRECTIONAL SQUARE ROOT SEARCH V/S BINARY SEARCH AND LINEAR SEARCH

It can be observed from the Table 1 and graph presented in Figure 1 that performance of proposed algorithm (Multiple Values Bidirectional Square Root Search) is far better than the linear search. Also it shows good result in comparison with Binary Search and show good competition. Table 2 shows the comparison of the proposed algorithm (Multiple Values Bidirectional Square Root Search) with the traditional searching algorithms on the basis of No. of comparisons. Graphical view of the same analysis is presented in the Figure 2. Total values in data list = 100000(1…..100000) Values Comparisons Linear Multiple Binary Search Values Search Bidirectional Square Root Search 1 1 1 48 948 948 9 40 10112 10112 32 43 30336 30336 67 38 50560 50560 67 32 69032 69032 75 38 89888 89888 33 37 97156 97156 10 41 100000 100000 1 35
Table 2: Multiple Values Bidirectional Square Root Search Vs Binary Search and Linear Search

It can be observed from the Table 2 and graph presented in Figure 2 that performance of proposed algorithm (Multiple Values Bidirectional Square Root Search) is far better than the linear search. Also it shows good result in comparison with Binary Search and show good competition. Table 3 shows the comparison of the proposed algorithm (Multiple Values Bidirectional Square Root Search) with the traditional searching algorithms on the basis of execution time (in ms). Graphical view of the same analysis is presented in the Figure 3. Total values in data list = 1000000(1…..1000000) No. of Elements Execution Time(millisecond) Linear Multiple Binary Search Values Search Bidirectional Square Root Search 19578 15.6 15.6 40950 31.2 46.8 80979.6 62.4 93.6 122226 78 109.2 210678 109.2 187 350107 124 234

50000 100000 200000 300000 500000 600000

Table 3: Multiple Values Bidirectional Square Root Search Vs Binary Search and Linear Search

160

http://sites.google.com/site/ijcsis/ ISSN 1947-5500

10

00 00

(IJCSIS) International Journal of Computer Science and Information Security, Vol. 8, No. 4, July 2010

400000 350000 300000
Execution Time(ms)

Multiple Values Bidirectional Square Root Search Binary Search

250000 200000 150000 100000 50000 0

Linear Search

[4] Donald Knuth. The Art of ComputerProgramming, Volume 3: Sorting and Searching, Third Edition. Addison-Wesley, 1997. ISBN 0-20189685-0. pp. 106–110 of section 5.2.2: Sorting by Exchanging. [5] Binary_search, (2010), Binary search, http://en.wikipedia.org/wiki/Binary_search, Accessed January 01, 2010 [6] Donald Knuth. The Art of Computer Programming, Volume 3: Sorting and Searching, Third Edition. Addison-Wesley, 1997. ISBN 0-20189685-0., pp. 138–141, of Section 5.2.3: Sorting by Selection. [7] Seymour Lipschutz. Theory and Problems of Data Structures,Schaum’s Outline Series: International Edition, McGraw- Hill, 1986. ISBN 0-07099130-8., pp. 324–325, of Section 9.4: Selection Sort. [8] Seymour Lipschutz. Theory and Problems of Data Structures,Schaum’s Outline Series: International Edition, McGraw- Hill, 1986. ISBN 0-07099130-8., pp. 322–323, of Section 9.3: Insertion Sort. [9] Linear_search, (2010), Linear search, http://en.wikipedia.org/wiki/Linear_search, Accessed January 01,2010.

00

50 0

20 0

00 0

No. of Elements

Figure 3: Multiple Values Bidirectional Square Root Search v/s Binary Search and Linear Search

It can be observed from the Table 3 and graph presented in Figure 3 that performance of proposed algorithm (Multiple Values Bidirectional Square Root Search) is far better than the linear search. Also it shows good result in comparison with Binary Search and show good competition. VII. CONCLUSION By analyzing the graphs above, it can be easily examined that Multiple Values Bidirectional square root search efficient then linear search and also give good competition to binary search. The common thing between Multiple Values Bidirectional Square Root Search and Binary Search is that for both, the list of element should be sorted. In future, we are foreseeing to come up with a new searching technique, which hopefully will be more efficient. ACKNOWLEDGMENT We acknowledge the support and contribution from our loving and caring families, teachers and friends in continuing the education and research. With their moral and financial support, we are in higher education, which encourages us to write this research for the ease of human kind. Thank you all. REFERENCES
[1] Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, and Clifford Stein. Introduction to Algorithms, Second Edition. MIT Press and McGraw-Hill, 2001. ISBN 0-262-03293-7. Section 1.1: Algorithms, pp.5–6. [2] D. A. Bailey, Java Structure:Data Structure in Java for Principled Programmer, 2nd ed. McGraw-Hill, 2003. [3] R. Sedgewick, Algorithms in C++. Reading, Massachusetts: AddisonWesley, 1992.

50 0

00 0

161

http://sites.google.com/site/ijcsis/ ISSN 1947-5500

Sign up to vote on this title
UsefulNot useful

Master Your Semester with Scribd & The New York Times

Special offer for students: Only $4.99/month.

Master Your Semester with a Special Offer from Scribd & The New York Times

Cancel anytime.