暴力破解(Brute Force)
简介(Introduction)
Brute force is a very general problem-solving technique that consists of systematically enumerating all possible candidates for the solution and checking whether each candidate satisfies the problem’s statement.
Here, we talk about some algorithms based on brute force technique.
字符串匹配(String matching)
function StringMatching(p, t)
for i ← 0 to n − m do
j ← 0
while j < m and p[j] = t[i + j] do
j ← j + 1
if j = m then
return i
return −1
最近点对(Closest Pair)
function ClosestPair()
min ← ∞
for i ← 0 to n − 2 do
for j ← i + 1 to n − 1 do
d ← sqrt((xi − xj)^2 + (yi − yj)^2)
if d < min then
min ← d
p1 ← i
p2 ← j
return p1, p2
最后再说两句(PS)
Selection sort and graph traversal are also based on brute force technique.
Brute force is simple, easy to program and widely applicable. But in generally it is suitable for small size problem.
Welcome questions always and forever.
6942

被折叠的 条评论
为什么被折叠?



