15.04.2018 Views

programming-for-dummies

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Taking Action on Trees 389<br />

10<br />

8<br />

12<br />

4<br />

9<br />

11<br />

19<br />

8<br />

Removing a sub-tree can leave<br />

remaining nodes disconnected from<br />

the rest of the tree.<br />

4 9<br />

19<br />

Figure 5-14:<br />

Pruning<br />

a tree<br />

removes<br />

two or more<br />

nodes from<br />

a tree.<br />

4<br />

8<br />

9<br />

19<br />

or 4<br />

9<br />

The computer might use a tree data structure to represent all possible<br />

moves when the root node represents one possible move. Then each alternating<br />

level in the tree represents the possible human responses and the<br />

best possible computer responses, as shown in Figure 5-16.<br />

8<br />

19<br />

Book III<br />

Chapter 5<br />

Graphs and Trees<br />

By organizing possible moves in a tree, a computer can determine the best<br />

possible move to make that will give its human opponent the worst possible<br />

moves later. This strategy is min-max — the computer minimizes the<br />

human’s best possible moves and maximizes its own best moves.<br />

Despite having to create trees out of other data structures (such as linked<br />

lists) and being more complicated to create and manage than other data<br />

structures, trees are one of the most useful and flexible data structures<br />

available.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!