SUNY Geneseo Department of Computer Science


Performance Analysis for List Bubble Sort

{Date}

CSci 141, Fall 2004
Prof. Doug Baldwin

Return to List of Lectures

Previous Lecture


Misc

Exam 2 is next Tuesday, Nov. 9

Questions?

Faster robots? See "setSpeed"

Some browsers put blank lines at front of world files

Proof for homework

Recursive Bubblesort

    // In class SortableList, a subclass of List...
    void sort() {
        if ! this.isEmpty()
            this.bringSmallestToFront()
            this.getRest().sort()
    }
    void bringSmallestToFront()
        if ( ! this.getRest().isEmpty() )
            this.getRest().bringSmallestToFront()
            if this.getFirst() > this.getRest().getFirst()
                first = this.getAndRemove()
                second = this.getAndRemove()
                this.addItem( first )
                this.addItem( second )

Execution Time?

Count simple list messages

Also need time for bringSmallestToFront, plug it into recurrence for sort

Recurrence for bringSmallestToFront

What about sort?

n f(n)
0 1
1 4 + 1 = 5
2 (20-6) + (4+1)
  = 14 + 4 + 1
3 (30-6) + (20-6) + (4+1)
  = 24 + 14 + 4 + 1

[Simplifying Sum of 10i-4, Plus 1]

Next

Stacks, a list-like data structure

Read


Next Lecture