Data Structures in Java
Session 24 Instructor: Bert Huang http://www.cs.columbia.edu/~bert/courses/3134
Data Structures in Java Session 24 Instructor: Bert Huang - - PowerPoint PPT Presentation
Data Structures in Java Session 24 Instructor: Bert Huang http://www.cs.columbia.edu/~bert/courses/3134 Announcements Homework 6 due Dec. 10, last day of class Final exam Thursday, Dec. 17 th , 4-7 PM, Hamilton 602 (this room) same
Session 24 Instructor: Bert Huang http://www.cs.columbia.edu/~bert/courses/3134
Hamilton 602 (this room)
Artificial Intelligence:
with algorithms that behave intelligently
agent
percepts
for its agents, so games are a nice starting point
we can take some time to compute a good decision at each turn
represented as game trees
turn
whole tree, make decisions based on the subtrees
X X X X O X O X O X O X O X O X X X O X X O X O X X O O X X O O X X X O O X X O X O X X X O O X
the optimal strategy via the minimax algorithm
move at the next level. Use that result to decide which move is optimal at current level.
Result
Our Turn
Win Lose Win Win Lose Win
Result
Our Turn
+100
+1 +2
+1
propagate information up
use heuristic measures
squares
see a subtree that can't possibly be better than one we saw earlier
trees too
to children states
efficiently
8 5 3 2 1 4 6 7 8 5 3 2 1 4 6 7 8 5 3 2 1 6 7 4 8 5 3 2 1 4 6 7 8 5 3 2 4 6 1 7 8 5 3 2 1 4 6 7 8 5 3 2 1 6 7 4 8 5 2 1 3 6 7 4 8 5 3 2 1 4 6 7
knowledge, we are guessing arbitrarily
the next state to try according to heuristic
distance from maze goal
compute exactly, and often there is insufficient information to make an exact decision
is using graphs to represent probabilistic independence
probability of both flips landing heads?
lands heads, we flip a second coin. What is the probability of two heads?
computation by taking advantage of independence
Subway runs Rain Cloudy Construction
Topological sort:
incoming neighbors have been computed
settings
mostly 2nd half.
(heaps)
Shortest Paths, Spanning Tree
have the following definitions:
cf(N) bounds T(N)
T(N) = O(f (N)) ← T(N) ≤ cf (N) T(N) = Ω(g(N)) ← T(N) ≥ cg(N) T(N) = Θ(h(N)) ← T(N) = O(h(N)) T(N) = Ω(h(N))
first-served
modular arithmetic
list tactic
children
T Data; Collection<TreeNode<T>> myChildren; }
preorder(node x) print(x) for child : myChildren preorder(child)
postorder(node x) for child : myChildren postorder(child) print(x)
T element; BinaryNode<T> left; BinaryNode<T> right; }
inorder(x.left) print(x) inorder(x.right)
searching by key
Keys in left subtree are less than root. Keys in right subtree are greater than root.
10 8 15 3 12 9
into right subtree, if lesser, insert into left subtree
if (t == null) return new Node(x) if (x > t.key), then t.right = insert(x, t.right) if (x < t.key), then t.left = insert(x, t.left) return t
10 8 15 3 12 9
if (t.left == null) return t.key else return findMin(t.left)
if (t == null) return false if (x == t.key) return true if (x > t.key), then return search(x, t.right) if (x < t.key), then return search(x, t.left)
removing a node with
grandchildren are easy
grandchildren?
10 8 15 3 12 9
from the right subtree
t.key = a.key;
node in right subtree remove(a.key, t.right)
10 8 15 3 12 9 root
close to log N
For each node, all keys in its left subtree are less than the nodeʼs and all keys in its right subtree are greater. Furthermore, the height of the left and right subtrees differ by at most 1
violates the AVL property,
the root.
rotation.
b a 3 1 2
b a 3 1 2
b a 3 1 2
right-left)
b a 1 c 2 3 4
b a 1 c 3 2 4
b a 1 c 3 2 4
b a 1 c 2 4 3
search tree property
that node the new root of the tree
more spread out
rotation
and there are two cases
left child (or left-right)
a b c w x y z a b c w x y z
strategy like AVL trees
weʼll compare this to single-rotation
a b c y w x z a b c y w x z
smallest key
smallest key
properties
all nodes are full*
any node is smaller than its children
A B C
A < B A < C C ? B
constant speedup)
bottom level
and repeat
creating a hole
child and repeat
reverse level-order
percolateDown(i)
specific sections (i.e., which to skip)