Searching Algorithms - GeeksforGeeks (2024)

Last Updated : 01 Apr, 2024

Improve

Searching algorithms are essential tools in computer science used to locate specific items within a collection of data. These algorithms are designed to efficiently navigate through data structures to find the desired information, making them fundamental in various applications such as databases, web search engines, and more.

Searching Algorithms - GeeksforGeeks (1)

Searching Algorithm

Table of Content

  • What is Searching?
  • Searching terminologies
  • Importance of Searching in DSA
  • Applications of Searching
  • Basics of Searching Algorithms
  • Searching Algorithms
  • Comparisons Between Different Searching Algorithms
  • Library Implementations of Searching Algorithms
  • Easy Problems on Searching
  • Medium Problems on Searching
  • Hard Problems on Searching

What is Searching?

Searching is the fundamental process of locating a specific element or item within a collection of data. This collection of data can take various forms, such as arrays, lists, trees, or other structured representations. The primary objective of searching is to determine whether the desired element exists within the data, and if so, to identify its precise location or retrieve it. It plays an important role in various computational tasks and real-world applications, including information retrieval, data analysis, decision-making processes, and more.

Searching terminologies:

Target Element:

In searching, there is always a specific target element or item that you want to find within the data collection. This target could be a value, a record, a key, or any other data entity of interest.

Search Space:

The search space refers to the entire collection of data within which you are looking for the target element. Depending on the data structure used, the search space may vary in size and organization.

Complexity:

Searching can have different levels of complexity depending on the data structure and the algorithm used. The complexity is often measured in terms of time and space requirements.

Deterministic vs. Non-deterministic:

Some searching algorithms, likebinary search, are deterministic, meaning they follow a clear, systematic approach. Others, such as linear search, are non-deterministic, as they may need to examine the entire search space in the worst case.

Importance of Searching in DSA:

  • Efficiency:Efficient searching algorithms improve program performance.
  • Data Retrieval:Quickly find and retrieve specific data from large datasets.
  • Database Systems:Enables fast querying of databases.
  • Problem Solving:Used in a wide range of problem-solving tasks.

Applications of Searching:

Searching algorithms have numerous applications across various fields. Here are some common applications:

  • Information Retrieval: Search engines like Google, Bing, and Yahoo use sophisticated searching algorithms to retrieve relevant information from vast amounts of data on the web.
  • Database Systems: Searching is fundamental in database systems for retrieving specific data records based on user queries, improving efficiency in data retrieval.
  • E-commerce: Searching is crucial in e-commerce platforms for users to find products quickly based on their preferences, specifications, or keywords.
  • Networking: In networking, searching algorithms are used for routing packets efficiently through networks, finding optimal paths, and managing network resources.
  • Artificial Intelligence: Searching algorithms play a vital role in AI applications, such as problem-solving, game playing (e.g., chess), and decision-making processes
  • Pattern Recognition: Searching algorithms are used in pattern matching tasks, such as image recognition, speech recognition, and handwriting recognition.

Basics of Searching Algorithms:

  • Introduction to Searching – Data Structure and Algorithm Tutorial
  • Importance of searching in Data Structure
  • What is the purpose of the search algorithm?

Searching Algorithms:

  • Linear Search
  • Sentinel Linear Search
  • Binary Search
  • Meta Binary Search | One-Sided Binary Search
  • Ternary Search
  • Jump Search
  • Interpolation Search
  • Exponential Search
  • Fibonacci Search
  • The Ubiquitous Binary Search

Comparisons Between Different Searching Algorithms:

  • Linear Search vs Binary Search
  • Interpolation search vs Binary search
  • Why is Binary Search preferred over Ternary Search?
  • Is Sentinel Linear Search better than normal Linear Search?

Library Implementations of Searching Algorithms:

  • Binary Search functions in C++ STL (binary_search, lower_bound and upper_bound)
  • Arrays.binarySearch() in Java with examples | Set 1
  • Arrays.binarySearch() in Java with examples | Set 2 (Search in subarray)
  • Collections.binarySearch() in Java with Examples

Easy Problems on Searching:

  • Find the largest three elements in an array
  • Find the Missing Number
  • Find the first repeating element in an array of integers
  • Find the missing and repeating number
  • Search, insert and delete in a sorted array
  • Count 1’s in a sorted binary array
  • Two elements whose sum is closest to zero
  • Find a pair with the given difference
  • k largest(or smallest) elements in an array
  • Kth smallest element in a row-wise and column-wise sorted 2D array
  • Find common elements in three sorted arrays
  • Ceiling in a sorted array
  • Floor in a Sorted Array
  • Find the maximum element in an array which is first increasing and then decreasing
  • Given an array of of size n and a number k, find all elements that appear more than n/k times

Medium Problems on Searching:

  • Find all triplets with zero sum
  • Find the element before which all the elements are smaller than it, and after which all are greater
  • Find the largest pair sum in an unsorted array
  • K’th Smallest/Largest Element in Unsorted Array
  • Search an element in a sorted and rotated array
  • Find the minimum element in a sorted and rotated array
  • Find a peak element
  • Maximum and minimum of an array using minimum number of comparisons
  • Find a Fixed Point in a given array
  • Find the k most frequent words from a file
  • Find k closest elements to a given value
  • Given a sorted array and a number x, find the pair in array whose sum is closest to x
  • Find the closest pair from two sorted arrays
  • Find three closest elements from given three sorted arrays
  • Binary Search for Rational Numbers without using floating point arithmetic

Hard Problems on Searching:

  • Median of two sorted arrays
  • Median of two sorted arrays of different sizes
  • Search in an almost sorted array
  • Find position of an element in a sorted array of infinite numbers
  • Given a sorted and rotated array, find if there is a pair with a given sum
  • K’th Smallest/Largest Element in Unsorted Array | Worst case Linear Time
  • K’th largest element in a stream
  • Best First Search (Informed Search)

Quick Links:

  • ‘Practice Problems’ on Searching
  • ‘Quizzes’ on Searching

Recommended:

  • Learn Data Structure and Algorithms | DSA Tutorial


Like Article

Suggest improvement

Next

Linear Search Algorithm - Data Structure and Algorithms Tutorials

Share your thoughts in the comments

Please Login to comment...

Searching Algorithms - GeeksforGeeks (2024)

FAQs

What is the most efficient searching algorithm? ›

The Binary Search algorithm is arguably the best, but it requires your array to be sorted. It simply works by getting the middle index and comparing it with your target. If the target is greater than the middle, it will ignore the left part and search the right part.

How many types of searching algorithms are there? ›

Types of search algorithms include Linear Search, Jump Search, Exponential Search, Binary Search, Interpolation Search, and Fibonacci Search. Graph Search Algorithms like Breadth-First Search (BFS) and Depth-First Search (DFS) are pivotal for searching vertices in a graph efficiently.

What are searching techniques? ›

The search technique is a mechanism through which, one can find relevant information from information systems. The information system may be in- house or online. • Storage mechanism can be dictionary, numeric and classified arrangement of information.

What do you mean by searching? ›

Searching means locating a particular element in a collection of elements. Search result determines whether that particular element is present in the collection or not. If it is present, we can also find out the position of that element in the given collection.

What is the best optimized search algorithm? ›

This type of searching algorithm is used to find the position of a specific value contained in a sorted array. The binary search algorithm works on the principle of divide and conquer and it is considered the best searching algorithm because it's faster to run.

What is the fastest pattern searching algorithm? ›

Why is Boyer-Moore the fastest searching algorithm? The Boyer–Moore algorithm uses information gathered during the preprocessing step to skip text sections, resulting in a lower constant factor than many other string search algorithms. In general, the algorithm runs faster as the pattern length increases.

What are the 7 search strategy techniques? ›

Search strategy techniques
  • Choosing search terms.
  • Searching with keywords.
  • Searching for exact phrases.
  • Using truncated and wildcard searches.
  • Searching with subject headings.
  • Using Boolean logic.
  • Citation searching.

What are the 4 search strategies? ›

Search strategies
  • Understand your topic and define your search terms.
  • Create your search strategy.
  • Select an appropriate tool.
  • Evaluate your resources.

What are the six basic search techniques? ›

Search Techniques
  • Search Techniques.
  • Broad and narrow searches.
  • Search blocks.
  • Combining search words with Boolean operators (AND, OR and NOT)
  • Searching for part of words (truncation)
  • Searching for phrases (quotation marks)
  • Simple and advanced search forms.
  • Improving your search.
Oct 30, 2023

What is an example of searching? ›

For example you want to see how many 5's are in an array. This array has 3 occurances of 5s and we want to return the indexes (where they are in the array) of all of them. This is called global linear search. You will need to adjust your code to return an array of the index points at which it finds the target element.

What do you call a person who searches for something? ›

Definitions of searcher. someone making a search or inquiry. synonyms: quester, seeker.

What is the difference between looking and searching? ›

The most common definitions refer to search (or searching) as - 'to look into or over carefully or thoroughly in an effort to find or discover something'. Whereas looking is - 'an act of directing one's gaze in order to see someone or something. '

What is the optimal search algorithm? ›

An algorithm that gives you optimal paths—branch and bound
  • Although the straight line distance from node 1 to the goal is shorter than the distance of node 2 to the goal, we find a river blocking the way.
  • These guessing strategies are called heuristics.
  • Branch and bound search uses 2 heuristics to guide search.

What is the most efficient algorithm? ›

The highest efficiency level in algorithm complexity is the O(1) or constant time complexity. An algorithm with O(1) complexity is highly efficient, as its performance does not depend on the size of the input data. It takes the same amount of time to execute, regardless of the input size.

What is the most efficient sorting algorithm? ›

In practice, Quick Sort is usually the fastest sorting algorithm. Its performance is measured most of the time in O(N × log N). This means that the algorithm makes N × log N comparisons to sort N elements.

Which type of search is more efficient? ›

Lower average case complexity is better for faster performance, especially with large inputs. Algorithms like binary search O(log n) are highly efficient. On the other hand, higher complexities, such as O(n), may become impractical for large datasets due to linear or worse runtime growth.

Top Articles
Latest Posts
Article information

Author: Neely Ledner

Last Updated:

Views: 5827

Rating: 4.1 / 5 (42 voted)

Reviews: 81% of readers found this page helpful

Author information

Name: Neely Ledner

Birthday: 1998-06-09

Address: 443 Barrows Terrace, New Jodyberg, CO 57462-5329

Phone: +2433516856029

Job: Central Legal Facilitator

Hobby: Backpacking, Jogging, Magic, Driving, Macrame, Embroidery, Foraging

Introduction: My name is Neely Ledner, I am a bright, determined, beautiful, adventurous, adventurous, spotless, calm person who loves writing and wants to share my knowledge and understanding with you.