Recent from talks
Nothing was collected or created yet.
Search algorithm
View on WikipediaThis article has multiple issues. Please help improve it or discuss these issues on the talk page. (Learn how and when to remove these messages)
|

In computer science, a search algorithm is an algorithm designed to solve a search problem. Search algorithms work to retrieve information stored within particular data structure, or calculated in the search space of a problem domain, with either discrete or continuous values.
Although search engines use search algorithms, they belong to the study of information retrieval, not algorithmics.
The appropriate search algorithm to use often depends on the data structure being searched, and may also include prior knowledge about the data. Search algorithms can be made faster or more efficient by specially constructed database structures, such as search trees, hash maps, and database indexes.[1][2]
Search algorithms can be classified based on their mechanism of searching into three types of algorithms: linear, binary, and hashing. Linear search algorithms check every record for the one associated with a target key in a linear fashion.[3] Binary, or half-interval, searches repeatedly target the center of the search structure and divide the search space in half. Comparison search algorithms improve on linear searching by successively eliminating records based on comparisons of the keys until the target record is found, and can be applied on data structures with a defined order.[4] Digital search algorithms work based on the properties of digits in data structures by using numerical keys.[5] Finally, hashing directly maps keys to records based on a hash function.[6]
Algorithms are often evaluated by their computational complexity, or maximum theoretical run time. Binary search functions, for example, have a maximum complexity of O(log n), or logarithmic time. In simple terms, the maximum number of operations needed to find the search target is a logarithmic function of the size of the search space.
Applications of search algorithms
[edit]Specific applications of search algorithms include:
- Problems in combinatorial optimization, such as:
- The vehicle routing problem, a form of shortest path problem
- The knapsack problem: Given a set of items, each with a weight and a value, determine the number of each item to include in a collection so that the total weight is less than or equal to a given limit and the total value is as large as possible.
- The nurse scheduling problem
- Problems in constraint satisfaction, such as:
- The map coloring problem
- Filling in a sudoku or crossword puzzle
- In game theory and especially combinatorial game theory, choosing the best move to make next (such as with the minmax algorithm)
- Finding a combination or password from the whole set of possibilities
- Factoring an integer (an important problem in cryptography)
- Search engine optimization (SEO) and content optimization for web crawlers
- Optimizing an industrial process, such as a chemical reaction, by changing the parameters of the process (like temperature, pressure, and pH)
- Retrieving a record from a database
- Finding the maximum or minimum value in a list or array
- Checking to see if a given value is present in a set of values
Classes
[edit]For virtual search spaces
[edit]Algorithms for searching virtual spaces are used in the constraint satisfaction problem, where the goal is to find a set of value assignments to certain variables that will satisfy specific mathematical equations and inequations / equalities. They are also used when the goal is to find a variable assignment that will maximize or minimize a certain function of those variables. Algorithms for these problems include the basic brute-force search (also called "naïve" or "uninformed" search), and a variety of heuristics that try to exploit partial knowledge about the structure of this space, such as linear relaxation, constraint generation, and constraint propagation.
An important subclass are the local search methods, that view the elements of the search space as the vertices of a graph, with edges defined by a set of heuristics applicable to the case; and scan the space by moving from item to item along the edges, for example according to the steepest descent or best-first criterion, or in a stochastic search. This category includes a great variety of general metaheuristic methods, such as simulated annealing, tabu search, A-teams,[7] and genetic programming, that combine arbitrary heuristics in specific ways. The opposite of local search would be global search methods. This method is applicable when the search space is not limited and all aspects of the given network are available to the entity running the search algorithm.[8]
This class also includes various tree search algorithms, that view the elements as vertices of a tree, and traverse that tree in some special order. Examples of the latter include the exhaustive methods such as depth-first search and breadth-first search, as well as various heuristic-based search tree pruning methods such as backtracking and branch and bound. Unlike general metaheuristics, which at best work only in a probabilistic sense, many of these tree-search methods are guaranteed to find the exact or optimal solution, if given enough time. This is called "completeness".
Another important sub-class consists of algorithms for exploring the game tree of multiple-player games, such as chess or backgammon, whose nodes consist of all possible game situations that could result from the current situation. The goal in these problems is to find the move that provides the best chance of a win, taking into account all possible moves of the opponent(s). Similar problems occur when humans or machines have to make successive decisions whose outcomes are not entirely under one's control, such as in robot guidance or in marketing, financial, or military strategy planning. This kind of problem — combinatorial search — has been extensively studied in the context of artificial intelligence. Examples of algorithms for this class are the minimax algorithm, alpha–beta pruning, and the A* algorithm and its variants.
For sub-structures of a given structure
[edit]An important and extensively studied subclass are the graph algorithms, in particular graph traversal algorithms, for finding specific sub-structures in a given graph — such as subgraphs, paths, circuits, and so on. Examples include Dijkstra's algorithm, Kruskal's algorithm, the nearest neighbour algorithm, and Prim's algorithm.
Another important subclass of this category are the string searching algorithms, that search for patterns within strings. Two famous examples are the Boyer–Moore and Knuth–Morris–Pratt algorithms, and several algorithms based on the suffix tree data structure.
Search for the maximum of a function
[edit]In 1953, American statistician Jack Kiefer devised Fibonacci search which can be used to find the maximum of a unimodal function and has many other applications in computer science.
For quantum computers
[edit]There are also search methods designed for quantum computers, like Grover's algorithm, that are theoretically faster than linear or brute-force search even without the help of data structures or heuristics. While the ideas and applications behind quantum computers are still entirely theoretical, studies have been conducted with algorithms like Grover's that accurately replicate the hypothetical physical versions of quantum computing systems.[9]
See also
[edit]- Backward induction – Process of reasoning backwards in sequence
- Content-addressable memory – Type of computer memory hardware
- Dual-phase evolution – Process that drives self-organization within complex adaptive systems
- Linear search problem – Computational search problem
- No free lunch in search and optimization – Average solution cost is the same with any method
- Recommender system – System to predict users' preferences, also use statistical methods to rank results in very large data sets
- Search engine (computing) – System to help searching for information
- Search game – Two-person zero-sum game
- Selection algorithm – Method for finding kth smallest value
- Solver – Software for a class of mathematical problems
- Sorting algorithm – Algorithm that arranges lists in order, necessary for executing certain search algorithms
- Web search engine – Software system for finding relevant information on the Web
Categories:
References
[edit]Citations
[edit]- ^ Beame & Fich 2002, p. 39.
- ^ Knuth 1998, §6.5 ("Retrieval on Secondary Keys").
- ^ Knuth 1998, §6.1 ("Sequential Searching").
- ^ Knuth 1998, §6.2 ("Searching by Comparison of Keys").
- ^ Knuth 1998, §6.3 (Digital Searching).
- ^ Knuth 1998, §6.4, (Hashing).
- ^ Talukdar, Sarosh; Baerentzen, Lars; Gove, Andrew; De Souza, Pedro (1998-12-01). "Asynchronous Teams: Cooperation Schemes for Autonomous Agents". Journal of Heuristics. 4 (4): 295–321. doi:10.1023/A:1009669824615. ISSN 1572-9397.
- ^ Hunter, A.H.; Pippenger, Nicholas (4 July 2013). "Local versus global search in channel graphs". Networks: An International Journey. arXiv:1004.2526.
- ^ López, G V; Gorin, T; Lara, L (26 February 2008). "Simulation of Grover's quantum search algorithm in an Ising-nuclear-spin-chain quantum computer with first- and second-nearest-neighbour couplings". Journal of Physics B: Atomic, Molecular and Optical Physics. 41 (5) 055504. arXiv:0710.3196. Bibcode:2008JPhB...41e5504L. doi:10.1088/0953-4075/41/5/055504. S2CID 18796310.
Bibliography
[edit]Books
[edit]- Knuth, Donald (1998). Sorting and Searching. The Art of Computer Programming. Vol. 3 (2nd ed.). Reading, MA: Addison-Wesley Professional.
Articles
[edit]- Beame, Paul; Fich, Faith (August 2002). "Optimal Bounds for the Predecessor Problem and Related Problems". Journal of Computer and System Sciences. 65 (1): 38–72. doi:10.1006/jcss.2002.1822. S2CID 1991980.
- Schmittou, Thomas; Schmittou, Faith E. (2002-08-01). "Optimal Bounds for the Predecessor Problem and Related Problems". Journal of Computer and System Sciences. 65 (1): 38–72. doi:10.1006/jcss.2002.1822.
External links
[edit]- Uninformed Search Project at the Wikiversity.
Search algorithm
View on GrokipediaIntroduction
Definition and Purpose
A search algorithm is a method for finding a target element or solution within a defined search space, such as arrays, graphs, or abstract state spaces.[5] These algorithms are fundamental in computer science, enabling the systematic exploration of data structures to retrieve specific information or resolve problems.[6] The primary purpose of a search algorithm is to efficiently locate items, paths, or optimal solutions by minimizing computational resources, such as time or memory usage, thereby supporting applications from simple data retrieval to complex problem-solving.[7] Basic examples illustrate this purpose. Linear search involves sequential scanning of an array from the first element until the target is found or the end is reached, requiring O(n) time in the worst case, where n is the number of elements.[8] In contrast, hashing provides direct access via hash functions that map keys to array indices, achieving O(1) average-case time complexity for lookups, though it may degrade under collisions.[9] Key components of a search algorithm include the input—typically the search space and a query or target—the output, which is either the target itself or an indication of its absence, and termination conditions that define when the search concludes, such as exhausting the space or meeting a success criterion.[10] These elements ensure the algorithm operates predictably within the broader context of search spaces and complexity measures explored in foundational concepts.[1]Historical Development
The conceptual foundations of search algorithms trace back to 19th-century mathematics, where precursors to modern searching emerged in sorting techniques that systematically scanned and compared elements, such as the radix sort developed by Herman Hollerith in 1887 for efficient data organization.[11] These methods laid groundwork for algorithmic traversal and comparison, influencing later computational search. In the 1940s, with the rise of electronic computing, Alan Turing's seminal 1936 work on computable numbers and the Entscheidungsproblem introduced formal models of computation that inherently involved searching for halting states or proofs, establishing search as a core element of decidability and algorithmic processes. The 1950s and 1960s marked the emergence of explicit search frameworks in artificial intelligence and data processing. Allen Newell, Herbert A. Simon, and J.C. Shaw developed the General Problem Solver (GPS) in 1957, an early AI program that employed tree search and means-ends analysis to simulate human-like problem-solving by exploring state spaces.[12] Complementing this, the Knuth-Morris-Pratt algorithm for string matching, initially conceived by James H. Morris in 1970 and formalized by Donald Knuth, Vaughan Pratt, and Morris in 1977, revolutionized pattern search by preprocessing the pattern to enable linear-time execution without backtracking over text.[13] During the 1970s and 1980s, graph-based search algorithms solidified their role in optimization and AI. Edsger W. Dijkstra's 1959 algorithm for finding shortest paths in weighted graphs provided an efficient, greedy method for network traversal, gaining widespread application in routing and operations research thereafter.[14] Nils J. Nilsson's 1980 textbook Principles of Artificial Intelligence systematically described uninformed search strategies like breadth-first and depth-first search, framing them within AI problem-solving and influencing subsequent theoretical developments.[15] Richard M. Karp's contributions, including the Edmonds-Karp algorithm for maximum flow in 1972, extended search techniques to network problems by iteratively finding augmenting paths via breadth-first search.[16] From the late 1960s into the 1990s and beyond, informed and quantum search paradigms advanced efficiency in complex domains. Peter Hart, Nils Nilsson, and Bertram Raphael introduced the A* algorithm in 1968, blending Dijkstra's uniform-cost search with admissible heuristics to guide exploration toward goals, with ongoing expansions enhancing its use in pathfinding and planning.[17] In 1996, Lov K. Grover developed a quantum algorithm offering a quadratic speedup for unstructured database search, marking a pivotal shift toward quantum-enhanced methods for exhaustive searches.[18] These innovations by key figures like Dijkstra, Karp, and Grover underscore the progression from classical to specialized search paradigms.Fundamental Concepts
Search Space and Problem Formulation
In artificial intelligence and computer science, the search space, often synonymous with the state space, refers to the complete set of all possible states or configurations that a problem can assume. This space is typically modeled as a graph where nodes represent individual states and directed edges denote valid transitions between them, induced by permissible actions. For example, in pathfinding tasks, states might correspond to locations in a map, while in constraint satisfaction problems, the search space encompasses all feasible assignments of values to a set of variables subject to given constraints. The size of the search space can range from small and enumerable to exponentially large, making efficient traversal a core challenge for search algorithms.[19][20] Formulating a search problem involves specifying a structured framework that captures its essential elements, enabling algorithms to systematically explore the search space. A standard formulation, as outlined in foundational AI literature, includes the initial state, which denotes the problem's starting configuration; the successor function (or actions and transition model), which defines how to generate adjacent states from any given state; the goal test, a procedure to check whether a state satisfies the objective; and the path cost function, which measures the cumulative expense of a solution path, incorporating step costs for transitions in weighted environments. These components implicitly or explicitly delineate the boundaries and dynamics of the search space, allowing for the identification of optimal or feasible solutions. In formal terms, a search problem can be represented as a tuple comprising the set of states , the initial state , the set of actions available in each state , the transition model indicating resulting states, the goal set , and the step cost function . This structure applies to deterministic problems where outcomes are predictable, contrasting with stochastic variants that incorporate probabilities.[19] State representation plays a crucial role in managing the search space, balancing completeness with computational feasibility. Explicit representations store states directly, such as arrays for board configurations in puzzles like the 8-queens problem, which is practical for small, finite spaces but becomes prohibitive for larger ones due to memory demands. In contrast, implicit representations generate states dynamically via the successor function, avoiding full enumeration; this is the norm in vast domains like chess, where the state space exceeds positions, and only relevant portions are expanded during search. The choice influences algorithm efficiency, with implicit methods enabling exploration of theoretically infinite or uncountably large spaces, such as continuous configurations in robotics.[19][21] A representative example of this formulation is the pathfinding problem, where the objective is to determine a sequence of actions leading from an initial state—such as a vehicle's position at a starting city—to a goal state, like arriving at a destination city, while minimizing travel cost in a road network. Here, states are locations, the successor function yields neighboring cities connected by roads, the goal test verifies arrival at the target, and path costs reflect distances or times; this setup underpins applications from GPS navigation to game AI.[19]Time and Space Complexity Measures
In search algorithms, time complexity quantifies the computational effort required to find a solution, typically measured by the number of nodes generated or expanded in the search tree. For problems formulated in a search space with branching factor (average number of successors per node) and solution depth , uninformed search methods like breadth-first search exhibit a time complexity of , as they explore all nodes up to depth and part of depth .[19] This arises because the algorithm expands layers of the tree sequentially, leading to an exponential growth in the number of nodes processed.[22] Space complexity assesses the memory usage, often determined by the size of the frontier (open list of nodes to explore) and explored set (closed list). In breadth-first search, space requirements reach due to storing all nodes at the deepest level in the queue.[19] By contrast, depth-first search, which delves deeply along one branch before backtracking, has a space complexity of , where is the maximum depth of the search tree, as it only maintains a stack proportional to the path length plus unexpanded siblings.[22] These measures highlight how algorithm design influences resource demands in navigating the search space. Beyond efficiency, search algorithms are evaluated for optimality and completeness. An algorithm is optimal if it guarantees finding a solution with the lowest path cost among all possible solutions, assuming uniform costs or admissible heuristics.[19] Completeness means the algorithm will find a solution if one exists in a finite search space, provided it systematically explores without infinite loops.[19] Breadth-first search achieves both properties in uniform-cost environments, while depth-first search is complete but not optimal due to potential oversight of shorter paths.[22] A key trade-off exists between time and space complexity, as algorithms optimizing one often exacerbate the other. Iterative deepening search addresses this by performing successive depth-limited searches with increasing limits, achieving completeness and optimality like breadth-first search but with time complexity and space complexity , thus balancing exponential time growth with linear space in depth.[19] This makes it suitable for memory-constrained settings where full frontier storage is prohibitive. For a concrete example outside tree search, binary search on a sorted array of elements demonstrates logarithmic efficiency, with a time complexity of in the worst case, as each step halves the search interval until the target is isolated. Space complexity here is for the iterative version, relying only on index pointers without additional storage.Types of Search Algorithms
Uninformed Search Strategies
Uninformed search strategies, also known as blind search methods, rely solely on the problem definition to systematically explore the search space without incorporating any heuristic knowledge or estimates about the proximity to the goal state.[23][24] These approaches treat the search as a tree or graph traversal, expanding nodes based on predefined rules like order or depth, making them applicable to any well-defined problem but often inefficient in large spaces due to exhaustive enumeration.[19] Breadth-first search (BFS) performs a level-order traversal of the search tree, expanding all nodes at the current depth before proceeding to the next, using a first-in, first-out (FIFO) queue to manage the frontier of unexpanded nodes.[23] This strategy is complete, guaranteeing a solution if one exists in a finite space, and optimal for unweighted graphs where all edge costs are uniform, as it finds the shallowest goal state.[24] The time and space complexity of BFS is , where is the branching factor and is the depth of the shallowest solution, reflecting the exponential growth in nodes explored up to that level.[23] A standard implementation of BFS in the context of tree search follows this pseudocode, adapted for problem-solving agents:function TREE-SEARCH(problem, frontier) returns a solution or failure
frontier ← INSERT(MAKE-NODE(INITIAL-STATE(problem)), frontier)
while not IS-EMPTY(frontier) do
node ← REMOVE-FRONT(frontier) // FIFO queue for BFS
if GOAL-TEST(problem, STATE(node)) then return node
for each action in ACTIONS(problem, STATE(node)) do
child ← CHILD-NODE(problem, node, action)
INSERT(child, frontier)
return failure
function TREE-SEARCH(problem, frontier) returns a solution or failure
frontier ← INSERT(MAKE-NODE(INITIAL-STATE(problem)), frontier)
while not IS-EMPTY(frontier) do
node ← REMOVE-FRONT(frontier) // FIFO queue for BFS
if GOAL-TEST(problem, STATE(node)) then return node
for each action in ACTIONS(problem, STATE(node)) do
child ← CHILD-NODE(problem, node, action)
INSERT(child, frontier)
return failure