Algorithms
and
Data
Structures

Spring 2021
course
site
-->

April 29

... start recording

Questions?

final project

I've put up a page describing the final project - what I'm looking for and some ideas.

finish up search discussion

We've spent several classes now discussing several "search" ideas, looking for a target solution by moving through a tree or a graph or looping over the different possibilities.

There are many variations of these ideas. You should be looking for the big ideas, and then digging into the details depending on the specific problem.

Today we'll discuss a few more ideas, then let you look into one more thoroughly for Monday.

We started discussing two player minmax games last time; I'd like to finish that discussion by describing negamaz and alpha-beta pruning, a variation which is reduces the size of the search tree.

Negamax is a way to fold the minmax algorithm into one recursive function, which essentially does the mim/max flip by multiplying by -1 at each step. So negamax() recursively calls -negamax().

You can read about alpha-beta at chessprogramming.org/Alpha-Beta and in this alpha-beta explanation with bags by Bruce Moreland, which I will summarize here :

You get to choose a bag ... your enemy chooses what to give you from that bag.
(In other words, a max/min tree.)

You look at each bag and contents right-to-left, not seeing ahead.

bag 1                        bag 2
-----                        -----
peanut butter sandwich *     $20
keys to a new car            $10
                             rotten fish *
                             (stop looking)

The "pruning" is that you stop looking in bag 2 once you see the rotten fish. You already know that if you choose bag 1, you can get a peanut butter sandwich, and know you know that if you choose bag 2, your enemy can choose the rotten fish ... so it doesn't matter what else is in bag 2 - you can already do better with bag 1.

The idea behind alpha-beta pruning is that the algorithm keeps track of this sort of "best you can do so far" for each of the two players, and that those two values are named alpha and beta. At each recursive step we use the negamax idea to flip both who's who, and the sense of what's good and bad, by swapping (alpha,beta) to (-beta,-alpha).

I have an implementation of this in this tictactoe.py code, which I will demonstrate and discuss briefly. (Note the use of python objects to represent RandomPlayer, InteractivePlayer, and SmartPlayer, each with the same getMove method, allowing different simulutions.)

aside

Usually it's too expensive to loop over all permutations ... but to find them, you can use Heap's algorith . (Named after B. R. Heap, not the data structure.)

Or you can just be a change ringer ...

SQL ?

Depending on how long all that takes, we may start to discuss SQL and relational databases ... or do that on Monday. I've added bunch of links for that topic on the resources page.

We did start discussing SQL; check out the video for what we covered.

https://cs.bennington.college /courses /spring2021 /algorithms /notes /search3
last modified Sun May 2 2021 9:34 pm