mirror of
https://github.com/krahets/hello-algo.git
synced 2024-12-25 21:46:28 +08:00
fb04ff6535
* translation update: Update summary.md added and refined some parts. I feel like that this chapter is already pretty well translated. * translation: Update summary.md rewritten some parts of the sentence as per Thomas suggested. please note that some parts I re-wrote it a bit differently. * translation update: summary.md Added what Ymmma suggested
1.6 KiB
1.6 KiB
Summary
- Binary search depends on the order of data and performs the search by iteratively halving the search interval. It requires the input data to be sorted and is only applicable to arrays or array-based data structures.
- Brute force search may be required to locate an entry in an unordered dataset. Different search algorithms can be applied based on the data structure: Linear search is suitable for arrays and linked lists, while breadth-first search (BFS) and depth-first search (DFS) are suitable for graphs and trees. These algorithms are highly versatile, requiring no preprocessing of data, but they have a higher time complexity of
O(n)
. - Hash search, tree search, and binary search are efficient search methods that can quickly locate target elements within specific data structures. These algorithms are highly efficient, with time complexities reaching
O(\log n)
or evenO(1)
, but they usually require extra space to accommodate additional data structures. - In practice, we need to analyze factors such as data volume, search performance requirements, data query and update frequencies, etc., to choose an appropriate search method.
- Linear search is ideal for small or frequently updated (volatile) data. Binary search works well for large and sorted data. Hash search is suitable for data that requires high query efficiency and does not need range queries. Tree search is best suited for large dynamic data that require maintaining order and need to support range queries.
- Replacing linear search with hash search is a common strategy to optimize runtime performance, reducing the time complexity from
O(n)
toO(1)
.