DS&A

Data Structures and Algorithms

Exercises: Box-and-Pointer Diagrams

Feb 192018

Before attempting these exercises, you should view the box-and-pointer diagrams video lecture.

The following classes are defined:

class Foo:
    def __init__(self, baz, qux):
        self.baz = baz
        self.qux = qux

class Bar:
    def __init__(self, quux, quuz):
        self.quux = quux
        self.quuz = quuz

In each of the exercises below, your box-and-pointer diagrams should show the program state after the code has been executed, including all variables, objects, and references.

Exercises

  1. Draw a box-and-pointer diagram showing the program state after the following Python code has been executed:
    corge = Foo(1, 2)
    grault = Foo(3, 4)
    garply = Bar(corge, grault)

  2. Draw a box-and-pointer diagram showing the program state after the following Python code has been executed:
    waldo = Foo(5, 6)
    fred = waldo
    fred.baz = 7

  3. Draw a box-and-pointer diagram showing the program state after the following Python code has been executed:
    plugh = Foo(8, 9)
    xyzzy = Bar(plugh, None)
    thud = Bar(xyzzy, xyzzy)

  4. Draw a box-and-pointer diagram showing the program state after the following Python code has been executed:
    wibble = Foo(1, 2)
    wibble = Foo(3, 4)
    wibble = Foo(5, 6)

  5. Draw a box-and-pointer diagram showing the program state after the following Python code has been executed:
    wobble = Bar(None, None)
    wobble = Bar(wobble, None)
    wobble.quuz = wobble

There are no published comments.

New comment

Your comment will not appear until a moderator approves it.

Atom

hosted on werp.site