Analysis of Algorithms: Computational Geometry and Range Searching, Study notes of Algorithms and Programming

A portion of the slides from a university course, cs 5633, analysis of algorithms, taught in spring 2004. The slides cover computational geometry and range searching in 1d and 2d. Topics include fundamental objects, basic structures, orthogonal range searching, and 1d range trees. The slides also discuss the analysis of these algorithms in terms of query time, preprocessing time, and space.

Typology: Study notes

Pre 2010

Uploaded on 07/30/2009

koofers-user-03s
koofers-user-03s 🇺🇸

10 documents

1 / 31

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CS 5633 Analysis of Algorithms 13/22/04
CS 5633 -- Spring 2004
Computational Geometry
Carola Wenk
Slides courtesy of Charles Leiserson with small
changes by Carola Wenk
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f

Partial preview of the text

Download Analysis of Algorithms: Computational Geometry and Range Searching and more Study notes Algorithms and Programming in PDF only on Docsity!

CS 5633 Analysis of Algorithms

CS 5633 -- Spring 2004 Computational Geometry

Carola Wenk

Slides courtesy of Charles Leiserson with small

changes by Carola Wenk

CS 5633 Analysis of Algorithms

Computational geometry

Algorithms for solving “geometric problems”in 2D and higher.Fundamental objects:

point

line segment

line

Basic structures:

polygon

point set

CS 5633 Analysis of Algorithms

Orthogonal range searching

Input:

n^ points in

d^ dimensions

  • E.g., representing a database of

n^ records

each with

d^ numeric fields

Query:

Axis-aligned

box

(in 2D, a rectangle)

  • Report on the points inside the box:• Are there any points?• How many are there?• List the points.

CS 5633 Analysis of Algorithms

Orthogonal range searching

Input:

n^ points in

d^ dimensions

Query:

Axis-aligned

box

(in 2D, a rectangle)

  • Report on the points inside the box Goal:^ Preprocess points into a data structure to support fast queries - Primary goal:

Static data structure

  • In 1D, we will also obtain adynamic data structuresupporting insert and delete

CS 5633 Analysis of Algorithms

1D range searching

In 1D, the query is an interval:New solution that extends to higher dimensions:• Balanced binary search tree

  • New organization principle:Store points in the

leaves

of the tree.

  • Internal nodes store copies of the leavesto satisfy binary search property:• Node

x^ stores in

key [

x ] the maximum

key of any leaf in the left subtree of

x.

CS 5633 Analysis of Algorithms

8

3/22/

Example of a 1D range tree

11

6 6

8 12812

1414

1717

26 26

35 35

41 41

4242

4343 5959

6161

key [ x

] is the maximum key of any leaf in the left subtree of

x.

CS 5633 Analysis of Algorithms 1212 8 12812

1414

1717

26 26

35 35

4141 2626 1414

Example of a 1D range query

11

6 6

4242

4343 5959

6161

6 6

41 41

5959

11

1212 8 12812

1414

1717

26 26

35 35

4141 2626 14 14

35 35

4343 4242

88

1717

R^ ANGE

-Q^ UERY

([7, 41])

x^ x ≤^ x^

^ x

CS 5633 Analysis of Algorithms

General 1D range query

root

split node

CS 5633 Analysis of Algorithms

Pseudocode, part 2: Traverseleft and right from split node

1D-R

ANGE

-Q^ UERY

( T , [ x

,^ x ]) 12

[ find the split node

]

//^ w^ is now the split node if^ w^ is a leaf^ then output the leaf

w^ if^ x

≤^ key 1 [ w ]^ ≤ x^2

else^ v

←^ left

[ w ]^

// Left traversal

while

v^ is not a leaf do if^ x ≤^1 key [ v

] then^ output the subtree rooted at

right

[ v ]

v^ ←^ left

[ v ] else^ v

←^ right

[ v ]

output the leaf

v^ if^ x

≤^ key 1 [ v ]^ ≤^

x^2

[ symmetrically for right traversal

]

w

CS 5633 Analysis of Algorithms

Analysis of 1D-R

ANGE

-QUERY

Query time:

Answer to range query represented

by O(log

n ) subtrees found in O(log

n ) time.

Thus:• Can test for points in interval in O(log

n ) time.

  • Can report the first

k^ points in interval in

O(k + log

n ) time.

  • Can count points in interval inO(log

n ) time (exercise) Space:

O( n

Preprocessing time:

O( n

log^

n )

CS 5633 Analysis of Algorithms

Store a 3/22/

primary

1D range tree for all the points

based on

2D range trees^ x -coordinate.

Thus in O(log

n ) time we can find O(log

n ) subtrees

representing the points with proper

x -coordinate.

How to restrict to points with proper

y -coordinate?

CS 5633 Analysis of Algorithms

2D range trees

Idea:

In primary 1D range tree of

x -coordinate,

every node stores a

secondary

1D range tree

based on

y -coordinate for all points in the subtree of the node. Recursively search within each.

CS 5633 Analysis of Algorithms

d -dimensional range trees

Query time:

O( k

  • log

d^ n ) to report

k^ points.

Space:

O( n

d log

  • 1^ n

Preprocessing time:

O( n

d log

  • 1^ n

Each node of the secondary

y -structure stores

a tertiary

z -structure representing the points in the subtree rooted at the node, etc. Best data structure to date:Query time:

O( k

  • log

d^ – 1^ n

) to report

k^ points.

Space:

O( n

(log

n^ / log log

d^ – 1 n )

Preprocessing time:

O( n

d log

  • 1^ n

CS 5633 Analysis of Algorithms

Primitive operations:Crossproduct

Given two vectors

v = (^1

x ,^ y^1

) and 1

v = (^2

x ,^ y^2

is their counterclockwise angle

θ

-^ convex

-^ reflex

(> 180º), or

  • borderline (0 or 180º)?

v^2 θ v^1

v^1 v^2 θ convex

reflex

Crossproduct

v ×^1

v =^2

xy^1

-^ y 2

x 1 2 = | v^1

| | v | sin^2

θ^.

Thus, sign(

v ×^1

v ) = sign(sin^2

θ)^

0 if

θ^ convex, < 0 if

θ^ reflex, = 0 if

θ^ borderline.