CS 280 Data Structures - PowerPoint PPT Presentation

1 / 7
About This Presentation
Title:

CS 280 Data Structures

Description:

It will take the entire period. You can have 1 page ... That depends on the shape of the call tree. A Good Call Tree ... Middle pivots are usually 'good enough' ... – PowerPoint PPT presentation

Number of Views:24
Avg rating:3.0/5.0
Slides: 8
Provided by: wikiWe
Learn more at: http://wiki.western.edu
Category:
Tags: data | structures

less

Transcript and Presenter's Notes

Title: CS 280 Data Structures


1
CS 280Data Structures
  • Professor John Peterson

2
Test 1
  • Well do a test next week on Wednesday. It will
    take the entire period. You can have 1 page of
    notes.
  • Think about all of the homework / projects /
    quizzes weve had. Ill be doing something
    similar.
  • There will be a little programming.
  • I have graded homework!
  • Im slowly getting projects graded watch your
    email.

3
Call Trees
  • A call tree shows the different calls to
    methods and their arguments. For example, in
    sorting 2,4,3,7,1,8, if the pivot is 4, this
    will generate calls to qs 2,3,1 and qs 7, 8.
    Im not worried about the ordering of elements
    coming out of partition I could have said
    2,1,3 as well. Lets draw a full tree on the
    board.

4
Complexity
  • Whats the time complexity?
  • partition takes O(s) time, where n size of
    subarray (this is bounded by O(n), why?)
  • So how many recursive calls are there and how
    long does each take?
  • That depends on the shape of the call tree.

5
A Good Call Tree
  • Suppose the partition always divides the array in
    half.
  • What does the call tree look like in terms of
    size?
  • What is the complexity in this case?

6
A Bad Call Tree
  • Suppose the pivot happens to divide the array
    into unequal parts the pivot is always the
    highest thing in the subarray. What does the
    call tree look like? What is the complexity?
    How might we get a bad tree?

7
Preventing Bad Trees
  • Choose the pivot in the middle. This is the
    right choice for sorted data and its unlikely
    that this would be bad for any common data
    ordering
  • Choose the pivot randomly this defeats any
    pattern in the incoming data.
  • Middle pivots are usually good enough. Note
    that a bad strategy has to be bad most of the
    time a few bad picks dont mess up the
    complexity.
Write a Comment
User Comments (0)
About PowerShow.com