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...

Comb Sort

Comb sort is a sorting algorithm that was first proposed by Włodzimierz Dobosiewicz in 1980. The algorithm is a variation of bubble sort, and it is designed to improve upon the performance of bubble sort by using a larger gap between elements during the comparison phase of the algorithm. The basic idea behind comb sort is to compare elements that are separated by a large gap, and gradually reduce the gap between elements until the gap is equal to 1. The gap between elements is known as the "comb" in comb sort, and it is initially set to be the size of the input array being sorted. The size of the comb is then reduced by a factor known as the shrink factor, which is typically set to 1.3. During each pass of the algorithm, elements that are separated by the current gap are compared and swapped if they are out of order. The gap between elements is then reduced by the shrink factor, and the process is repeated until the gap is equal to 1. Once the gap is equal to 1, the algorithm...