Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between "hill climbing" and "greedy" algorithms?

Tags:

algorithm

Please explain the difference between "hill climbing" and "greedy" algorithms.

It seems both are similiar, and I have a doubts that "hill climbing" is an algorithm; it seems to be an optimization. Is this correct?

like image 207
Yabert Yanuar Avatar asked Nov 09 '11 03:11

Yabert Yanuar


People also ask

Why is hill climbing called greedy algorithm?

Hill climbing is called a greedy algorithm because at each step it makes the locally optimal choice. It does not necessarily converge to a global maximum, but it will find a local maximum, which may or may not be close to the global one, but will likely be found in a shorter time.

What are the main differences between hill climbing search vs best first search?

Best-first search calculates the value of ALL neighboring nodes and then iterates with the best one. Simple hill climbing calculates the value of each neighbouring node in turn and iterates as soon as it finds one better than the current node.

What's the difference between greedy and heuristic algorithm?

Greedy algorithms supply an exact solution! Heuristic algorithms use probability and statistics in order to avoid running through all the possibilities and provide an "estimated best solution" (which means that if a better solution exists, it will be only slightly better).

What type of algorithm is hill climbing?

Hill Climbing is a form of heuristic search algorithm which is used in solving optimization related problems in Artificial Intelligence domain. The algorithm starts with a non-optimal state and iteratively improves its state until some predefined condition is met.


1 Answers

Hill-climbing and greedy algorithms are both heuristics that can be used for optimization problems. In an optimization problem, we generally seek some optimum combination or ordering of problem elements. A given combination or ordering is a solution. In either case, a solution can evaluated to compare it against other solutions.

In a hill-climbing heuristic, you start with an initial solution. Generate one or more neighboring solutions. Pick the best and continue until there are no better neighboring solutions. This will generally yield one solution. In hill-climbing, we need to know how to evaluate a solution, and how to generate a "neighbor."

In a greedy heuristic, we need to know something special about the problem at hand. A greedy algorithm uses information to produce a single solution.

A good example of an optimization problem is a 0-1 knapsack. In this problem, there is a knapsack with a certain weight limit, and a bunch of items to put in the knapsack. Each item has a weight and a value. The object is to maximize the value of the objects in the knapsack while keeping the weight under the limit.

A greedy algorithm would pick objects of highest density and put them in until the knapsack is full. For example, compared to a brick, a diamond has a high value and a small weight, so we would put the diamond in first.

Here is an example of where a greedy algorithm would fail: say you have a knapsack with capacity 100. You have the following items:

  • Diamond, value 1000, weight 90 (density = 11.1)
  • 5 gold coins, value 210, weight 20 (density each = 10.5)

The greedy algorithm would put in the diamond and then be done, giving a value of 1000. But the optimal solution would be to include the 5 gold coins, giving value 1050.

The hill-climbing algorithm would generate an initial solution--just randomly choose some items (ensure they are under the weight limit). Then evaluate the solution--that is, determine the value. Generate a neighboring solution. For example, try exchanging one item for another (ensure you are still under the weight limit). If this has a higher value, use this selection and start over.

Hill climbing is not a greedy algorithm.

like image 180
RobertR Avatar answered Oct 01 '22 07:10

RobertR