CSCE 310: Data Structures - PowerPoint PPT Presentation

1 / 10
About This Presentation
Title:

CSCE 310: Data Structures

Description:

CSCE 310: Data Structures – PowerPoint PPT presentation

Number of Views:146
Avg rating:3.0/5.0
Slides: 11
Provided by: johnl51
Category:
Tags: csce | com | data | info | structures

less

Transcript and Presenter's Notes

Title: CSCE 310: Data Structures


1
CSCE 310 Data Structures Algorithms
  • Divide and Conquer (III)
  • Dr. Ying Lu
  • ylu_at_cse.unl.edu

slides referred to http//www.aw-bc.com/info/lev
itin
2
Divide and conquer examples
  • Closest-pair problem
  • Convex-hull problem

3
Closest pair problem
  • Problem find closest among n points in
    k-dimensional space
  • Algorithm Compute distance between each pair of
    points
  • The basic operation of the algorithm
  • Efficiency


?(n2)
4
Closest-pair problem divide and conquer
approach
  • Presentation Slides by Tsvika Klein

5
Quickhull algorithm
  • Presentation slides by João Comba

6
QuickHull Algorithm
  • Inspired by Quicksort, it compute Convex Hull
  • Assume points are sorted by x-coordinate values
  • Identify extreme points P1 and P2 (part of hull)
  • Compute upper hull (Lower hull computation is
    similar)
  • find point Pmax that is farthest away from line
    P1P2
  • compute the hull of the points to the left of
    line P1Pmax
  • compute the hull of the points to the left of
    line PmaxP2

7
Efficiency of QuickHull algorithm
  • Finding point farthest away from line P1P2 can be
    done in linear time
  • This gives same efficiency as quicksort
  • Worst case T( n2)
  • Average case T( n log n)
  • If points are not initially sorted by
    x-coordinate value, this can be accomplished in
    T( n log n) no increase in asymptotic
    efficiency class
  • Other algorithms for convex hull
  • Grahams scan
  • DCHull
  • also in T( n log n)

8
In-Class Exercise 1
  • A k-way merge operation. Suppose you have k
    sorted arrays, each with n elements, and you want
    to combine them into a single sorted array of kn
    elements.
  • A) Heres one strategy Using the merge procedure
    from Section 4.1, merge the first two arrays,
    then merge in the third, then merge in the
    fourth, and so on. What is the time complexity of
    this algorithm, in terms of k and n?
  • B) Give a more efficient solution to this
    problem, using divide-and-conquer.

9
In-Class Exercise 2
  • An array A1 n is said to have a majority
    element if more than half of its entries are the
    same. Given an array, the task is to design an
    efficient algorithm to tell whether the array has
    a majority element, and, if so, to find that
    element. The elements of the array are not
    necessarily from some ordered domain like the
    integers, and so there can be no comparisons of
    the form is Ai gt Aj?. (Think of the array
    elements as GIF files, say.) However you can
    answer questions of the form is Ai Aj?
    in constant time.

10
Reading List of the Week
  • Chapter 5.1 5.2, 5.3 5.4
Write a Comment
User Comments (0)
About PowerShow.com