8puzzle & Kd-tree & Boggle

Source: Internet
Author: User

8puzzle:

Using a * algorithm to solve 8-puzzle question.

1.define a state of board position

2.the number of moves made to reach the board position

3.the Previous State

Insert Initial board state, 0 moves, null previous state to priority queue.

The every time delete from priority queue the State with minimum priority, and inserts all its neibors state (those can is R Eached in one move)

Repeat the procedure until the state dequeued was goal state.

To calculate priority:there is both priority functions:

(1) Hamming priority function:the number of blocks in the wrong position, plus the number of moves made so far as get to T He state

(2) Manhatan priority function:the sum of the distances (sum of the vertical and horizontal distance) from the blocks to T Heir goal positions, plus the number of moves made so far to get to the state.

A critical optimization. After implementing Best-first Search, you'll notice one annoying feature:states corresponding to the same board Positio N is enqueued on the priority queue many times. To prevent unnecessary exploration of useless States, when considering the neighbors of a state, don ' t enqueue the NEIGHBO R if its board position are the same as the previous state.

Kd-tree:

A 2d-tree is a generalization of a BST to two-dimensional keys. The idea was to build a BST with points in the nodes, using the x-and y-coordinates of the points as key s in strictly alternating sequence.

The prime advantage of a 2d-tree over a BST are that it supports efficient implementation of range search and nearest Neigh Bor search. Each node corresponds to a axis-aligned rectangle in the unit square, which encloses all of the points in its subtree. The root corresponds to the unit square; The left and right children of the root corresponds to the other rectangles split by the x-coordinate of the at the root; And so forth.

  • Range Search.  to find all points contained in a given query rectangle, start on the root and recursively search for points in  ; both  subtrees using the following  pruning rule : If the query rectangle does not intersect the rectangle corresponding to a node, and there is no need to explore this node (or its subtrees). a subtree is searched only if it might contain a point contained in the query rectangle.
  • Nearest neighbor Search. To find a closest point to a given query point, start at the root and recursively search in both subtrees using t He following pruning rule: If the closest point discovered so far is closer than the distance between the query P Oint and the rectangle corresponding to a node, there are no need to explore this node (or its subtrees). That's, a node is searched only if it might contain a point that's closer than the best one found so far. The effectiveness of the pruning rule depends on quickly finding a nearby point. To does this, the organize your recursive method so the when there is the possible subtrees to go down, your always choose The subtree that was on the same side of the the splitting line as the query point as the first subtree to explore-the CLO Sest Point found while exploring the first subtree may enable pruning of the second subtree.

Boggle:

This section mainly uses the TRIE data structure to store a dictionary, and then uses DFS for depth-first search words in the boggle panel. One of the most important points to note is that when making pruning decisions, the trie tree node in the dictionary is not empty as the axis, to quickly abandon some unnecessary search, rather than first construct the local string, and then go back to search in the dictionary can not find, so that will save a large part of the time, It is also the key to get the full score at last.

8puzzle & Kd-tree & Boggle

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.