B. For each method, number nodes in order on depth-3 binary tree
B. Idea of g and h
g is exact distance from root (function of node)
h is interpreted as distance left to goal (function of position only)
f=g --> BF
f = -g --> DF
f = h --> greedy
C. A* = best first search with restriction that f = g+h, plus ("admissible")
ii. h(solution) = 0 [but not necessarily vice versa]
iii. h(position) unchanging
Note that this algorithm assumes that the "Node" object incorporates the current position/state as well as f, g, h, and a pointer to the parent Node. Thus, the same position/state may appear in more than one Node, but there is no need for the more complicated A* algorithm (presented in some texts) that keeps track of the "best" packpointer for a position/state. Also note that these repeated positions are eliminated with the monotonic algorithm anyhow.
E. Example with word ladders. Perform A* search, going from HATE to LOVE, using the heuristic of the number of incorrect letters (wrt goal word), and the following dictionary: HATE, LATE, HAVE, LANE, RATE, RAVE, HIVE, PANE, LINE, RATS, RITE, ROVE, RACE, LIVE, DIVE, ROPE, LOVE. Note that some words appear in more than once place in the tree.
F. Idea of Monotonic h: F value never decreases along any path. I.e. go 1 step in direction of solution, and h decreases by at most 1. It is possible to have admissible but non-monotonic h. Benefit: 1st time a position is generated, it is the best. Introduce idea of a closed list.
A*-Monotonic(Root)
Open={Root}
Closed={}
loop
if Open={} then return failure
Node = pop(Open)
if solution(Node) then return Node
add Node to Closed
remove from Open all nodes that terminate in the same position as Node
Put new(*) children(Node) on Open
sort Open by minimum f
(*) new = positions not already on Closed
ii. Exact solution to problem with constraint(s) relaxed (Pearl)
Eg1: Manhattan Distance is exactly right if you relaxed "move to empty square" rule
Eg2: Incorrect letters is exactly right if you relax rule that intermediate "words" be legal
ii. Node only needs to point to parent position
ii. Otherwise O(BD) [worst case] but hopefully (B/K)D on average. Space problems dominate large instances.
B. (setf (aref test 0) #\b), test --> "boo"
C. COPY-SEQ: returns a copy of a string (or other sequence -- lists and strings are both sequences).
(setq Test1 "Foo")
(setq Test2 Test1) ; Test2 now points where Test1 pointed
(setq Test3 (copy-seq Test1)) ; Test3 is a whole new string
(setf (aref Test2 0) #\B)
Now, Test2 and Test1 are both "Boo" (since they both point to the same location). But changing Test3 wouldn't affect Test1/Test2.
E. (setf (gethash "boo" *Table*) t)
F. (gethash "boo" *Table*)
G. Example of hash tables:
(setq *Numerals* (make-hash-table :test #'equal))
(loop for I from 1 to 500 do
(setf (gethash (format nil "~R" I) *Numerals*)
I))
(gethash "twenty-three" *Numerals*) --> 23