Merge the chapter of binary tree and searching.
|
@ -10,7 +10,6 @@ add_subdirectory(chapter_array_and_linkedlist)
|
||||||
add_subdirectory(chapter_stack_and_queue)
|
add_subdirectory(chapter_stack_and_queue)
|
||||||
add_subdirectory(chapter_heap)
|
add_subdirectory(chapter_heap)
|
||||||
add_subdirectory(chapter_hashing)
|
add_subdirectory(chapter_hashing)
|
||||||
add_subdirectory(chapter_binary_search)
|
|
||||||
add_subdirectory(chapter_tree)
|
add_subdirectory(chapter_tree)
|
||||||
add_subdirectory(chapter_searching)
|
add_subdirectory(chapter_searching)
|
||||||
add_subdirectory(chapter_sorting)
|
add_subdirectory(chapter_sorting)
|
|
@ -1 +0,0 @@
|
||||||
add_executable(binary_search binary_search.c)
|
|
|
@ -1 +1,2 @@
|
||||||
|
add_executable(binary_search binary_search.c)
|
||||||
add_executable(two_sum two_sum.c)
|
add_executable(two_sum two_sum.c)
|
|
@ -8,7 +8,6 @@ include_directories(./include)
|
||||||
add_subdirectory(chapter_computational_complexity)
|
add_subdirectory(chapter_computational_complexity)
|
||||||
add_subdirectory(chapter_array_and_linkedlist)
|
add_subdirectory(chapter_array_and_linkedlist)
|
||||||
add_subdirectory(chapter_stack_and_queue)
|
add_subdirectory(chapter_stack_and_queue)
|
||||||
add_subdirectory(chapter_binary_search)
|
|
||||||
add_subdirectory(chapter_hashing)
|
add_subdirectory(chapter_hashing)
|
||||||
add_subdirectory(chapter_tree)
|
add_subdirectory(chapter_tree)
|
||||||
add_subdirectory(chapter_heap)
|
add_subdirectory(chapter_heap)
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
add_executable(binary_search binary_search.cpp)
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
add_executable(binary_search binary_search.cpp)
|
||||||
|
add_executable(binary_search binary_search_edge.cpp)
|
||||||
add_executable(hashing_search hashing_search.cpp)
|
add_executable(hashing_search hashing_search.cpp)
|
||||||
add_executable(two_sum two_sum.cpp)
|
add_executable(two_sum two_sum.cpp)
|
||||||
add_executable(linear_search linear_search.cpp)
|
add_executable(linear_search linear_search.cpp)
|
|
@ -4,7 +4,7 @@
|
||||||
* Author: haptear (haptear@hotmail.com)
|
* Author: haptear (haptear@hotmail.com)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace hello_algo.chapter_binary_search;
|
namespace hello_algo.chapter_searching;
|
||||||
|
|
||||||
public class binary_search {
|
public class binary_search {
|
||||||
/* 二分查找(双闭区间) */
|
/* 二分查找(双闭区间) */
|
|
@ -2,7 +2,7 @@
|
||||||
// Created Time: 2022-12-05
|
// Created Time: 2022-12-05
|
||||||
// Author: Slone123c (274325721@qq.com)
|
// Author: Slone123c (274325721@qq.com)
|
||||||
|
|
||||||
package chapter_binary_search
|
package chapter_searching
|
||||||
|
|
||||||
/* 二分查找(双闭区间) */
|
/* 二分查找(双闭区间) */
|
||||||
func binarySearch(nums []int, target int) int {
|
func binarySearch(nums []int, target int) int {
|
|
@ -2,7 +2,7 @@
|
||||||
// Created Time: 2022-12-05
|
// Created Time: 2022-12-05
|
||||||
// Author: Slone123c (274325721@qq.com)
|
// Author: Slone123c (274325721@qq.com)
|
||||||
|
|
||||||
package chapter_binary_search
|
package chapter_searching
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@ -11,14 +11,14 @@ import (
|
||||||
|
|
||||||
func TestBinarySearch(t *testing.T) {
|
func TestBinarySearch(t *testing.T) {
|
||||||
var (
|
var (
|
||||||
target = 3
|
target = 6
|
||||||
nums = []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
|
nums = []int{1, 3, 6, 8, 12, 15, 23, 67, 70, 92}
|
||||||
expected = 2
|
expected = 2
|
||||||
)
|
)
|
||||||
// 在数组中执行二分查找
|
// 在数组中执行二分查找
|
||||||
actual := binarySearch(nums, target)
|
actual := binarySearch(nums, target)
|
||||||
fmt.Println("目标元素 3 的索引 =", actual)
|
fmt.Println("目标元素 6 的索引 =", actual)
|
||||||
if actual != expected {
|
if actual != expected {
|
||||||
t.Errorf("目标元素 3 的索引 = %d, 应该为 %d", actual, expected)
|
t.Errorf("目标元素 6 的索引 = %d, 应该为 %d", actual, expected)
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -4,7 +4,7 @@
|
||||||
* Author: Krahets (krahets@163.com)
|
* Author: Krahets (krahets@163.com)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package chapter_binary_search;
|
package chapter_searching;
|
||||||
|
|
||||||
public class binary_search {
|
public class binary_search {
|
||||||
/* 二分查找(双闭区间) */
|
/* 二分查找(双闭区间) */
|
|
@ -4,7 +4,7 @@
|
||||||
* Author: Krahets (krahets@163.com)
|
* Author: Krahets (krahets@163.com)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package chapter_binary_search;
|
package chapter_searching;
|
||||||
|
|
||||||
public class binary_search_edge {
|
public class binary_search_edge {
|
||||||
/* 二分查找最左一个元素 */
|
/* 二分查找最左一个元素 */
|
|
@ -24,8 +24,6 @@ let package = Package(
|
||||||
.executable(name: "deque", targets: ["deque"]),
|
.executable(name: "deque", targets: ["deque"]),
|
||||||
.executable(name: "linkedlist_deque", targets: ["linkedlist_deque"]),
|
.executable(name: "linkedlist_deque", targets: ["linkedlist_deque"]),
|
||||||
.executable(name: "array_deque", targets: ["array_deque"]),
|
.executable(name: "array_deque", targets: ["array_deque"]),
|
||||||
// chapter_binary_search
|
|
||||||
.executable(name: "binary_search", targets: ["binary_search"]),
|
|
||||||
// chapter_hashing
|
// chapter_hashing
|
||||||
.executable(name: "hash_map", targets: ["hash_map"]),
|
.executable(name: "hash_map", targets: ["hash_map"]),
|
||||||
.executable(name: "array_hash_map", targets: ["array_hash_map"]),
|
.executable(name: "array_hash_map", targets: ["array_hash_map"]),
|
||||||
|
@ -43,6 +41,7 @@ let package = Package(
|
||||||
.executable(name: "graph_bfs", targets: ["graph_bfs"]),
|
.executable(name: "graph_bfs", targets: ["graph_bfs"]),
|
||||||
.executable(name: "graph_dfs", targets: ["graph_dfs"]),
|
.executable(name: "graph_dfs", targets: ["graph_dfs"]),
|
||||||
// chapter_searching
|
// chapter_searching
|
||||||
|
.executable(name: "binary_search", targets: ["binary_search"]),
|
||||||
.executable(name: "two_sum", targets: ["two_sum"]),
|
.executable(name: "two_sum", targets: ["two_sum"]),
|
||||||
.executable(name: "linear_search", targets: ["linear_search"]),
|
.executable(name: "linear_search", targets: ["linear_search"]),
|
||||||
.executable(name: "hashing_search", targets: ["hashing_search"]),
|
.executable(name: "hashing_search", targets: ["hashing_search"]),
|
||||||
|
@ -86,8 +85,6 @@ let package = Package(
|
||||||
.executableTarget(name: "deque", path: "chapter_stack_and_queue", sources: ["deque.swift"]),
|
.executableTarget(name: "deque", path: "chapter_stack_and_queue", sources: ["deque.swift"]),
|
||||||
.executableTarget(name: "linkedlist_deque", path: "chapter_stack_and_queue", sources: ["linkedlist_deque.swift"]),
|
.executableTarget(name: "linkedlist_deque", path: "chapter_stack_and_queue", sources: ["linkedlist_deque.swift"]),
|
||||||
.executableTarget(name: "array_deque", path: "chapter_stack_and_queue", sources: ["array_deque.swift"]),
|
.executableTarget(name: "array_deque", path: "chapter_stack_and_queue", sources: ["array_deque.swift"]),
|
||||||
// chapter_binary_search
|
|
||||||
.executableTarget(name: "binary_search", path: "chapter_binary_search", sources: ["binary_search.swift"]),
|
|
||||||
// chapter_hashing
|
// chapter_hashing
|
||||||
.executableTarget(name: "hash_map", dependencies: ["utils"], path: "chapter_hashing", sources: ["hash_map.swift"]),
|
.executableTarget(name: "hash_map", dependencies: ["utils"], path: "chapter_hashing", sources: ["hash_map.swift"]),
|
||||||
.executableTarget(name: "array_hash_map", path: "chapter_hashing", sources: ["array_hash_map.swift"]),
|
.executableTarget(name: "array_hash_map", path: "chapter_hashing", sources: ["array_hash_map.swift"]),
|
||||||
|
@ -105,6 +102,7 @@ let package = Package(
|
||||||
.executableTarget(name: "graph_bfs", dependencies: ["utils", "graph_adjacency_list_target"], path: "chapter_graph", sources: ["graph_bfs.swift"]),
|
.executableTarget(name: "graph_bfs", dependencies: ["utils", "graph_adjacency_list_target"], path: "chapter_graph", sources: ["graph_bfs.swift"]),
|
||||||
.executableTarget(name: "graph_dfs", dependencies: ["utils", "graph_adjacency_list_target"], path: "chapter_graph", sources: ["graph_dfs.swift"]),
|
.executableTarget(name: "graph_dfs", dependencies: ["utils", "graph_adjacency_list_target"], path: "chapter_graph", sources: ["graph_dfs.swift"]),
|
||||||
// chapter_searching
|
// chapter_searching
|
||||||
|
.executableTarget(name: "binary_search", path: "chapter_searching", sources: ["binary_search.swift"]),
|
||||||
.executableTarget(name: "two_sum", path: "chapter_searching", sources: ["two_sum.swift"]),
|
.executableTarget(name: "two_sum", path: "chapter_searching", sources: ["two_sum.swift"]),
|
||||||
.executableTarget(name: "linear_search", dependencies: ["utils"], path: "chapter_searching", sources: ["linear_search.swift"]),
|
.executableTarget(name: "linear_search", dependencies: ["utils"], path: "chapter_searching", sources: ["linear_search.swift"]),
|
||||||
.executableTarget(name: "hashing_search", dependencies: ["utils"], path: "chapter_searching", sources: ["hashing_search.swift"]),
|
.executableTarget(name: "hashing_search", dependencies: ["utils"], path: "chapter_searching", sources: ["hashing_search.swift"]),
|
||||||
|
|
Before Width: | Height: | Size: 78 KiB After Width: | Height: | Size: 78 KiB |
Before Width: | Height: | Size: 62 KiB After Width: | Height: | Size: 62 KiB |
Before Width: | Height: | Size: 58 KiB After Width: | Height: | Size: 58 KiB |
Before Width: | Height: | Size: 57 KiB After Width: | Height: | Size: 57 KiB |
Before Width: | Height: | Size: 66 KiB After Width: | Height: | Size: 66 KiB |
Before Width: | Height: | Size: 57 KiB After Width: | Height: | Size: 57 KiB |
Before Width: | Height: | Size: 65 KiB After Width: | Height: | Size: 65 KiB |
Before Width: | Height: | Size: 56 KiB After Width: | Height: | Size: 56 KiB |
Before Width: | Height: | Size: 61 KiB After Width: | Height: | Size: 61 KiB |
Before Width: | Height: | Size: 45 KiB After Width: | Height: | Size: 45 KiB |
Before Width: | Height: | Size: 62 KiB After Width: | Height: | Size: 62 KiB |
Before Width: | Height: | Size: 55 KiB After Width: | Height: | Size: 55 KiB |
Before Width: | Height: | Size: 64 KiB After Width: | Height: | Size: 64 KiB |
Before Width: | Height: | Size: 55 KiB After Width: | Height: | Size: 55 KiB |
Before Width: | Height: | Size: 63 KiB After Width: | Height: | Size: 63 KiB |
Before Width: | Height: | Size: 55 KiB After Width: | Height: | Size: 55 KiB |
Before Width: | Height: | Size: 60 KiB After Width: | Height: | Size: 60 KiB |
Before Width: | Height: | Size: 53 KiB After Width: | Height: | Size: 53 KiB |
Before Width: | Height: | Size: 81 KiB After Width: | Height: | Size: 81 KiB |
67
mkdocs.yml
|
@ -153,29 +153,32 @@ nav:
|
||||||
- 5.2. 队列: chapter_stack_and_queue/queue.md
|
- 5.2. 队列: chapter_stack_and_queue/queue.md
|
||||||
- 5.3. 双向队列: chapter_stack_and_queue/deque.md
|
- 5.3. 双向队列: chapter_stack_and_queue/deque.md
|
||||||
- 5.4. 小结: chapter_stack_and_queue/summary.md
|
- 5.4. 小结: chapter_stack_and_queue/summary.md
|
||||||
- 6. 二分查找:
|
- 6. 散列表:
|
||||||
- 6.1. 二分查找: chapter_binary_search/binary_search.md
|
- 6.1. 哈希表: chapter_hashing/hash_map.md
|
||||||
- 6.2. 二分查找边界: chapter_binary_search/binary_search_edge.md
|
- 6.2. 哈希冲突处理: chapter_hashing/hash_collision.md
|
||||||
- 7. 散列表:
|
- 6.3. 小结: chapter_hashing/summary.md
|
||||||
- 7.1. 哈希表: chapter_hashing/hash_map.md
|
- 7. 树:
|
||||||
- 7.2. 哈希冲突处理: chapter_hashing/hash_collision.md
|
- 7.1. 二叉树: chapter_tree/binary_tree.md
|
||||||
- 7.3. 小结: chapter_hashing/summary.md
|
- 7.2. 二叉树遍历: chapter_tree/binary_tree_traversal.md
|
||||||
- 8. 树:
|
- 7.3. 二叉树数组表示: chapter_tree/array_representation_of_tree.md
|
||||||
- 8.1. 二叉树: chapter_tree/binary_tree.md
|
- 7.4. 二叉搜索树: chapter_tree/binary_search_tree.md
|
||||||
- 8.2. 二叉树遍历: chapter_tree/binary_tree_traversal.md
|
- 7.5. AVL 树 *: chapter_tree/avl_tree.md
|
||||||
- 8.3. 二叉树数组表示: chapter_tree/array_representation_of_tree.md
|
- 7.6. 小结: chapter_tree/summary.md
|
||||||
- 8.4. 二叉搜索树: chapter_tree/binary_search_tree.md
|
- 8. 堆:
|
||||||
- 8.5. AVL 树 *: chapter_tree/avl_tree.md
|
- 8.1. 堆: chapter_heap/heap.md
|
||||||
- 8.6. 小结: chapter_tree/summary.md
|
- 8.2. 建堆操作 *: chapter_heap/build_heap.md
|
||||||
- 9. 堆:
|
- 8.3. 小结: chapter_heap/summary.md
|
||||||
- 9.1. 堆: chapter_heap/heap.md
|
- 9. 图:
|
||||||
- 9.2. 建堆操作 *: chapter_heap/build_heap.md
|
- 9.1. 图: chapter_graph/graph.md
|
||||||
- 9.3. 小结: chapter_heap/summary.md
|
- 9.2. 图基础操作: chapter_graph/graph_operations.md
|
||||||
- 10. 图:
|
- 9.3. 图的遍历: chapter_graph/graph_traversal.md
|
||||||
- 10.1. 图: chapter_graph/graph.md
|
- 9.4. 小结: chapter_graph/summary.md
|
||||||
- 10.2. 图基础操作: chapter_graph/graph_operations.md
|
- 10. 搜索算法:
|
||||||
- 10.3. 图的遍历: chapter_graph/graph_traversal.md
|
- 10.1. 二分查找(New): chapter_searching/binary_search.md
|
||||||
- 10.4. 小结: chapter_graph/summary.md
|
- 10.2. 二分查找边界(New): chapter_searching/binary_search_edge.md
|
||||||
|
- 10.3. 哈希优化策略: chapter_searching/replace_linear_by_hashing.md
|
||||||
|
- 10.4. 重识搜索算法: chapter_searching/searching_algorithm_revisited.md
|
||||||
|
- 10.5. 小结: chapter_searching/summary.md
|
||||||
- 11. 排序算法:
|
- 11. 排序算法:
|
||||||
- 11.1. 排序算法: chapter_sorting/sorting_algorithm.md
|
- 11.1. 排序算法: chapter_sorting/sorting_algorithm.md
|
||||||
- 11.2. 冒泡排序: chapter_sorting/bubble_sort.md
|
- 11.2. 冒泡排序: chapter_sorting/bubble_sort.md
|
||||||
|
@ -186,16 +189,12 @@ nav:
|
||||||
- 11.7. 计数排序: chapter_sorting/counting_sort.md
|
- 11.7. 计数排序: chapter_sorting/counting_sort.md
|
||||||
- 11.8. 基数排序: chapter_sorting/radix_sort.md
|
- 11.8. 基数排序: chapter_sorting/radix_sort.md
|
||||||
- 11.9. 小结: chapter_sorting/summary.md
|
- 11.9. 小结: chapter_sorting/summary.md
|
||||||
- 12. 搜索算法:
|
- 12. 回溯算法:
|
||||||
- 12.1. 搜索算法(New): chapter_searching/searching_algorithm_revisited.md
|
- 12.1. 回溯算法(New): chapter_backtracking/backtracking_algorithm.md
|
||||||
- 12.2. 哈希优化策略: chapter_searching/replace_linear_by_hashing.md
|
- 12.2. 全排列问题(New): chapter_backtracking/permutations_problem.md
|
||||||
- 12.3. 小结: chapter_searching/summary.md
|
- 12.3. N 皇后问题(New): chapter_backtracking/n_queens_problem.md
|
||||||
- 13. 回溯算法:
|
- 13. 附录:
|
||||||
- 13.1. 回溯算法(New): chapter_backtracking/backtracking_algorithm.md
|
- 13.1. 编程环境安装: chapter_appendix/installation.md
|
||||||
- 13.2. 全排列问题(New): chapter_backtracking/permutations_problem.md
|
- 13.2. 一起参与创作: chapter_appendix/contribution.md
|
||||||
- 13.3. N 皇后问题(New): chapter_backtracking/n_queens_problem.md
|
|
||||||
- 14. 附录:
|
|
||||||
- 14.1. 编程环境安装: chapter_appendix/installation.md
|
|
||||||
- 14.2. 一起参与创作: chapter_appendix/contribution.md
|
|
||||||
- 参考文献:
|
- 参考文献:
|
||||||
- chapter_reference/index.md
|
- chapter_reference/index.md
|
||||||
|
|