Algorithms and OOD (CSC 207 2013F) : Outlines

Outline 51: Pause for Breath


Held: Wednesday, 4 December 2013

Back to Outline 50 - Heap Sort. On to Outline 52 - Dynamic Programming.

Summary

We pause for a bit to review a few concepts that have been causing folks problems.

Related Pages

Overview

Administrivia

Thinking about memory

Sample code

public class Counter {
    static int operations = 0;
    int counter;
    void increment() {
        ++Counter.operations;
        ++this.counter;
    } // increment()

    void decrement() {
        ++Counter.operations;
        --this.counter;
    } // decrement()

    int get() {
        ++Counter.operations;
        return this.counter;
    } // get()
} // class Counter

public class CounterExpt {
    public static void main(String[] args) {
        Counter c1 = new Counter();
        Counter c2 = new Counter();

        c1.increment();
        c1.increment();
        c2.decrement();

        System.out.println("ops: " + Counter.operations);
        System.out.println("c1: " + c1.get());
        System.out.println("c2: " + c2.get());
        System.out.println("ops: " + Counter.operations);
    } // main
} // class CounterExpt

We'll walk through the setup of memory

Note that we can do less detail and still learn a lot.

Loop invariants

Data Structure Invariants

Copyright (c) 2013 Samuel A. Rebelsky.

Creative Commons License

This work is licensed under a Creative Commons Attribution 3.0 Unported License. To view a copy of this license, visit http://creativecommons.org/licenses/by/3.0/ or send a letter to Creative Commons, 543 Howard Street, 5th Floor, San Francisco, California, 94105, USA.