Home Computer Heuristic Computer Science

Heuristic Computer Science

83
0

Examples of Heuristics in Computer Science

In computer science, heuristics are “rules-of-thumb” that assist in the finding of approximate solutions to complex problems. A heuristic algorithm is used when there is too much data to sort through to find a solution quickly. Heuristics are specific to each problem because they are based upon individual rules.

Heuristics are designed to provide solutions within a short time frame and sufficient to solve the problem at hand. Although the heuristic might not provide an exact solution, it is useful as an approximate or best-guess solution. While some problems may take hundreds of thousands of years to solve, we can quickly find an approximate solution.

Heuristic trade-offs

Trade-offs are the basis of any heuristic’s value proposition. We trade accuracy for time, which is the norm. However, when creating a good heuristic, we need to use many levers.

  • Optimality Many problems can have multiple solutions. For example, “What is the best way to get from one city to another?” Is it necessary to choose the best route or is a good one sufficient?
  • Completeness Do we have to search for all possible solutions to a problem? Is it possible to find only a small number of viable solutions?
  • Accuracy Many questions aren’t clear. These situations can include, for example, “Will Tommy like a pair of boots?” A heuristic can increase accuracy.
  • Execution Time: A heuristic’s primary purpose is to give a quick and accurate answer. Some heuristics can be slightly faster than traditional methods.

Below are examples of problems and some common heuristics.

Traveling Salesperson Problem (TSP).

The TSP algorithm is well-known and has a Big O complexity of O(n). The question is:

This question is easy to answer for a small number of cities. It becomes more difficult to find a solution as cities grow in number.

This problem is solved by the heuristic of the nearest-neighbor (NN). The computer will always choose the next unvisited place on the path. Although NN may not always be the best solution, it is close enough that the difference can often be negligible to answer the TSP. This heuristic can reduce the complexity of TSP from Big-O to O(n). ) to O (n2).

Problem with Knapsack

Problem with the knapsack:

A greedy algorithm is an example of a heuristic that can be used to solve this problem. It sorts the items according to their value and weight before inserting them into the “sack”. This ensures that the most valuable items are placed in the “sack” first.

Search Optimization

Since search engines were invented, SEO has been a sought-after topic. Search engines are used by people who want to quickly find the information they need. Search engines need to use heuristics to speed up the process because there is so much information. A heuristic can attempt each option at every step at the beginning, but as it continues to search, it can stop the search at any point if the current solution is not the best. This allows the search engine to be optimized for speed, accuracy, and precision.

Applying Heuristics in Your Algorithms

You must know what you are looking for before you can apply heuristics in your algorithms. You can create rules to help you reach your goal if you know what it is. It is possible to design a heuristic to cause the knight to choose the path with the most moves. For example, if the algorithm is designed to determine how many moves a knight has on a square and 8×8 chessboard while visiting each square, it is possible to create an algorithm that does this. It may be more effective to design a heuristic to cause the knight to choose the path that has the least number of moves, as we are trying to create a particular path. Because the options are more limited, the solutions are also easier to find.

Previous articleHow to Become a Computer Programmer?
Next articleWhat is a Computer Science Degree?

LEAVE A REPLY

Please enter your comment!
Please enter your name here