



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Minimax is an algorithm that allows a computer to calculate the best move to make in a game, assuming the opponent plays optimally.
Typology: Lecture notes
1 / 5
This page cannot be seen from the preview
Don't miss anything!




a) What is the pre-order traversal of the tree? Solution: 6 4 2 1 5 9 8 7
b) What is the post-order traversal of the tree? Solution: 1 2 5 4 7 8 9 6
c) What is the in-order traversal of the tree? Solution: 1 2 4 5 6 7 8 9
d) What is the breadth-first traversal of the tree? Solution: 6 4 9 2 5 8 1 7
Provide the best case and worst case runtimes in theta notation in terms of N, and a brief justification for the following operations on a binary search tree. Assume N to be the number of nodes in the tree. Additionally, each node correctly maintains the size of the subtree rooted at it. [Taken from Final Summer 2016]
boolean contains(T o); //Returns true if the object is in the tree
Solution: Best: Θ(1) Why: If the object is at the root.
Worst: Θ(N) Why: If the object is at the leaf of a spindly tree.
void insert(T o); //Inserts the given object.
Solution: Best: Θ(1) Why: One example may be inserting to the left child of the root of a right leaning spindly tree.
Worst: Θ(N) Why: One example may be inserting to the leaf node of a right leaning spindly tree.
T getElement(int i); //Returns the ith smallest object in the tree.
Solution: Best: Θ(1) Why: One example may be if i = 1 and the tree is a very spindly right leaning tree.
Worst: Θ(N) Why: One example may be if i = N and the tree is a very spindly right leaning tree.
Assume we have some binary search tree, and we want to prune it so that all values in the tree are between L and R, inclusive. Fill out the method below that takes in a BST, as well as L and R, and returns the pruned tree. Note that the root of the original tree might not be between L and R, so make sure you return the root of the new pruned tree.
class BST { int label; BST left; // null if no left child BST right; // null if no right child }
public BST pruneBST(BST root, int L, int R) { if (root == null) { return null; } else if (root.label < L) { return pruneBST(root.right, L, R); } else if (root.label > R) { return pruneBST(root.left, L, R); } root.left = pruneBST(root.left, L, R); root.right = pruneBST(root.right, L, R); return root; }
Consider the game tree below. The upside down triangles represent minimizer nodes and the normal trian- gles represent maximizer nodes.
Here is a very nice step-by-step walkthrough of traversing and updating the values of nodes in a game tree, prepared by CS188 at Berkeley: https://www.youtube.com/watch?v=xBXHtz4Gbdo
Solution: Minimax is, assuming you can generate the full tree, guaranteed to be optimal. However, it
is a pessimistic algorithm because of the assumptions it makes regarding its opponent. Since 3-year- olds are not masters of strategy, we might want to opt for a potentially riskier move that has a chance of a higher reward if our opponent makes a suboptimal move. So, it is definitely possible to win in less moves if the opponent makes suboptimal moves.