As part of a larger investigation into the uses of short animations, I am compiling a set of animations that could be used in an introductory data structures course. All of the following examples came from professors who have taught UC Berkeley's introductory data structures class, CS 61B. Below, I give the pedagogical rationale for each case and predict its effectiveness as best I can. I am in need of comments and other example, so please send them along!
The Flash Player is needed to view these animations.
This example is based on an idea from Prof. Mike Clancy. Some students were having trouble grasping the alternating partition/merge structure of divide-and-conquer algorithms such as quicksort. A lab exercsise such as the one below might help.
This exercise presents the student with Java code for quicksort and a box and pointer diagram for a given invocation of the algorithm. The execution of the algorithm is shown by highlighting the active line of code while moving the boxes and pointers. The student is shown the first partition step and asked to complete the rest of the animation. (Right click on the animation to rewind and start from the beginning.) After submitting answers, students will be shown their animations in synch with a correct animation so they can evaluate their answers.
While it does not animate the graphical elements past the first partition step, this example does highlight the code for each step all the way to completion of the algorithm. This hint may or may not be desirable, but I did it in order to synchronize the student's animation with the solution. Without this, the student's animation may be completely out of synch with the correct version. (Is this a problem?)
This example takes a little over two minutes to play, which may take too long to build in a lab exercise. Also, the code is not readable at the small magnification required to show this animation synchronized with another version. Despite these problems, I believe this exercise could prove very helpful to some students. By moving the graphics through each step of the algorithm, it becomes clear how the desired sorting behavior emerges from the code. This approach could be used to teach many algorithms.
This example is also based on an idea from Prof. Mike Clancy. Some students, when getting values from a hash table, were explicitly calling the key's "hashCode" method (e.g., "table.get(myKey.hashCode())"). Suspecting that these students were not understanding how or when the key's hashCode method was invoked, he suggested an exercise like the following.
Students are given a definition for a key object, such as this one:
public class MyKey {
public MyString( String s ) {
myString = s;
}
public int hashCode() {
return myString.charAt(0);
}
public boolean equals( Object obj ) {
return myString.equals(obj);
}
private String myString;
}
Students are then asked to create an animation that shows which methods are invoked during the execution of a simple program like the one below. The list of methods to pick from includes "hashCode" and "equals" methods for the key objects and value objects, as well as any classes they use internally. A "correct" animation is shown below.
This exercise would not be hard to do with pencil and paper; animation seems superfluous. It is possible that students might get a deeper understanding of how objects interact when they see method invocations happening over time. However, this example does not seem very compelling. Perhaps it would be more compelling if the example were longer. Or perhaps this exercise needs a more elaborate animation showing the interactions between objects.