what exactly is the brute force algorithm [closed] - algorithm

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this question
what exactly is the brute force algorithm? (besides just the approach only)
when a problem can use brute-force approach, and when not to?
What characteristics are there in an algorithm, when the algorithm uses brute force approach?

1 and 3 : Brute force means that you will go through all possible solutions extensively. For example, in a chess game, if you know you can win in two moves, the brute force will go through all possible combination of moves, without taking anything in consideration. So the little pawn in the back that cannot influence the outcome will still be considered.
2 : As you consider everything, the problem quickly goes out of control. Brute force through 15 moves in chess is impossible because of combinatorial explosion (too many situations to consider). However, more clever algorithms that take into account "knowledge about the problem" can go much further (20-30 moves ahead)
Edit : To clarify, brute force is simplest (dumbest?) way to explore the space of solutions. If you have a problem is set in a countable space (chess moves are countable, passwords are countable, continuous stuff is uncountable) brute force will explore this space considering all solutions equally. In the chess example, you want to checkmate your opponent. This is done via a sequence of moves, which is countable. Brute force will go through all sequence of moves, however unlikely they may be. The word unlikely is important, because it means that if you have knowledge about your problem (you know what is unlikely to be the solution, like sacrificing your queen), you can do much better than brute force.

Related

What is the time complexity of A* search [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 5 years ago.
Improve this question
I'm new to stack overflow, but I'm here because I've searched everywhere and can't seem to find much info on the time complexity of A*, besides off the wiki. I would also like to compare it to Dijkstra's algorithm and see how adding a heuristic in A* improves it's performance.
I know it's a very advanced topic, but I just can't fully understand it from the info given on wiki (Even the analysis of Dijkstra's algorithm on wiki seems quite advanced).
https://en.wikipedia.org/wiki/Dijkstra%27s_algorithm
https://en.wikipedia.org/wiki/A*_search_algorithm
I would greatly appreciate it if anyone could explain the time complexity in more detail, or suggest any reading / learning material on the topic. I do have a good understanding of the A* algorithm, but I've just started learning the analysis thereof now.
The answer is simply it depends. A star by itself is no complete algorithm. A star is Dijkstra with a heuristic that fulfills some properties (like triangle inequality). You can select different heuristic functions that lead to different time complexities. The simplest heuristic is straight line distance. However there is also more advanced stuff like landmarks heuristic for example.
In the worst case you always need to explore the whole neighborhood so you won't get better than Dijkstra from a general point of analysis.
However in most practical applications you can achieve much better bounds.
This is only when you know some properties of your graph and of your heuristic function. You then can make some assumptions which lead to a better complexity, but only for those instances.
For example if you know that the straight line distance is always the correct distance in your graph and you use a straight line distance heuristic, then your A star will have the best possible complexity with Theta(1). However this is a much to strong assumption for most applications. But you can think of where this goes.
The bottom line is: It extremely depends on the structure of your graph and your heuristic function.
Here's a lecture on A star as you ask for learning material: Efficient Route Planning (A*, Landmarks, Set Dijkstra) - University of Freiburg
There is also much on the internet, the algorithm is pretty popular as it is very easy to implement and for most cases already fast enough (non-complex games for example).

For TSP, how does Held–Karp algorithm reduce the time complexity from Brute-force's O(n!) to O(2^n*n^2)? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I have hard time to grasp the key idea of Held-Karp algorithm, how does it reduce the time-complexity?
Is it because it uses Dynamic programming so that time is saved by getting the intermediate result from the cache or because it removes some paths earlier in the calculation?
Also, is it possible to use 2 dimension table to show the calculation for
a simple TSP problem(3 or 4 cities)?
The dynamic programming procedure of the Held–Karp algorithm takes advantage of the following property of the TSP problem: Every subpath of a path of minimum distance is itself of minimum distance.
So essentially, instead of checking all solutions in a naive "top-down", brute force approach (of every possible permutation), we instead use a "bottom-up" approach where all the intermediate information required to solve the problem is developed once and once only. The initial step is the very smallest subpath. Every time we move up to solve a larger subpath, we are able to look up the solutions to all the smaller subpath problems which have already been computed. The time savings come because all of the smaller subproblems have already been solved and these savings compound exponentially (at each greater subpath level). But no "paths are removed" from the calculations–at the end of the procedure all of the subproblems will have been solved. The obvious drawback is that a very large memory size may be required to store all the intermediate results.
In summary, the time savings of the Held–Karp algorithm follow from the fact that it never duplicates solving the solution to any subset (combination) of the cities. But the brute force approach will recompute the solution to any given subset combination many times (albeit not necessarily in consecutive order within a given overall set permutation).
Wikipedia contains a 2D distance matrix example and pseudocode here.

How can you compute the smallest number of queens that can be placed to attack each uncovered square? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
This is a variant question from the Elements of Programming Interviews and doesn't come with a solution.
How can you compute the smallest number of queens that can be placed to attack each uncovered square?
The problem is about finding a minimal dominating set in a graph (the queen graph in your case http://mathworld.wolfram.com/QueenGraph.html), this more general problem is NP-Hard. Even if this reduction (on this specific kind of graphs) is unlikely to be NP-Hard, you may expect to not be able to find any efficient (polynomial) algorithm and indeed as up today nobody find one.
As an interview question, I think an acceptable answer would be a backtracking algorithm. You can add small improvements like always stop the search if you already put (n-2)-queens on the board.
For more information and pseudo-code of the algorithm and also more sophisticated algorithms I would suggest to read:
Fernau, H. (2010). minimum dominating set of queens: A trivial programming exercise?. Discrete Applied Mathematics, 158(4), 308-318.
http://www.sciencedirect.com/science/article/pii/S0166218X09003722
The simplest way is probably exhaustive searching with 1,2,3... queens until you find a solution. If you take the symmetries of the board into account you will only need ~10^6 searches to confirm that 4 queens is not enough (at that point you could use the same search until you find a solution for 5 queens or alternately, use a greedy algorithm for 5 queens to find a solution faster).

Why are heuristics proposed? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I have a small confusion with the nature of heuristics.
We know that heuristics need not give correct outputs for all input instances.
But then, why are heuristics proposed??
Heuristics are used to trade off performance (usually execution speed, but also memory consumption) with potential accuracy or generality. For example, your anti virus software uses heuristics to characterize what a virus might look like, and can take advantage of that piece of information to determine which files it should spend more time analyzing. A good heuristic has the property that it can save substantial time with minimal cost.
In graph traversal theory, a heuristic for an A* search algorithm need not be perfect. It just needs to have a predicted cost function h(x) that is less than or equal to the true cost to the goal state in order to guarantee an optimal solution. The closer h(x) equals the true cost, the quicker an optimal solution will be found.
Let me give you an example which might help you understand the importance of heuristics.
In Artificial Intelligence, search problems are mainly classified as blind search and directed search. Blind search is where you make use of algorithms such as BFS and DFS and there is a reason they are called blind search, they don't have any knowledge about the direction you should go, you just have to explore and explore until you reach the goal node, imagine the time and space complexity for those algorithms.
Now if you look at the directed search algorithm such as A*, where you have some kind of heuristic function or in simple terms an assumption about which direction you should take the next step.
Although heuristics does not guarantee the best result but rather will try to give you a better solution and sometimes even the best. There are so many classes of problems (Ex. games you play) where a better solution does the task rather than wasting so much time and space in finding the best solution.
I hope it helps.

Are all brute force algorithms exponential? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
Every example I have seen of brute force algorithm has exponential run time.
Is this a strict rule, i.e. are all brute force algorithms exponential in run time?
No, certainly not. Consider a linear search algorithm to search a sorted array. You can do better, but a linear search could be considered "brute force".
See https://en.wikipedia.org/wiki/Brute-force_search for further examples and explanation. A relevant quote from that page:
While a brute-force search is simple to implement, and will always find a solution if it exists, its cost is proportional to the number of candidate solutions - which in many practical problems tends to grow very quickly as the size of the problem increases.
Nope. You can also do worse.
Example, finding the shortest tour (travelling salesman) using brute force is Omega(n!), which is not exponential.

Resources