PRACTICAL IMPROVEMENT: A-STAR, KD-TREE, FIBONACCI HEAP CS16: Introduction to Data Structures & Algorithms Thursday, April 10, 2014 1.

Slides:



Advertisements
Similar presentations
Numbers Treasure Hunt Following each question, click on the answer. If correct, the next page will load with a graphic first – these can be used to check.
Advertisements

Chapter 28 Weighted Graphs and Applications
Solving Systems of Linear Equations Graphically and Numerically
You have been given a mission and a code. Use the code to complete the mission and you will save the world from obliteration…
Mathematical Preliminaries
Angstrom Care 培苗社 Quadratic Equation II
Unit-iv.
1
& dding ubtracting ractions.
Copyright © 2003 Pearson Education, Inc. Slide 1 Computer Systems Organization & Architecture Chapters 8-12 John D. Carpinelli.
and 6.855J Cycle Canceling Algorithm. 2 A minimum cost flow problem , $4 20, $1 20, $2 25, $2 25, $5 20, $6 30, $
Introduction to Algorithms
and 6.855J Spanning Tree Algorithms. 2 The Greedy Algorithm in Action
We need a common denominator to add these fractions.
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
FACTORING ax2 + bx + c Think “unfoil” Work down, Show all steps.
Polygon Scan Conversion – 11b
Around the World AdditionSubtraction MultiplicationDivision AdditionSubtraction MultiplicationDivision.
David Luebke 1 6/1/2014 CS 332: Algorithms Medians and Order Statistics Structures for Dynamic Sets.
CS16: Introduction to Data Structures & Algorithms
Break Time Remaining 10:00.
Chapter 4: Informed Heuristic Search
Finding Optimal Solution of 15 puzzle B NTUCSIE Kai-Yung Chiang.
Turing Machines.
Table 12.1: Cash Flows to a Cash and Carry Trading Strategy.
PP Test Review Sections 6-1 to 6-6
Data Structures: A Pseudocode Approach with C
Abstract Data Types and Algorithms
Data Structures Using C++
ABC Technology Project
Traffic assignment.
Outline Minimum Spanning Tree Maximal Flow Algorithm LP formulation 1.
Bellwork Do the following problem on a ½ sheet of paper and turn in.
1 Undirected Breadth First Search F A BCG DE H 2 F A BCG DE H Queue: A get Undiscovered Fringe Finished Active 0 distance from A visit(A)
Exarte Bezoek aan de Mediacampus Bachelor in de grafische en digitale media April 2014.
1 Breadth First Search s s Undiscovered Discovered Finished Queue: s Top of queue 2 1 Shortest path from s.
Copyright © 2012, Elsevier Inc. All rights Reserved. 1 Chapter 7 Modeling Structure with Blocks.
Squares and Square Root WALK. Solve each problem REVIEW:
Basel-ICU-Journal Challenge18/20/ Basel-ICU-Journal Challenge8/20/2014.
1..
© 2012 National Heart Foundation of Australia. Slide 2.
The x- and y-Intercepts
Adding Up In Chunks.
Quadratic Graphs and Completing the Square
CS1022 Computer Programming & Principles
© 2010 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of CHAPTER 11: Priority Queues and Heaps Java Software Structures: Designing.
25 seconds left…...
1 hi at no doifpi me be go we of at be do go hi if me no of pi we Inorder Traversal Inorder traversal. n Visit the left subtree. n Visit the node. n Visit.
10 -1 Chapter 10 Amortized Analysis A sequence of operations: OP 1, OP 2, … OP m OP i : several pops (from the stack) and one push (into the stack)
We will resume in: 25 Minutes.
Essential Cell Biology
CSE Lecture 17 – Balanced trees
Rizwan Rehman Centre for Computer Studies Dibrugarh University
Clock will move after 1 minute
CS203 Lecture 15.
PSSA Preparation.
& dding ubtracting ractions.
Foundations of Data Structures Practical Session #7 AVL Trees 2.
Physics for Scientists & Engineers, 3rd Edition
Instructor: Shengyu Zhang 1. Content Two problems  Minimum Spanning Tree  Huffman encoding One approach: greedy algorithms 2.
How to create Magic Squares
1 Decidability continued…. 2 Theorem: For a recursively enumerable language it is undecidable to determine whether is finite Proof: We will reduce the.
Single Source Shortest Paths
Bioinformatics Programming 1 EE, NCKU Tien-Hao Chang (Darby Chang)
KD TREES CS16: Introduction to Data Structures & Algorithms Tuesday, April 7,
Project 2 Presentation & Demo Course: Distributed Systems By Pooja Singhal 11/22/
SHORTEST PATHS IN GRAPHS
KD Tree A binary search tree where every node is a
Presentation transcript:

PRACTICAL IMPROVEMENT: A-STAR, KD-TREE, FIBONACCI HEAP CS16: Introduction to Data Structures & Algorithms Thursday, April 10,

Outline A* Shortest-path Search KD-trees for Nearest Neighbor Fibonacci Heap 2 Thursday, April 10, 2014

Road Trip Thursday, April 10, ATL SF LA CLE DC PHL NYC PVD PHX STL CHI Start End 20

Road Trip Thursday, April 10, ATL SF LA CLE DC PHL NYC PVD PHX STL CHI Start End

Optimistic Estimates Thursday, April 10, ATL SF LA CLE DC PHL NYC PVD PHX STL CHI Start End 20 0 inf Optimistic estimate to End Shortest distance to Start PQ: (CHI,30) (…,inf) inf

Optimistic Estimates Thursday, April 10, ATL SF LA CLE DC PHL NYC PVD PHX STL CHI Start End inf 15 inf Optimistic estimate to End Shortest distance to Start PQ: (STL,30) (SF,40) (CLE,46) (NYC,50) (…,inf) inf

Optimistic Estimates Thursday, April 10, ATL SF LA CLE DC PHL NYC PVD PHX STL CHI Start End inf Optimistic estimate to End Shortest distance to Start PQ: (SF,35) (CLE,46) (ATL,48) (NYC,50) (DC,55) (PHL,72) (…,inf) inf

Optimistic? It’s so important for estimates to be optimistic, ie never say it’s farther than it is, so that the best path will always be taken first Important to be admissible: a heuristic that never overestimates Inadmissible heuristics don’t always return the best path Thursday, April 10,

A* (A Star) Algorithm The algorithm is as follows: Decorate all nodes with: Distance ∞, except start node, which has distance 0, Optimistic estimate of node-to-end-node distance. Add all nodes to a priority queue, with the sum of both decorations as the priority. While the priority queue isn’t empty and you haven’t expanded the destination: Remove the minimum priority node Update the decorations and priority to the removed node’s neighbors if the distances have decreased Thursday, April 10,

A* Algorithm Pseuodocode Thursday, April 10, function astar(G, s, d): //Input: Graph G with vertices V, start vertex s, and destination vertex d //Output: u.dist set to shortest distance from s to u and path saved for v in V:// Initialize vertices’ decorations v.dist = infinity // dist-from-start v.est = heuristic(v, d) // dist-from-destination estimates v.prev = null // set previous pointers to null s.dist= 0 PQ = PriorityQueue(V) // add all nodes with (v.dist + v.est) as priority while PQ not empty and PQ.getMin()!=d://haven’t reached destination curr = PQ.removeMin() for all edges (curr, v)://cost() returns edge weight if (curr.dist + cost(curr, v)) < v.dist: // if this path is shorter v.dist = curr.dist+cost(curr,v) //Update to curr’s path+weight v.prev = curr// Maintain pointers for path PQ.replaceKey(v, v.dist+v.est)

Other Applications and Heuristics What other problems do we use search to solve? Games like Chess, Go, Tic Tac Toe Dijkstras functions as BFS since the cost of all transitions are equal Heuristics can be much funkier than distance: chess could use number of your pieces on the board, sum of the values of pieces, moves until checkmate Runtime is dependent on difficulty of calculating heuristic Thursday, April 10,

1D-Tree Example – Nearest Neighbor Thursday, April 10,

1D-Tree Example – Nearest Neighbor Thursday, April 10,

2D-Tree Example Now lets sort something a little more complicated, points in the Cartesian plane. A(10, 12), B(11, 9), C(3,4), D(5,3), E(7,8), F(1, 5) Thursday, April 10,

2D-Tree Example Sort list in the 1st dimension(x) F, C, D, E, A, B Center element becomes new node. Make two new lists, everything in the left list is less than or equal to the center, everything in the right list is greater than the center. Left list: F, C, DRight list: A, B Thursday, April 10, E

2D-Tree Example Thursday, April 10, We now sort each list in the next dimension(y). F, C, D -> D, C, F A, B -> B, A Again we take the center element to be the new node Make our separate lists again. DFB E CA

2D-Tree Example Sort our lists; in the first dimension this time DFB Make our new nodes Thursday, April 10, E CA DFB

2D-Tree Example: Nearest Neighbor Thursday, April 10, X E Y C Y A X D X F X B X Y A(10, 12) B(11, 9) C(3,4) D(5,3) E(7, 8) F(1,5) G(1, 3.5)

2D-Tree Example: Nearest Neighbor Thursday, April 10, X E Y C Y A X D X F X B X Y A(10, 12) B(11, 9) C(3,4) D(5,3) E(7, 8) F(1,5) G(1, 3.5)

2D-Tree Example: Nearest Neighbor Thursday, April 10, X E Y C Y A X D X F X B X Y A(10, 12) B(11, 9) C(3,4) D(5,3) E(7, 8) F(1,5) G(1, 3.5)

NNS: Pseudocode Move down the tree recursively starting with the root. Go left or right depending on whether the point is less than or greater than the current node in the split dimension. Once you reach a leaf node, save it as the "current best" Unwind the recursion of the tree, performing the following steps at each node: o If the current node is closer than the current best, then it becomes the current best. o Check whether there could be any points on the other side of the splitting plane that are closer to the search point than the current best.  This is done by intersecting the splitting hyperplane with a hypersphere around the search point that has a radius equal to the current nearest distance. Since the hyperplanes are all axis-aligned this is implemented as a comparison to see whether the difference between the splitting coordinate of the search point and current node is less than the distance from the search point to the current best.  If the hypersphere crosses the plane, there could be nearer points on the other side of the plane, so we must move down the other branch of the tree from the current node looking for closer points, following the same recursive process.  If the hypersphere doesn't intersect the splitting plane, then we continue walking up the tree, and the entire branch on the other side of that node is eliminated. Thursday, April 10, Wikipedia

3D-Tree example and Applications Thursday, April 10, Wikipedia

Fibonacci Heap OperationBinary HeapFibonacci Heap insertlog(n)1 (amortized) decreaseKeylog(n)1 (amortized) removeMinlog(n) Thursday, April 10,

Fibonacci Heap DS: list of trees Thursday, April 10,

Fibonacci Heap DS: list of trees Thursday, April 10, insert(k, p): Add a new tree with key and priority If (p < current min): point current min at new tree decreasePri(n, p): decrease n.p if (n.p < n.parent.p): cut n from parent and make a new tree go up tree cutting marked ancestors until root or unmarked ancestor is reached mark first unmarked ancestor // note that roots are never marked

Fibonacci Heap DS: list of trees Thursday, April 10, removeMin(): use pointer to get minimum make each child a new root combineTrees() point current min at new tree

Outline A* Shortest-path Search KD-trees for Nearest Neighbor Fibonacci Heap 27 Thursday, April 10, 2014