Professional Documents
Culture Documents
AAB: A Generalized Java-Based Algorithm Animator Builder. Term Project Report
AAB: A Generalized Java-Based Algorithm Animator Builder. Term Project Report
net/publication/250789450
CITATIONS READS
0 176
Some of the authors of this publication are also working on these related projects:
An Investigation into Modelling & Specification of Mobile Computing Environment View project
Efficient P2P File Sharing and Searching with Inline Annotations Using de Bruijn Overlay. View project
All content following this page was uploaded by Ratan K. Ghosh on 22 October 2014.
Abstract
The project aims at building a high-level language and provides a Graphical User
Interface for coding animation of Data Structures and algorithms. The software
inputs commands from the application’s console and stores it in its database. The
interpreter then interprets the input commands and creates objects needed to for
animation. These objects are utilized by the application and the code for animation (a
Java applet code) is made based on the input commands of the user.
The software allows for demonstration of Sorting & Searching algorithms, Graph
Theory algorithms and data structures like Arrays, Stacks, Queues, Lists, Trees and
Graphs.
1.Introduction
By writing the software in Java, users can run the animations on almost any
machine and do not have to install the software locally. By leveraging the capabilities
of Java and the
_________________________________________________________________
*Undergraduate Student, **Professor, Dept. of Computer Science & Engineering,
Indian Institute of Technology, Kanpur
Web, we have built a system that will provide educators the realistic option of quickly
generating algorithm animations for demonstration use in the classroom or by
students generating quick animations of their programs.
The core application of the project provides a high-level language in which, the
user can code for animation of algorithms. It is a convenient way to learn algorithms.
However using programming languages like Java or C++ for animation-algorithms
often gets cumbersome as the complexity of algorithms increases and to animate a
complicated algorithm in itself becomes a difficult problem.
The project specifically addresses this problem. It provides a high level
language to program the code for applets animating algorithms. The syntax of the
language used is deliberately kept lucid, so that the focus of the user was on the
algorithm and not on the means of animation. The syntax of the language used is
given later for reference.
The input console was so designed that it prompted for almost every
syntactical error in the user’s code. This reduced the errors in the final code.
The only essential software needed by the project to run was the Java
Runtime Environment (JRE).The project’s application is executable in all operating
systems which incorporate the Java Runtime Environment. Platform independence
is an important feature of the application. Other than the JRE, no other software is
specifically needed to use the application.
The output of the application is the code for the applet which can be compiled
and the resulting applet is accessible on the internet via a web-browser.
2.Related Work
Over the last decade need of packages for algorithm animation was felt in the
community of Computer Science students and teachers. The packages XTango [8]
and its successor Samba [9] have been used by many Computer Science Professors
for a variety of topics, including operating systems [4], algorithms and data structures
[7] and genetic algorithms [5].
In addition, Samba is used by students to generate animations [9].
For creating the data structures like arrays, stacks, queues, heap, graphs etc.
the secondary objects were used. Note: the secondary objects also have an
associated graphical attributes of font, colour, size etc. Linked lists could be
implemented by the use of primary data structures. In the dialog box for a graphical
entity there are fields for all the attributes of the entity. On starting a new animation of
an algorithm, the user specifies the attributes of these graphical entities and later
uses them. All the commands of the algorithm are inserted in the in the Event
Console. Thus the user can manipulate the attributes of these objects while coding
the algorithm, by using appropriate commands (like CC, MV) at the command
prompt. The language for used for coding is discussed later on.
Arrays:
Arrays are the in build data structures in the application. The user
can specify the attributes of number arrays in the NumberArray dialog box.
They have an associated font size, number’s colour, enclosure (rectangle/circle)
etc.These arrays form the building blocks of other data structures like heaps, graphs
etc. NumberArray has an option to specify the x and y spacing of the constituent
NumberObjects.
Trees:
Trees can be created by specifying the position of each node (number-objects),
or by defining an array of number objects. Line graphic object is used to define an
edge in the tree. The attributes of the trees can be specified by a similar procedure
as for arrays. After implementing the tree data structure, the user can use it for
implementation of advanced data structures like Red-black trees-trees, AVL trees
are build by assigning desired attributes to the constituent objects.
Graphs:
Graphs in the application can be drawn with node placements specified
by the user in the dialog box. To build a specified layout graph, the data structure
NumberArray is used. The location and size of a node is also specified in the dialog
boxes. Once the nodes are made, the LineArrays are used to define the edge set of
the graphs. An attribute isDirected of Line and LineArray object is used to distinguish
between directed and undirected graphs.
Data structures like Heaps, Stacks and Queues are generated by the NumberArray
objects.
The overall design of the application can be broadly classified into the following
categories:
1. The graphical user interface (GUI): the buttons and menu-items for creating
the geometrical entities, editing options and incorporating subroutines.
3. A Translator converting the user’s code into a code that can be easily
processed by the application.
The menu bar had options to declare objects used in the program, dialog
boxes for editing e.g. to insert a command after a given line in the algorithm or to
delete a line etc.( the actual coding of the algorithm was done in the command
prompt.)
In the Actions tab, it had options to declare a subroutine (used for implementing
recursive algorithms) and also to declare a local variable (of the type NumberObject,
Circle, Rectangle, Line String etc. and arrays of these objects).
The input for the application could be directed from a file in order to reduce the work
of the user. The option for directed input was in the edit tab of the menu bar.
On clicking on the “Number” menu the following dialog box takes the input
from the user:
Console:
The console is a text-area build by the Java class JTextArea which could input the
code (in the language provided by the application) from the user.The job of the
console is to take the input from the user and gives it to the translator.
Translator:
The translator converts the console input into a code which can be
conveniently processed by the software for further use and stores it in a file
(pseudoCode.txt). It has an addition task of keeping a close vigil on the syntax of the
console input and to prompt back to console in case of erroneous input. This helps in
reducing the errors in the final code.
The translator also updates two files, one of which has the description about
the objects used in the program pseudoObjectCode.txt, and another has the
database of variables defined by the user and their corresponding variable names
used in the program. This was needed in order to maintain consistency during the
parsing of translator output.
Input Parser:
It is the application which takes the code generated by the Translator and the
database as input and converts it to Java applet code. As object oriented approach is
used for creating numbers, circles rectangles, instances of these objects were made
by the input parser whenever needed in the program. To avoid flickering in the
applets, “off-screen double buffering” was used. As the code for double buffering
was generic it was added to every output file (applet code).The pseudoCode.txt was
parsed and corresponding output file, i. e. the applet code was generated. Actions
for commands like MV, CC were defined in the input parser.
Thus we get the final code for the applet, which could be then compiled and
executed to animate the algorithm.
5. Animation Language
5. LINE: A graphical object used to represent the edges of trees and graphs.
It has associated attributes of the initial and final coordinates and fill-
colour.
1. IF (<condition>) THEN
<Code>
ELSE <Code>: for an “if-then-else’ conditional in the program.
The ELSE clause is optional. The <condition > must evaluate to a Boolean
value
2. WHILE (<condition>) DO
<Code>: for a “while” loop in the program.
The <condition > must evaluate to a Boolean value
6.Coding Procedure:
The user declares the variables to be used by the dialog boxes of the objects
from the Geometry tab of the menubar. These variables are taken as global
variables in the program. In order to define local variables, the Actions tab has an
entry for declaring the local variables (all the fields defined in the languages can
have global and/or local (uniquely) appearances. At this stage the files
pseudoObjectCode.txt and pseudoEventCode.txt are updated in order to store the
database and the attributes of objects.
The code for the algorithm with the desired animation is then input either from
a file or from the application’s command prompt. In case of any error the error log
shows a description of the error. A non erroneous input is shown in the Algorithm
console and correspondingly file having the pseudocode of the algorithm
(pseudoEventCode.txt) is updated. In order to declare subroutines the subroutine
dialog box is used. In case the input is complete and syntactically correct, the
InputParser parses the pseudoEventCode.txt and writes the corresponding applet
code in the file NewApplet.java. A sample the code of insertion-Sort is shown below
int index
FOR (index = 1 ; index <10 ; index = index +1 )
key.a = array[index]
CC key.e BLUE
MV key 150
int i
i = index -1
CC array[i].e BLUE
WHILE (i >=0 && array[i ] > key) DO
MH key key.x - 40
MH array[i] array[i].x + 40
CC array[i].e BLACK
IF (i >0) THEN
CC array[i-1].e BLUE
END
array[i+1].a = array[i]
i = i -1
END
MV key 100
array[i+1].a = key
IF (i >=0) THEN
CC array[i].e BLACK
END
CC array[i+1].e BLACK
END
WAIT START
IF START
END
FOR (index = 1 ; index <10 ; index = index +1 )
key = array[index]
CC key.e BLUE
MV key 150
i = index -1
CC array[i].e BLUE
Sample Output:
Database entries:
File Name: NewApplet.java
NUMBERARRAY NA1 10 30 0 100.0 100.0 (255,255,255) 40.0 0 (255,0,0)
true 95 99 83 11 30 44 59 17 93 34
NUMBER N1 0 30 20.0 20.0 (255,255,255) 1 (255,0,0) false
INTEGER j
INTEGER i
7. Conclusions:
Algorithm Animator is a Graphical user interface with a high level language for
creating animations of data structures and algorithms. Its output can be compiled
and run on any platform with the Java Runtime Environment to generate an
animation.
When used in conjunction with traditional teaching
methods, Algorithm Animator can provide students with an alternative
and visual perspective, which may help increase their understanding.
References
[1] A. Badre, C. Lewis, and J. Stasko, Empirically Evaluating the Use of Animations to Teach
Algorithms, Proceedings of the 1994 IEEE Symposium on Visual Languages,
p. 48-54, 1994.
[2] C. Boroni, F. Goosey, M. Grinder, R. Ross and P. Wissenbach, WebLab! A Universal and
Interactive Teaching, Learning, and Laboratory Environment for the World Wide Web,
Twenty-eighth SIGCSE Technical Symposium on Computer Science Education, p. 199-203,
1997.
[3] D. Carlson, M. Guzdial, C. Kehoe, V. Shah and J. Stasko, WWW Interactive Learning
Environments for Computer Science Education, Twenty-seventh SIGCSE Technical
Symposium on Computer Science Education, p. 290-294, 1996.
[4] S. Hartley, Animating Operating Systems Algorithms with Xtango, Twenty-fifth SIGCSE
Technical Symp. on Computer Science Education, p.344-348, 1994.
[5] D. Jackson and A. Fovargue, The Use of Animation to Explain Genetic Algorithms,
Twenty-eighth SIGCSE Technical Symposium on Computer Science Education, p. 243-247,
1997.
[8] J. Stasko, Tango: A Framework and System for Algorithm Animation, IEEE Computer,
p.27-39, 1990.
[12] J. Wilson and R. Aiken, Review of animation systems for algorithm understanding,
Proceedings on Integrating Technology into Computer Science Education,p.75-77, 1996.