A brute force algorithm doesn't follow any design patterns. It often takes the form of the most simple solution to implement, but might not be very efficient.
Pros:
Cons:
A greedy algorithm is something that makes a sequence of decisions, and never reconsiders decisions that have been made already.
You must show that the locally optimal decision leads to a globally optimal solution.
Pros:
Cons:
Let's say you're looking at sorting. A brute force solution: you could create all the permutations, and see which one is sorted.
Another approach to sorting leads to a better solution. You could find the smallest item, move to the first location ( operations), and then find the next smallest item and move it to the second location ( operations), and leave the largest item in the final location. This is selection sort.
Bubble sort is an example of a greedy approach to sorting.
Divide a problem solution into two (or more) smaller problems, preferably of equal size. This is often recursive, and often involve a factor. Why? Dividing it brings an expectation of a log somewhere in the results.
Pros:
Cons:
Let's start with a smallest subdomain possible. Then, combine increasingly larger subdomains until size = n. An example of this is merge sort.
Remembers partial solutions when smaller instances are related. It solves the small instances first, stores the results, and looks them up when needed.
Pros:
Cons:
Constraint Satisfaction problems:
With these problems, you could stop early.
Optimization problem: Constraint problem with objective function to maximize/minimize
Definition: systematically consider all possible outcomes of each decision, but prune searches that do not satisfy the constraints
Can a graph be colored with four colors? To do this, assign colors to vertices such that no two vertices connected by an edge have the same color. Some graphs can be 4-colored, and some cannot.
Start with some vertex on a graph of 5 vertices. It has to be colored. Suppose you pick vertex A, then B, then C, then D, etc. Let's say you color A the color 1. You never have to consider the graph where vertex A is colored anything else. The choice of one color does not matter. You've just reduced the search space from to 4^4$$. A little bit better.