Skip to main content

Searching

 

Searching is a process of finding an item or group of items that match certain criteria within a data structure, such as an array or linked list. There are various search algorithms with varying time complexity, including linear search, binary search, and hash table search.

Linear search goes through each element in the data structure sequentially until a match is found. Binary search divides the data structure in half with each iteration and only searches the half that could contain the item. Hash table search uses a hash function to map data to an index in an array and directly access the desired item.

The efficiency of a search algorithm depends on the size of the data structure and the distribution of the data. Sorted data structures make binary search faster, while unsorted data makes linear search faster. Hash tables are efficient for searching large data sets with a good hash function.

In programming, searching is an important operation that is used in many applications, such as databases, search engines, and e-commerce websites. The choice of search algorithm often depends on the specific requirements of the application and trade-offs between time and space complexity.


TYPES OF SEARCHING ALGORITHMS :

  1. Linear Search
  2. Binary Search
  3. Depth First Search (DFS)
  4. Breadth First Search (BFS)
  5. Rabin-Karp Algorithm
  6. Z- Algorithm

QUESTIONS ON SEARCHING ALGORITHMS :

  1. Linear Search
  2. Binary Search
  3. Depth First Search (DFS)
  4. Breadth First Search (BFS)
  5. Rabin-Karp Algorithm
  6. Z- Algorithm

Comments

Popular posts from this blog

Bubble Sort

   Bubble sort is a simple sorting algorithm that works by repeatedly swapping adjacent elements if they are in the wrong order. It is named after the way bubbles rise to the top of a liquid, as it sorts the array by repeatedly moving the largest or smallest elements to the top of the array. The algorithm works by iterating through the array, comparing each adjacent pair of elements and swapping them if they are in the wrong order. This process is repeated until the array is fully sorted. Let's say we have an array of integers [5, 3, 8, 4, 2]. The first pass of the algorithm would compare 5 and 3, swap them to get [3, 5, 8, 4, 2]. It would then compare 5 and 8 and not swap them, as they are in the correct order. It would then compare 8 and 4, swap them to get [3, 5, 4, 8, 2]. It would then compare 8 and 2, swap them to get [3, 5, 4, 2, 8]. The first pass is now complete, and the largest element, 8, is at the end of the array. The second pass would start with comparing 3 and 5,...

Shell Sort

Shell sort is a sorting algorithm developed by Donald Shell in 1959. It is an extension of the insertion sort algorithm and is classified as an in-place comparison sort. Shell sort aims to improve the performance of insertion sort by sorting elements that are far apart from each other first, thus reducing the number of comparisons needed to sort the entire array. The algorithm works by first dividing the array into smaller subarrays, each containing elements that are a certain gap apart. The gap is typically initialized to be the length of the array divided by 2, and is then halved in each iteration until it becomes 1. The subarrays are then sorted using insertion sort, which sorts elements within each subarray by comparing adjacent elements and swapping them if they are in the wrong order. The key idea behind Shell sort is that insertion sort performs poorly on arrays that are almost sorted, but works well on small arrays. By sorting the subarrays with larger gaps first, the algorithm...

Pigeonhole Sort

Pigeonhole sort is a sorting algorithm that works by distributing elements of an input sequence into a set of pigeonholes or buckets. It is an efficient sorting algorithm for small ranges of values where the number of elements to be sorted is roughly the same as the range of values. Pigeonhole sort is an example of a bucket sort algorithm. The pigeonhole sort algorithm works by first determining the range of values in the input sequence. This range is used to create a set of pigeonholes or buckets, each of which can hold one or more elements from the input sequence. Each element in the input sequence is then placed into its corresponding pigeonhole based on its value. If two or more elements have the same value, they can be placed in the same pigeonhole. Once all the elements have been placed into their corresponding pigeonholes, the elements are sorted within each pigeonhole. Finally, the sorted elements are combined into a single output sequence. Pigeonhole sort has a time complexity...