Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

07 Kdtrees

Download as pdf or txt
Download as pdf or txt
You are on page 1of 17

BST Range Search!

T:
Instead of finding an exact match,
find all items whose keys fall k!
between a range of values, e.g.,
between m and z, inclusive! d! p!
!
Example applications:!
Lecture 7: BST Range Search! a! f! m! z!
k-d Trees!
Binary Space Partitioning Trees! l! n!
Nearest-Neighbor Search!

BST Range Search: Algorithm! BST Range Search: Example! results:!

z!
searchrange, subtreerange!
void! n!
rangesearch(T, [m-z], [a-z], results)!
rangesearch(Link root, Key searchrange[],
 (T’s range is “whole universe”)! m!
Key subtreerange[], List results)! is k in [m-z]?! [a-z]
! p!
does [a-j] overlap [m-z]?! T: k!
1.  if root is in search range," T: does [l-z] overlap [m-z]?!
add root to results! k! search p’s subtree! [a-j] [l-z]
is p in [m-z]? results p!
2.  compute range of left subtree! d! p!
does [l-o] overlap [m-z]?!
3.  if search range covers all or" d! p! search m’s subtree! [l-o] [q-z]
part of left subtree, search left! is m in [m-z]? results m!
4.  compute range of right subtree! does [l-l] overlap [m-z]?! a! f! m! z!
5.  if search range covers all or" a! f! m! z! does [n-o] overlap [m-z]?! [l-l] [n-o]
part of right subtree, search right! search n’s subtree!
is n in [m-z]? results n! l! n!
6.  return results! does [q-z] overlap [m-z]?!
l! n!
! search z’s subtree!
(Other traversal orders are also ok)! is z in [m-z]? results z!
BST Range Search: Support Functions! BST Range Search: Other Details !
1.  if root is in search range, i.e.,!
root->key <= searchrange[MAX], and! How to express range when the keys are floats?!
root->key >= searchrange[MIN]! •  be careful with numerical precision and floating point
add node to results! errors [one of this week’s discussion topic]!
!
2.  compute subtree’s range: replace upper (lower) bound How to support duplicate keys?!
of left (right) subtree’s range by root->key-1 (+1)! •  be consistent about using ≤ or <"
•  if ≤, the range for the left subtree would be closed, e.g.,
3.  if search range covers all or part of subtree’s range," [–∞, 0], and the range for the right subtree half open,
search subtree! e.g., (0, +∞]!
•  each subtree covers a range of key values!
•  compute overlap between subtree’s range and search range!
•  no overlap if either"
searchrange[MAX] < subtreerange[MIN] or

searchrange[MIN] > subtreerange[MAX]!

Multidimensional Search! k-d Trees!


A k-d tree is a binary search tree (not covered in
Example applications:! textbook, link to original 1975 paper on syllabus)!

! At each level of the k-d tree, keys from a different search


! dimension is used as the discriminator!
! •  keys for any given level are all from the same dimension indicated by
the discriminator!
! •  nodes on the left subtree of a node have keys with value < the
! node’s key value along this dimension!
A k-d tree can handle all these queries with O(log n) •  nodes on the right subtree have keys with value > the node’s key
value along this dimension!
insert and search times (it can also handle partial,
range, and approximate matches)! We cycle through the dimensions as we go down the tree!
•  for example, given keys consisting of x- and y-coordinates, level 0
could discriminate by the x-coordinate, level 1 by the y-coordinate,
level 2 again by the x-coordinate, etc.!
k-d Trees: Example! k-d Tree Insert!
void kdTree::!
Given points in a Cartesian plane on the left," insert(Link &root, Item newitem, int disc)!
{!
a corresponding k-d tree is shown on the right! if (root == NULL) {!
disc! root = new Node(newitem);!
y return;!
E(40, 85)! G(70, 85)!
T: A! x!
}!
! if (newitem.key[disc] < root->item.key[disc]) // or <=!
B(10, 70)! insert(root->left, newitem, (disc+1)%dim);!
B! C! y! else if (newitem.key[disc] > root->item.key[disc])!
H(30, 60)!
! insert(root->right, newitem, (disc+1)%dim);!
A(50, 50)!
}!
D! E! F! G! x!
! If new item’s key is smaller than root’s along the dimension
! indicated by the discriminator, recursive call on left subtree!
C(80, 15)!
D(25, 20)! H! y! else recursive call on right subtree!
F(60, 10)!
x In both cases, switch the discriminator before traversing"
0 100 the next level of the tree, cycling through the dimensions!

k-d Tree Search! k-d Tree Remove!


To remove a node on a level with
Search works similarly to insert, using a discriminator along dimension j:!
discriminator to cycle through the dimensions as • if the node is a leaf, remove it!
one recurses down the levels: O(log n) time! • else if node has right subtree,"
find the j-minimum node in the right subtree!
The tree we built was nicely balanced!
• replace node with j-minimum node and repeat
• if nodes are inserted randomly, on average we will get a until you reach a leaf, then remove the leaf!
balanced tree: O(log n) time!
• else find the j-maximum node in the left subtree,
• if nodes inserted are sorted, recursively insert the median replace, repeat, remove!
of the range to build a balanced tree: O(n log n) time!
• j-minimum means minimum along the j dimension,
analogously j-maximum!
•  O(log n) time!
k-d Tree Remove Example! k-d Tree Remove Example!
delete (35,60)!
35,60! x! 50,30! x! 50,30! x! 50,30! x!

20,45! 60,80! y! 20,45! 60,80! y! 20,45! 60,80! y! 20,45! 60,80! y!

10,35! 80,40! x! 10,35! 80,40! x! 10,35! 80,40! x! 10,35! 80,40! x!

20,20! 50,30! 90,60! y! 20,20! 50,30! 90,60! y! 20,20! 50,30! 90,60! y! 20,20! 60,20! 90,60! y!

60,20! x! replacement! x! 60,20! replacement! x! 60,20! replacement! x! 60,20! replacement!


x-minimum! y-maximum! y-maximum! x-minimum!
70,10! y! y! 70,10! y! 70,10! y! 70,10!
delete (50,30)!

k-d Tree Remove Example! k-d Tree Remove Summary!


delete (35,60)!
50,30! x! 50,30! x! 35,60! x! 50,30! x!

20,45! 60,80! y! 20,45! 60,80! y! 20,45! 60,80! y! 20,45! 60,80! y!

10,35! 80,40! x! 10,35! 80,40! x! 10,35! 80,40! x! 10,35! 80,40! x!

20,20! 60,20! 90,60! y! 20,20! 60,20! 90,60! y! 20,20! 50,30! 90,60! y! 20,20! 60,20! 90,60! y!

x! 60,20! x! 70,10! leaf node, can 60,20! x! x! 70,10!


replacement! be deleted!
y! 70,10! 70,10! 70,10! y!
delete (60,20)!
Multidimensional Range Search! k-d Tree Range Search!
void!
Example applications:! kdTree::rangesearch(Link root,int disc,

Key searchrange[],

Key subtreerange[], List results)!
•  cycle through the dimensions as we traverse down the tree,
same as with kdTree::insert()!
What would the kdTree::rangesearch()" •  searchrange[] holds 2 values (min, max) per dimension!
function signature be?! •  subtree’s ranges are defined for all dimensions!
•  What are its formal arguments?! •  for 2D, both searchrange[] and"
•  What would it return?! subtreerange[] define a rectangle!
•  for dimension j’s range, subtreerange[2*j] holds the lower bound,
subtreerange[2*j+1] holds the upper bound"
these need to be updated as we go down the levels!

Example: Binary Space Axis-Aligned BSP Tree: Idea!


Partitioning (BSP) Trees! Splitting plane aligned to x, y, or z axis!

Axis-aligned BSP tree: a k-d tree used for spatial


Minimal! Split along!
range search, with the following distinctions:! box! plane!
•  items are stored in leaf nodes only!
•  other internal nodes store only the coordinates used to
partition space!
•  an item that spans multiple partitions are stored in all
corresponding leaf nodes!

Example usages:! Split along! Split along!


• occlusion culling and collision detection in computer plane! plane!
graphics, computer games, robot motion planning!

Tomas Akenine-Mőller © 2002!


Axis-Aligned BSP Tree: Build! Example Use: Collision Detection!
B D E Blue wants to get to

Plane 2
0 object e! a
f

b
1a 1b
Plane 1a
Plane 1b Blue draws a straight line
Plane 0

from itself to e! g
A B C 2
A C Now it needs to know d
c

which objects in the room


e
D E h
could potentially obstruct
it if it follows this straight m

line! j

Each internal node holds a divider plane! What is the brute force
l

Leaves hold geometry!


k
way of finding potentially i n

obstructing objects?!

Tomas Akenine-Mőller © 2002!

Collision Detection with BSP! Collision Detection with BSP!


Algorithm:! x=30 x=52
3 x=30 x=52
In this case, we use:!
1
1 3
C
• use a plane to divide a
A B f
4
A B f C
x=30, y=30, x=52, y=45!
space into 2 parts! b x=45
y=45" a
b
4
x=45
y=45" with the resulting BSP:!
• objects whose j- D
1
x=30
1 1
x=30 x=30
1
x=30
1
x=30
D
coordinate is smaller than g
g
that of the partition go to d
c
c A A A 2 A2
2 2 2
e d y=30 A y=30 y=30 y=30 y=30
the left subtree! h
e a, b , g
h, i, j, k
a, b , g a, b , g a, b , g
h, i, j, kh, i, j, k h, i, j, k
a, b , g
h, i, j, k
h
• objects with j-coordinate 3
x=52
3E
x=52
l
3
x=52
E3
x=52
l
E 3
l x=52
E
l
E
l
m 2
larger than the partition’s j E
y=30 m 2 n n n n n

y=30
go to the right subtree! l
j E
B B4 B
d
B4 4B
y=45
d
4 4
y=45
d y=45
d y=45
d y=45
l
• repeat for the two k
k
partitions, cycling through i n
i n
C
f
D
c
C
f
C D
f c
CD
fc
C
D
fc
D
c

the coordinates! e
m
e
m
e
m
e
m
e
m
Collision Detection with BSP! Collision Detection with BSP!
x=30 x=52
1 1 1 1 1 1 3
Blue searches the BSP and x=30 x=30 x=30 x=30 x=30 Blue found out that c " A B C
f
found that at x=30, e is to its is in its way to e! a 4

right, so it can ignore objects b x=45


y=45"


a, b, g, h, i, j, k! A A A 2 A2
2 2 2
So it needs to navigate
y=30 A y=30 y=30 y=30 y=30
a, b , g a, b , g a, b , g a, b , g a, b , g around c! D

At y=30, e is to its left, so it


g
h, i, j, k h, i, j, kh, i, j, k h, i, j, k h, i, j, k
Assumes Blue can query


c
can ignore objects l, n! 3 3E 3 E3 E 3 E E d

object c for its dimension,


x=52 e
x=52 x=52
l x=52
l l x=52 l l
It now knows that it would n n n n n
it now knows that it "
h

potentially have to navigate B needs to go to (52, 45) " m 2


B B4 B4 4B 4
around d, f, c, and m! d y=45
d d y=45
d
y=45
d
4
y=45 y=45 to navigate around c! j E
y=30

Of d, f, c, and m, c and m are in Next Blue needs to find


l

the same area as e, compute C D C C D CD C


D D
out if any object is in its i
k
n
f c fc
intersection with them first! f c
e
f
e e
fc c
e way to (52, 45)!
e
m m m m m

Collision Detection with BSP! Collision Detection with BSP!


x=30 x=52
1 1 1 1 1 1 3
Blue needs to find out if any x=30 x=30 x=30 x=30 x=30 Now Blue is at (52, 45), it A B f C
object is in its way to (52, 45)! faces away from y=45, so a 4
b x=45
y=45"
What objects does Blue need it needs to turn around to


2 2 D
A 2 A2 2
to compute intersection
A A y=30 A y=30 y=30 y=30
go to e!
a, bwith?!
y=30
,g a, b , g a, b , g a, b , g a, b , g
h, i, j, k h, i, j, k h, i, j, k g
h, i, j, k
Blue is in the left side of the
h, i, j, k
To get to e, it needs to


c
3 E 3 E
x=52 partition, and only
3
x=52
3E
x=52 x=52
E3
x=52 l x=52
E
l
find if there are other d
e
l l l
object d is on the same side! n n n n n objects in its way! h

So Blue only needs to B B4 B B4 4B 4 Since it is now in the m 2


4
same region as e, it only
y=45 y=30
d y=45
compute intersection with d! d
y=45 y=45 E
d d d y=45 j

needs to compute l

✗✗ intersection with other k


C D C C D CD C D
D
objects in the region: c
i n
f c f f c fc fc c
e e e e e
m m m m m and m!
Collision Detection with BSP! Fixed-Range Search!
Compared to the brute force method, we only The range searches we have considered all have
need to compute intersection with c, m, d, and fixed ranges specified in world space, e.g.,!
c and m again: 5 intersection computations •  of the whole alphabet space, search in range [m–z]"
instead of 3*13 intersections!
•  of the whole Cartesian space, search in range"
Under normal k-d trees, we search both [(–∞, 6), (–∞, 8)]!
subtrees when the search range spans both •  find all (or k) departures within 2 hours of noon!
•  relative to local point of reference!
subtrees! •  but can be transformed into a fixed- and absolute-range query"
in world-space, i.e., [10 am to 2 pm]!
Under BSP trees however, items that span
subtrees are split into two halves such that
only one subtree needs to be searched!

Nearest-Neighbor Search! Nearest Neighbor Search: Algorithm!


1.  start with a reference point ( ) and an infinite search range!
In nearest-neighbor search the range is not 2.  if root node matches query and the distance from reference
pre-specified and is in local space, e.g.,! point to root is smaller than current search range, reduce
• find the ATM machine nearest to me! search range to this distance!
⇐ range not specified!! 3.  determine whether the reference point is to the left or right
• find the k restaurants nearest to me!
of root (along the discriminating coordinate)!
[Known as the k-nearest neighbor (k-NN) problem]! 4.  recursively search the branch of the tree where the reference
point belongs!
Using k-d tree to support nearest-neighbor 5.  upon returning from the recursive search, the search range
queries in 2D:! may have been further reduced, check to see if the current
•  not the most efficient solution in theory! search range covers the other branch of the tree that has not
•  but everyone uses it in practice! been searched!
•  time complexity: O(n1/2 + k)!
6.  if so, recursively search the other branch of the tree;
otherwise prune the other branch!
7.  return results!
Nearest Neighbor Search! Nearest Neighbor Search!
void!
nnsearch(Link root, int disc, Key reference,
double *searchradius,

Key subtreerange[], List results)!
E D G F

E D G F

Reduce search range from initial infinite value to


Assume all data points distance(reference, A) (A being the root of the k-d tree)!
match query!
Current search range covers both children of A!
[wikipedia]! [wikipedia]!

Nearest Neighbor Search! Nearest Neighbor Search!

E D G F E D G F

Reference is to the left of A, search left child of A first!


Since B’s children are not in the new search range,"
Found a node (B) closer to reference than A! we’re done with this branch!
Reduce search range to distance(reference, B)!
[wikipedia]! [wikipedia]!
Nearest Neighbor Search! Nearest Neighbor Search!

E D G F

Returning back to A, current (new) search range no In this example, the k-d tree is formed by splitting
longer overlaps A’s right child, prune the right child, planes, similar to an axis-aligned BSP, hence the
return result! internal nodes do not always hold data points!
[wikipedia]! [Sellarès]!

Nearest Neighbor Search! Nearest Neighbor Search!

Since the root doesn’t hold a data point, the search As we traverse to the second level of the k-d tree,
range remains at ∞ as we search the right side of we still cannot reduce the search range!
the k-d tree where the reference point is!
[Sellarès]! [Sellarès]!
Nearest Neighbor Search! Nearest Neighbor Search!

We’ve reached a leaf node and found two data points Returning back to the parent node, we found that the
that match our query (assume all data points do), search range overlaps the range of the right subtree,
reduce the search range to the minimum distance search the right subtree"
between the reference point and the two data points"
[Sellarès]! [Sellarès]!

Nearest Neighbor Search! Nearest Neighbor Search!

Found a closer neighbor in the left branch of the right Using current search range and each subtree’s range,
subtree, further reduce the search range" prune parts of the tree that could NOT include the
nearest neighbor!

[Sellarès]! [Sellarès]!
Nearest Neighbor Search! k Nearest Neighbors Search!

Using current search range and each subtree’s range, To find k nearest neighbors, maintain k current best
prune parts of the tree that could NOT include the instead of just the best [different k from k-d tree]!
nearest neighbor! Branches are only eliminated when they can't hold
any neighbor closer than any of the k current best!
[Sellarès]! [Sellarès]!

Programming Assignment 2! Geographic


Topic: Location-Based Services! Coordinate System!
“Consumer and advertiser expenditure on A point on earth is given by its
location-based services (LBS) to approach $10B latitude and longitude!
by 2016, with search advertising accounting for !
just over 50%.” LA Times, 6/10/11! Latitude 0º is at the Equator!
Due date: Thu, 10/13, 10:00 pm! Latitude 90º is at the North Pole!
Latitude –90º is at the South Pole!
To be done individually (no group or team)! !
No STL (iostream and string are allowed, Longitude 0º is the Prime Meridian!
they are part of the C++ standard library, not part Longitude ±180º is a the
of STL)! International Dateline"
(more or less)!
Standard Coordinate Frame! Lat/Lon of Some Cities on Earth!
The World Geodetic System 84 represents the earth as City! Latitude! Longitude!
Kinshasa! –4.325! 15.322222!
an ellipsoid with the origin located at the Earth’s center
Istanbul! 41.01224! 28.976018!
of mass (±2 cm)!
Mumbai! 18.975! 72.825833!
WGS84 is the current standard coordinate frame used Jakarta! –6.2! 106.8!
by GPS systems! Shanghai! 31.2! 121.5!
Queenstown! –45.031111! 168.6625!
Honolulu! 21.308889! –157.826111!
San Francisco! 37.7793! –122.4192!
Ann Arbor! 42.281389! –83.748333!
Rio de Janeiro! –22.908333! –43.196389!
Reykjavik! 64.133333! –21.933333!
Casablanca! 33.533333! –7.583333!

Problem Specification! Sample Location Database!


In one column:!
Read in a “database” of location data!
42.2893 –83.7391 NorthsideGrill restaurant 42.2984 –83.7195 Qdoba fastfood
Each entry consists of:! 42.3036 –83.7090 UMCU bank 42.2780 –83.7409 Ashley's pub
lat lon name tag! 42.2831 –83.7485 TheBrokenEgg restaurant 42.2984 –83.7195 Panera bakery

where the lat and lon are floats and! 42.2982 –83.7200 GreatPlainsBurger fastfood
42.3033 –83.7053 Evergreen restaurant
42.2846 –83.7451 Zingerman's restaurant
42.2797 –83.7496 WestendGrill restaurant
name and tag are single words! 42.2785 –83.7413 CometCoffee cafe 42.2808 –83.7486 KaiGarden restaurant
42.2845 –83.7463 Yamato restaurant 42.2909 –83.7178 UMCU bank
To simplify the assignment, we limit acceptable 42.2806 –83.7497 GrizzlyPeak pub 42.2806 –83.7493 CafeZola restaurant
latitude to between 0º and 90º and we limit 42.2810 –83.7486 Vinology restaurant 42.3047 –83.7090 Kroger supermarket
42.3030 –83.7066 TCF bank 42.2830 –83.7467 NoThai fastfood
acceptable longitude to between 0º and –180º 42.2803 –83.7479 ArborBrewingCompany pub 42.3048 –83.7083 AABank bank
(covering North America)! 42.2780 –83.7449 CreditUnion bank 42.2827 –83.7470 CafeVerde cafe
42.2804 –83.7497 Sweetwaters cafe 42.2780 –83.7449 UMCU bank
42.2795 –83.7438 TCF bank 42.2828 –83.7485 Heidelberg pub
42.2792 –83.7409 PotBelly fastfood
Problem Specification! Problem Specification!
You can assume there will be no duplicate records The database is followed by a single blank line and
(all four fields being the same) in the database! one or more queries!

The lat/lon may be duplicated, but as long as the There are three types of queries (not ordered):!
name and/or the tag is different, records with the 1.  exact-match query, led by an ‘@’ sign:!
same lat/lon are not considered duplicates! @ 42.2982 –83.7200"
@ 42.2984 –83.7195"
We limit the lat/lon precision to 4 decimal places
@ 42.2980 –83.7109"
(±0.0001°), which translates to about 11 m
longitudinal distance at the equator and about 2.  range-match query, led by an ‘r’:!
5.56 m longitudinal distance at latitude 60°!
r 42.2806 –83.7493 0.0004"
r 42.2812 –83.7521 0.002"

Problem Specification! Problem Specification!


3.  nearest neighbor query, led by an ‘n’ sign:! The two floats following the ‘@’ and ‘r’ signs
should be obvious!
n 42.2785 –83.7461 bank"
!
n 42.2785 –83.7461 bookstore"
The third float following the ‘r’ sign specifies the
n 42.3033 –83.7078 bank"
search range from the provided location, in degree!
n 42.3034 –83.7078 bank"
!
We limit the range to be at most 0.5 degree from
the provided location, so in total the search range is
limited to 1 degree (enough to cover the New York
Metropolitan Area or the Tokyo/Yokohama
megalopolis, the two largest urban conglomerations
in the world, by area)!
Problem Specification! Problem Specification!
Given the acceptable lat/lon and the limit on The tag following the lat/lon in nearest location
search range, the acceptable latitude on a range search is the queried tag, i.e., a record matches
search is limited to 0.5º to 89.5º and the the query only if the record contains the same tag
acceptable longitude is limited to –0.5º to –179.5º! as the queried tag!
! !
No need to translate degree to linear units!! To simplify implementation, we will use a
“bounding box” covering the search radius to
perform nearest neighbor search!
!
void!
rangesearch(Link root, int disc, Key reference,

double *searchradius, Key bbox[],

Key subtreerange[], List results)!

Nearest Neighbor Bounding Box! Nearest Neighbor Bounding Box!


data matches query! data matches query!
data does not match query! data does not match query!

Bounding box search range covers the circle whose Bounding box is shrunk as a nearer neighbor is found!
radius is the distance between the reference point !
and the nearest neighbor ! A data point is considered a “neighbor” only if its tag
distance(A, B) = √(Bx – Ax)2 + (By – Ay)2! matches that of the queried tag"
[Sellarès]! [Sellarès]!
Output! Given the above database and queries, Location-Based Search!
the output of your program should be:! Finding exact matches:!
@ 42.2982 –83.7200" 42.2982 -83.7200 GreatPlainsBurger fastfood" •  must be implemented using hashing!
@ 42.2984 –83.7195" 42.2984 -83.7195 Panera bakery" •  figure out: what hash function to use!
" 42.2984 -83.7195 Qdoba fastfood"
@ 42.2980 –83.7109"
•  figure out: how to resolve collisions!
No record found"
r 42.2806 –83.7493 0.0004" 42.2806 -83.7493 CafeZola restaurant" •  assume your program will be used all over the
42.2806 -83.7497 GrizzlyPeak pub" acceptable region!
"
" 42.2804 -83.7497 Sweetwaters cafe"
No record found"
r 42.2812 –83.7521 0.002"
Finding range and nearest neighbor matches:!
n 42.2785 –83.7461 bank" 42.2780 -83.7449 CreditUnion bank"
n 42.2785 –83.7461 bookstore" No record found" •  must be implemented using k-d tree!
n 42.3033 –83.7078 bank" 42.3030 -83.7066 TCF bank" •  search range forms a rectangle/bounding box!
n 42.3034 –83.7078 bank" 42.3036 -83.7090 UMCU bank" •  no need to implement node removal!
•  may assume database is not sorted!

level.right(disc) lat lon name tag!

k-d Tree!
0.-1(0) 42.2893 -83.7391 NorthsideGrill restaurant!
1.0(1) 42.2831 -83.7485 TheBrokenEgg restaurant!
2.0(0) 42.2806 -83.7497 GrizzlyPeak pub! PA2 Grading Criteria!
3.0(1) 42.2804 -83.7497 Sweetwaters cafe!
4.1(0) 42.2797 -83.7496 WestendGrill restaurant!
5.1(1) 42.2806 -83.7493 CafeZola restaurant! Working, efficient solution (75%):!
3.1(1) 42.2810 -83.7486 Vinology restaurant!
4.0(0) 42.2808 -83.7486 KaiGarden restaurant! • autograder will use –O3 compile flag for timing,
4.1(0) 42.2828 -83.7485 Heidelberg pub!
2.1(0) 42.2785 -83.7413 CometCoffee cafe!
so make sure your Makefile also uses the"
3.0(1) 42.2780 -83.7449 CreditUnion bank! –O3 flag!
4.0(0) 42.2780 -83.7449 UMCU bank!
4.1(0) 42.2780 -83.7409 Ashley's pub!
3.1(1) 42.2845 -83.7463 Yamato restaurant!
4.0(0) 42.2803 -83.7479 ArborBrewingCompany pub!
Test cases (20%)!
5.1(1) 42.2830 -83.7467 NoThai fastfood!
6.0(0) 42.2827 -83.7470 CafeVerde cafe!
4.1(0) 42.2795 -83.7438 TCF bank! Code is readable, well-documented (5%):!
5.0(1) 42.2792 -83.7409 PotBelly fastfood!
5.1(1) 42.2846 -83.7451 Zingerman's restaurant! •  pay attention to PA1 grade report and avoid
1.1(1) 42.3036 -83.7090 UMCU bank!
2.0(0) 42.2982 -83.7200 GreatPlainsBurger fastfood! being penalized for the same stylistic issues!
3.0(1) 42.2909 -83.7178 UMCU bank!
3.1(1) 42.2984 -83.7195 Qdoba fastfood!
4.0(0) 42.2984 -83.7195 Panera bakery!
4.1(0) 42.3047 -83.7090 Kroger supermarket!
2.1(0) 42.3033 -83.7053 Evergreen restaurant!
3.0(1) 42.3030 -83.7066 TCF bank!
3.1(1) 42.3048 -83.7083 AABank bank!
Files Organization! Time Requirements!
How would you organize your code into files?! How long does it take to do PA2?!
Alternative 1: main.cpp (NOT)! Lines of
Task! % Total Time!
Alternative 2: main.cpp, hash.h, hash.cpp, Code!
kdtree.h, kdtree.cpp, array.h, array.cpp, design (and writing spec)! n/a (2 days)!
linkedlist.h linkedlist.cpp, location.h,
parse input (incl. unit test)! 42! 4!
location.cpp (NOT)!
hashing (incl. unit test)! 132! 27!
Alternative 3: lbs281.cpp, adts.h, hash.h, kdtree insert! 88! 7!
kdtree.h, location.h, location.cpp!
kdtree range search! 142! 23!
Your choice would be different, but try not to split it kdtree nearest neighbor! 130! 38!
up into too many files!! whole globe (excl. nn)! 102! +28!

You might also like