JASC: Journal of Applied Science and Computations ISSN NO: 1076-5131 ANALYSIS ON SEARCHING ALGORITHMS N.Pavani, M.Sree Vyshnavi, K. Sindhu Reddy, Mr. C Kishor Kumar Reddy and Dr.B V Ramana Murthy. Stanley College of Engineering and Technology for Women, Hyderabad [email protected], [email protected], [email protected], [email protected], [email protected] ABSTRACT Searching algorithms are designed to check form an element and retrieve an element from array from any of data structure where it is stored. Various searching techniques are analyzed based on the time a space complexity. There are two types of searching, internal searching and external searching. The analysis shows the advantages and disadvantages of various searching algorithms. On analysis it is found out that binary search is suitable for mid-sized data items in arrays and linked list whereas hash search is best for the larger data items. Keywords: Algorithm, Searching, Internal and External Searching, Time complexity. 1. INTRODUCTION Searching is a technique which programmers are always passively solving. Not even asingle day pass by, when we do not have to search for something in our daily life. Whenever a user asks for some data, computer has to search its memory to look for that data and should make it available to the user. And the computer has its own techniques to search through its memory very fast. To search an element in a given array, there are few algorithms available here: ⦁ Linear Search ⦁ Exponential Search ⦁ Ternary Search ⦁ Binary Search ⦁ Interpolation Search ⦁ Hash Search Volume VI, Issue I, January/2019 Page No:654 JASC: Journal of Applied Science and Computations ISSN NO: 1076-5131 1.1. Complexity Analysis The Complexity analysis is used to determine algorithm which will take amount of resources (like time and space) are necessary to execute it. There are two types of complexities, they are: Time Complexity and Space Complexity. An analysis of the time is required to solve a problem of particular size involves the time complexity of the algorithm. An analysis of computer memory required, involves the space complexity of the algorithm. There are three types of time complexities--- Best, average and worst case. Asymptotic Notations are languages that allow us to analyze an algorithms run time by identifying its behavior as the input size for the algorithm increases which is also known as an algorithm’s growth rate. Big Oh is mostly used to describe worst-case of an algorithm. Big Omega is the opposite of Big Oh, big Omega is used to describe the lower bound of asymptotic function. When an algorithm has complexity with lower bound=upper bound, which means the running time of that algorithm always falls in n log n for best-case and worst-case which is Big Theta. 2. RELEVANT WORK Bentley discussed searching algorithms, its advantages and disadvantages. They analyzed the different searching algorithms and binary search for mid-sized lists. Thomas Niemann in his research worked on searching algorithms on basics of time, space complexities. Reema Thareja discussed about the hashing and the hash functions. Wein Mark Allen explained about the different searching techniques, implementation with few examples. Various Searching Algorithms are: 2.1. LINEAR SEARCH/SEQUENTIAL SEARCH Linear searching is one of the basic searching technique. This type of searching is used to search an element in sequential order. Therefore, it is also called a sequential search. The basic concept of search is comparing the elements in the array. If any element in the array is matched to the number we entered then the position of that number is printed (index).Linear search has a simple search algorithm. Performance of linear search, we have different cases: In the average case, the linear search takes n/2 comparisons and in the worst case, it takes 2n+1 comparison’s, where n is the number of elements in the set. 2.1.1. Algorithm Linear search is simple and the job of this technique is to keep comparing with all the elements present in the list. This can be easily understood from the below algorithm. Firstly we need to set the value of i to. If the initial value is greater than n, then go to step 7. If a[i]=x then go to step 6. Then the value of i gets incremented. After incrementing again go to step 2. If the required element is found print "The element is found". If the element is not found then print "The element is not found", Exit. Volume VI, Issue I, January/2019 Page No:655 JASC: Journal of Applied Science and Computations ISSN NO: 1076-5131 Figure.1: Image showing target value through linear search. 2.1.2. Analysis a) Worst case is the condition at which the target is not found in the list and the order is O(n). b) Best case is when the required target is found in the first position and the order is O(1). c) Average case is when a target is found after n comparisons and the order is O(n). 2.1.3. Advantages a) This kind of searching technique is simple to perform. b) If we find the element in the first increment then there is no need for us to know how many pages are there. c) This type of technique takes less time. d) It is independent of number of elements in the directory. e) The Time complexity of linear search is O(1). 2.1.4. Disadvantages a) It is not suitable for long lists. b) If the list is too long then we need to search each and every element in the list. c) The Worst time complexity of the linear search is O(n). Volume VI, Issue I, January/2019 Page No:656 JASC: Journal of Applied Science and Computations ISSN NO: 1076-5131 2.2. EXPONENTIAL SEARCH Exponential search which is also called doubling search or galloping search is an algorithm created by Jon Bentley and Andrew-chi-chih-yao in 1976, for searching or sorted unbounded/infinite lists. There are many ways to implement this with the most common being to determine the range that the search key resides in and performing a binary search within that range. This takes O (log i ) where i is the position of the search key in list, if search key is in the list, or in position where the search key should be. 2.2.1. Algorithm Exponential search allows searching through a sorted and an unbounded list for a specified input value “the search key". The algorithm consists of two stages. The first stage determines the range in which search key would reside if it was in the list. In the second stage, a binary search is performed on that range. In the first stage, assuming that list is sorted in an ascending order, the algorithm looks for the first exponent, j , where the value 2 j is greater than search key. Figure.2: Target value being searched by exponential search. In each step, the algorithm compares the search key value with the key value at current search index. If the element at current index is smaller than the search key, the algorithm repeats, skipping to next search index by doubling it, calculating the next power of 2. If the element at the current index is larger than the search key, the algorithm now knows that search key, if it is contained in the list is located in the interval formed by the previous search index, 2 j - 1 , and the current search index, 2 j . The binary search is then performed with the result of either a failure, if the search key is not in the list, or in the position of the search key in the list. 2.2.2. Time Complexity The first stage of the algorithm takes O (log i ) time, where i is index where the search key would be in list. This gives the algorithm a total runtime, calculated by summing runtimes of the two stages: O (log i) + O (log i ) = 2 O (log i ) = O (log i ). 2.2.3. Advantages a) It is easy to learn and apply. b) It produces accurate forecasts. Volume VI, Issue I, January/2019 Page No:657 JASC: Journal of Applied Science and Computations ISSN NO: 1076-5131 c) It gives more significance to recent observations. 2.2.4. Disadvantages a) It produces forecasts that lag behind the actual trend. b) It cannot handle trends well. 2.3. TERNARY SEARCH This concept is used in unimodal functions to determine maximum or minimum value of that function. Unimodal functions are functions that have single highest value. Like linear search and binary search, ternary search is also a searching technique that is used to determine position of a specific value in an array. In binary search, the sorted array is divided into two parts while in ternary search, it is divided into 3 parts and then you determine in which part the element exists. Like linear search and binary search, ternary search is also a searching technique that is used to determine the position of a specific value in an array. In binary search, the sorted array is divided into two parts while in ternary search, it is divided into parts and then you determine in which part element exists. Ternary search, like binary search, is a divide-and-conquer algorithm. A ternary search tree is a special trie data structure where the child nodes of a standard trie are ordered as a binary search tree. Representation of ternary search trees: Unlike trie(standard) data structure where each node contains 26 pointers for its children, each node in a ternary search tree contains only 3 pointers: a) The left pointer points to the node whose value is less than the value in the current node.
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages11 Page
-
File Size-