Algorithms For Dummies. John Paul Mueller
Чтение книги онлайн.

Читать онлайн книгу Algorithms For Dummies - John Paul Mueller страница 15

Название: Algorithms For Dummies

Автор: John Paul Mueller

Издательство: John Wiley & Sons Limited

Жанр: Программы

Серия:

isbn: 9781119870005

isbn:

СКАЧАТЬ The same holds true for graphics. A computer sees a series of 0s and 1s, not a graphic containing a pretty scene of the countryside.

      

It’s important to consider data from the computer’s perspective when using algorithms. The computer sees only 0s and 1s, nothing else. Consequently, when you start working through the needs of the algorithm, you must view the data in that manner. You may actually find it beneficial to know that the computer’s view of data makes some solutions easier to find, not harder. You discover more about this oddity in viewing data as the book progresses.

      Arranging data makes the difference

      Computers also have a strict idea about the form and structure of data. When you begin working with algorithms, you find that a large part of the job involves making the data appear in a form that the computer can use when using the algorithm to find a solution to an issue. Although a human can mentally see patterns in data that isn’t arranged precisely right, computers really do need the precision to find the same pattern. The benefit of this precision is that computers can often make new patterns visible. In fact, that’s one of the main reasons to use algorithms with computers — to help locate new patterns and then use those patterns to perform other tasks. For example, a computer may recognize a customer’s spending pattern so that you can use the information to generate more sales automatically.

      Considering Algorithm Design

      IN THIS CHAPTER

      

Considering how to solve a problem

      

Using a divide-and-conquer approach to solving problems

      

Understanding the greedy approach to solving problems

      

Determining the costs of problem solutions

      

Performing algorithm measurements

      An algorithm consists of a series of steps used to solve a problem, that could include input data to provide the basis of solving the problem and sometimes constraints that any solution must consider before anyone will regard the algorithm as effective. The first section of this chapter helps you consider the problem solution (the solution to the problem you’re trying to solve). It helps you understand the need to create algorithms that are both flexible (can handle a wide range of data inputs) and effective (yield the desired output).

      The second section of this chapter considers how to derive a solution. Feeling overwhelmed by a problem is common and the most common way to solve the issue is to divide the problem into smaller, manageable pieces. This divide-and-conquer approach to problem solving originally referred to warfare (see a history of this approach at https://classroom.synonym.com/civilization-invented-divide-conquer-strategy-12746.html). However, people use the same ideas to cut problems of all sorts down to size.

The third section of the chapter refers to the greedy approach to problem solving. Greed normally has a negative connotation (like stealing your friend’s fruit cup from their plate), but not in this case. A greedy algorithm is one that makes an optimal choice at each problem-solving stage. By doing so, it hopes to obtain an overall optimal solution to solve the problem. Unfortunately, this strategy doesn’t always work, but it’s always worth a try. It often yields a good enough solution, making it a good baseline.

      No matter what problem-solving approach you choose, every algorithm comes with costs. Being good shoppers, people who rely heavily on algorithms want the best possible deal, which means performing a cost/benefit analysis. Of course, getting the best deal also assumes that a person using the algorithm has some idea of what sort of solution is good enough. Getting a solution that is too precise (one that offers too much detail) or one that offers too much in the way of output is often wasteful, so part of keeping costs under control is getting what you need as output and nothing more.

      To know what you have with an algorithm, you need to know how to measure it in various ways. Measurements create a picture of usability, size, resource usage, and cost in your mind. More important, measurements offer the means of making comparisons. You can’t compare algorithms without measurements. Until you can compare the algorithms, you can’t choose the best one for a task.

      Before you can solve any problem, you must understand it. Doing so isn’t just a matter of sizing up the problem, either. Knowing that you have certain inputs and require certain outputs is a start, but that’s not really enough to create a solution. Part of the solution process is to

       Discover how other people have created new problem solutions

       Know what resources you have on hand

       Determine the sorts of solutions that worked for similar problems in the past

       Consider what sorts of solutions haven’t produced a desirable result

      The following sections help you understand these phases of solving a problem. Realize that you won’t necessarily perform these phases in order and that sometimes you revisit a phase after getting more information. The process of starting a problem solution is iterative; you keep at it until you have a good understanding of the problem at hand.

      Modeling real-world problems

      Real-world problems differ from those found in textbooks, mostly because the real world has no imagination at all. When creating a textbook, the author often creates a simple example to help the reader understand the basic principles at work. The example models just one aspect of a more complex problem. A real-world problem may require that you combine several techniques to create a complete solution. For example, to locate the best answer to a problem, you may:

      1 Need to sort the answer set by a specific criterion.

      2 Perform some sort of filtering and transformation.

      3 Search the result.

      Without this sequence of steps, comparing each of the answers adequately may prove impossible, and you end up with a less-than-optimal result. A series of algorithms used together to create a desired result is an ensemble. You can read about their use in machine learning in Machine Learning For Dummies, 2nd Edition, by John Paul Mueller and Luca Massaron (Wiley). The article at https://machinelearningmastery.com/tour-of-ensemble-learning-algorithms/ gives you a quick overview СКАЧАТЬ