0% found this document useful (0 votes)
21 views7 pages

Algorithmic Strategies

The document discusses two algorithmic strategies: brute force and greedy algorithms. Brute force methods solve problems by trying every possible solution, exemplified by unlocking a padlock or solving the traveling salesman problem, but are often inefficient. Greedy algorithms make locally optimal choices at each step to achieve a globally optimal solution, with advantages in ease of creation and runtime analysis, but challenges in proving correctness.

Uploaded by

litlit6677
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views7 pages

Algorithmic Strategies

The document discusses two algorithmic strategies: brute force and greedy algorithms. Brute force methods solve problems by trying every possible solution, exemplified by unlocking a padlock or solving the traveling salesman problem, but are often inefficient. Greedy algorithms make locally optimal choices at each step to achieve a globally optimal solution, with advantages in ease of creation and runtime analysis, but challenges in proving correctness.

Uploaded by

litlit6677
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Algorithmic Strategies

Brute Force Method


Brute Force Algorithms are exactly what they sound like–
straightforward methods of solving a problem that rely on
sheer computing power and trying every possibility
rather than advanced techniques to improve efficiency.
• For example, imagine you have a small padlock with 4
digits, each from 0-9. You forgot your combination, but
you don't want to buy another padlock. Since you can't
remember any of the digits, you have to use a brute
force method to open the lock.
• So you set all the numbers back to 0 and try them one
by one: 0001, 0002, 0003, and so on until it opens. In
the worst case scenario, it would take 104, or 10,000
tries to find your combination.
• A classic example in computer science is the traveling
salesman problem (TSP). Suppose a salesman needs to
visit 10 cities across the country. How does one
determine the order in which those cities should be
visited such that the total distance traveled is
minimized?
• The brute force solution is simply to calculate the total
distance for every possible route and then select the
shortest one. This is not particularly efficient because it
is possible to eliminate many possible routes through
clever algorithms.
• The time complexity of brute force is O(mn), which is
sometimes written as O(n*m) . So, if we were to search
for a string of "n" characters in a string of "m"
characters using brute force, it would take us n * m
tries.
Greedy Algorithms
• A greedy algorithm always makes the choice that looks best at the
moment. That is, it makes a locally optimal choice in the hope that this
choice will lead to a globally optimal solution.
• A greedy algorithm, as the name suggests, always makes the choice
that seems to be the best at that moment. This means that it makes a
locally-optimal choice in the hope that this choice will lead to a globally-
optimal solution.
How do you decide which choice is optimal?
• Assume that you have an objective function that needs to be optimized
(either maximized or minimized) at a given point. A Greedy algorithm
makes greedy choices at each step to ensure that the objective function
is optimized. The Greedy algorithm has only one shot to compute the
optimal solution so that it never goes back and reverses the decision.
• Greedy algorithms have some advantages and disadvantages:
1.It is quite easy to come up with a greedy algorithm (or even
multiple greedy algorithms) for a problem.
2.Analyzing the run time for greedy algorithms will generally be
much easier than for other techniques (like Divide and conquer). For
the Divide and conquer technique, it is not clear whether the technique
is fast or slow. This is because at each level of recursion the size of
gets smaller and the number of sub-problems increases.
3.The difficult part is that for greedy algorithms you have to work
much harder to understand correctness issues. Even with the
correct algorithm, it is hard to prove why it is correct. Proving that a
greedy algorithm is correct is more of an art than a science. It involves
a lot of creativity.

You might also like