0% found this document useful (0 votes)
73 views36 pages

CSN-523: Computational Geometry: Indian Institute of Technology Roorkee

The document describes a lecture on computing the convex hull of a two-dimensional point set using Graham's scan algorithm. It begins with an overview of Graham's algorithm and provides an example of applying the Graham scan algorithm to find the convex hull of a set of 13 points. It then discusses an implementation of Graham's algorithm and establishes lower bounds on the minimum number of operations needed to solve computational geometry problems like convex hulls.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
73 views36 pages

CSN-523: Computational Geometry: Indian Institute of Technology Roorkee

The document describes a lecture on computing the convex hull of a two-dimensional point set using Graham's scan algorithm. It begins with an overview of Graham's algorithm and provides an example of applying the Graham scan algorithm to find the convex hull of a set of 13 points. It then discusses an implementation of Graham's algorithm and establishes lower bounds on the minimum number of operations needed to solve computational geometry problems like convex hulls.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 36

INDIAN INSTITUTE OF TECHNOLOGY ROORKEE

CSN-523: Computational Geometry

Lecture 16: Convex Hull in Two Dimensions

Dr. Sudip Roy


Assistant Professor
Department of Computer Science & Engineering
Piazza Class Room: https://piazza.com/iitr.ac.in/spring2017/csn523/home
Moodle Site: http://moodle.iitr.ac.in/course/view.php?id=23 [Enrollment Key: csn523@2017]
Grahams Algorithm:

2
Grahams Algorithm:

3
Grahams Algorithm:

4
Grahams Algorithm:

5
Grahams Algorithm:

6
Graham Scan: Example

p10

p9 p6

p12 p7 p5

p4 p3
p11
p8 p1
p2

p0

7
Graham Scan: Example

p10

p9 p6

p12 p7 p5

p4 p3
p11
p8 p1
p2

p0

8
Graham Scan: Example

p10

p9 p6

p12 p7 p5

p4 p3
p11
p8 p1
p2

p0

9
Graham Scan: Example

p10

p9 p6

p12 p7 p5

p4 p3
p11
p8 p1
p2

p0

10
Graham Scan: Example

p10

p9 p6

p12 p7 p5

p4 p3
p11
p8 p1
p2

p0

11
Graham Scan: Example

p10

p9 p6

p12 p7 p5

p4 p3
p11
p8 p1
p2

p0

12
Graham Scan: Example

p10

p9 p6

p12 p7 p5

p4 p3
p11
p8 p1
p2

p0

13
Graham Scan: Example

p10

p9 p6

p12 p7 p5

p4 p3
p11
p8 p1
p2

p0

14
Graham Scan: Example

p10

p9 p6

p12 p7 p5

p4 p3
p11
p8 p1
p2

p0

15
Graham Scan: Example

p10

p9 p6

p12 p7 p5

p4 p3
p11
p8 p1
p2

p0

16
Graham Scan: Example

p10

p9 p6

p12 p7 p5

p4 p3
p11
p8 p1
p2

p0

17
Graham Scan: Example

p10

p9 p6

p12 p7 p5

p4 p3
p11
p8 p1
p2

p0

18
Graham Scan: Example

p10

p9 p6

p12 p7 p5

p4 p3
p11
p8 p1
p2

p0

19
Grahams Algorithm:

Version A

20
Implementation of Grahams Algorithm:

21
Implementation of Grahams Algorithm:

22
Implementation of Grahams Algorithm:

23
Implementation of Grahams Algorithm:

24
Lower Bound: Limitations of Algorithm Power

A discussion from the Algorithm book by Anany Levitin:

Anany Levitin, Introduction to The Design and Analysis of


Algorithm, III edition, Pearson, 2011.

25
Lower Bound:

Lower bound: an estimate on a minimum amount of work


needed to solve a given problem

Examples:
number of comparisons needed to find the largest element in
a set of n numbers
number of comparisons needed to sort an array of size n
number of comparisons necessary for searching in a sorted
array
number of multiplications needed to multiply two n-by-n
matrices

26
Lower Bound:

Lower bound can be


an exact count
an efficiency class ()

Tight lower bound: there exists an algorithm with the same


efficiency as the lower bound

Problem Lower bound Tightness


sorting (comparison-based) (nlog n) yes
searching in a sorted array (log n) yes
element uniqueness (nlog n) yes
n-digit integer multiplication (n) unknown
multiplication of n-by-n matrices (n2) unknown

27
Methods for Establishing Lower Bounds:

trivial lower bounds

information-theoretic arguments (decision trees)

adversary arguments

problem reduction

28
Trivial Lower Bounds:

Trivial lower bounds: based on counting the number of items


that must be processed in input and generated as output

Examples
finding max element -- n steps or n/2 comparisons
polynomial evaluation
sorting
element uniqueness
Hamiltonian circuit existence

Conclusions
may and may not be useful

be careful in deciding how many elements must be


processed
29
Decision Trees:

Decision tree a convenient model of algorithms involving


comparisons in which:
internal nodes represent comparisons
leaves represent outcomes (or input cases)

Decision tree for 3-element insertion sort

30
Decision Trees and Sorting Algorithms:
Any comparison-based sorting algorithm can be represented by a
decision tree (for each fixed n)

Number of leaves (outcomes) n!

Height of binary tree with n! leaves log2n!

Minimum number of comparisons in the worst case log2n! for any


comparison-based sorting algorithm, since the longest path represents
the worst case and its length is the height

log2n! n log2n (by Sterling approximation)

This lower bound is tight (mergesort or heapsort)

Ex. Prove that 5 (or 7) comparisons are necessary and sufficient for sorting
4 keys (or 5 keys, respectively).

31
Adversary Arguments:
Adversary argument: Its a game between the adversary and the (unknown)
algorithm. The adversary has the input and the algorithm asks questions to the
adversary about the input. The adversary tries to make the algorithm work the
hardest by adjusting the input (consistently). It wins the game after the lower
bound time (lower bound proven) if it is able to come up with two different inputs.

Example 1: Guessing a number between 1 and n using yes/no questions


(Is it larger than x?)
Adversary: Puts the number in a larger of the two subsets generated by last
question

Example 2: Merging two sorted lists of size n


a1 < a2 < < an and b1 < b2 < < bn
Adversary: Keep the ordering b1 < a1 < b2 < a2 < < bn < an in mind and answer
comparisons consistently
Claim: Any algorithm requires at least 2n-1 comparisons to output the above
ordering (because it has to compare each pair of adjacent elements in the
ordering)
Ex: Design an adversary to prove that finding the smallest element in a set of n
elements requires at least n-1 comparisons.
32
Lower Bounds by Problem Reduction:

Fact: If problem Q can be reduced to problem P, then Q is at least as easy


as P, or equivalent, P is at least as hard as Q.

Reduction from Q to P: Design an algorithm for Q using an algorithm for P


as a subroutine.

Idea: If problem P is at least as hard as problem Q, then a lower


bound for Q is also a lower bound for P.
Hence, find problem Q with a known lower bound that can
be reduced to problem P in question.
Example: P is finding MST for n points in Cartesian plane, and
Q is element uniqueness problem (known to be in (nlogn))
Reduction from Q to P: Given a set X = {x1, , xn} of numbers (i.e. an
instance of the uniqueness problem), we form an instance of MST in the
Cartesian plane: Y = {(0,x1), , (0,xn)}. Then, from an MST for Y we can
easily (i.e. in linear time) determine if the elements in X are unique.
33
Lower Bound of CH(P):

34
Lower Bound of CH(P):

35
Optimality of ( log ):

36

You might also like