Generating GAIGS XML Scripts I Integrating Algorithm Visualization into Computer Science Education Grand Valley State University June 13-16, 2006.

Slides:



Advertisements
Similar presentations
Transparency No. 1 Java Collection API : Built-in Data Structures for Java.
Advertisements

Stacks.
Sequence of characters Generalized form Expresses Pattern of strings in a Generalized notation.
EXAMPLES (Arrays). Example Many engineering and scientific applications represent data as a 2-dimensional grid of values; say brightness of pixels in.
Data Structures1 Basic Data Structures Elementary Structures Arrays Lists Search Structures Binary search Tree Hash Tables Sequence Structures Stacks Queues.
Problem Solving 5 Using Java API for Searching and Sorting Applications ICS-201 Introduction to Computing II Semester 071.
1 Various Methods of Populating Arrays Randomly generated integers.
The Queue ADT Definition A queue is a restricted list, where all additions occur at one end, the rear, and all removals occur at the other end, the front.
ADT Stacks and Queues. Stack: Logical Level “An ordered group of homogeneous items or elements in which items are added and removed from only one end.”
Lab 1: 1. Download all my programs in your computer under the same folder. 2. The tree shown in the following figure represents an expression: (((( 3 +
Elementary Data Structures CS 110: Data Structures and Algorithms First Semester,
Chapter 5 Queues Modified. Chapter Scope Queue processing Comparing queue implementations 5 - 2Java Software Structures, 4th Edition, Lewis/Chase.
CS Data Structures II Review COSC 2006 April 14, 2017
CS 307 Fundamentals of Computer Science 1 Abstract Data Types many slides taken from Mike Scott, UT Austin.
Unit 11 1 Unit 11: Data Structures H We explore some simple techniques for organizing and managing information H This unit focuses on: Abstract Data Types.
CS 106 Introduction to Computer Science I 12 / 11 / 2006 Instructor: Michael Eckmann.
1 Lecture 24 Abstract Data Types (ADT) –I Overview  What is an Abstract Data type?  What is Stack ADT?  Stack ADT Specifications  Array Implementation.
CS 206 Introduction to Computer Science II 10 / 26 / 2009 Instructor: Michael Eckmann.
CHAPTER 6 Stacks Array Implementation. 2 Stacks A stack is a linear collection whose elements are added and removed from one end The last element to be.
CS102--Object Oriented Programming Lecture 6: – The Arrays class – Multi-dimensional arrays Copyright © 2008 Xiaoyan Li.
Chapter 6 C Arrays Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc. Arrays are data structures.
1 Memory Model of A Program, Methods Overview l Closer Look at Methods l Memory Model of JVM »Method Area »Heap »Stack l Preview: Parameter Passing.
Fall 2007CS 2251 Queues Chapter 6. Fall 2007CS 2252 Chapter Objectives To learn how to represent a waiting line (queue) and how to use the methods in.
 2007 Pearson Education, Inc. All rights reserved C Arrays.
ADT Stacks and Queues. Stack: Logical Level “An ordered group of homogeneous items or elements in which items are added and removed from only one end.”
Java Unit 9: Arrays Declaring and Processing Arrays.
Abstract Data Types (ADTs) and data structures: terminology and definitions A type is a collection of values. For example, the boolean type consists of.
Topic 3 The Stack ADT.
Chapter 3 Introduction to Collections – Stacks Modified
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Custom Templatized Data Structures.
Chapter 3 List Stacks and Queues. Data Structures Data structure is a representation of data and the operations allowed on that data. Data structure is.
Data Structures and Abstract Data Types "Get your data structures correct first, and the rest of the program will write itself." - David Jones.
The JHAVÉ Project JHAVÉ: Java Hosted Algorithm Visualization Environment Goal: Development of a comprehensive suite of visualization-based materials for.
SAK 3117 Data Structures Chapter 3: STACKS. Objective To introduce: Stack concepts Stack operations Stack applications CONTENT 3.1 Introduction 3.2 Stack.
Introduction to GAIGS XML Scripting Integrating Algorithm Visualization into Computer Science Education Grand Valley State University June 13-16, 2006.
Jan 12, 2012 Introduction to Collections. 2 Collections A collection is a structured group of objects Java 1.2 introduced the Collections Framework Collections.
Arrays Module 6. Objectives Nature and purpose of an array Using arrays in Java programs Methods with array parameter Methods that return an array Array.
Arrays An array is a data structure that consists of an ordered collection of similar items (where “similar items” means items of the same type.) An array.
Generating GAIGS XML Scripts II Integrating Algorithm Visualization into Computer Science Education Grand Valley State University June 13-16, 2006.
Data TypestMyn1 Data Types The type of a variable is not set by the programmer; rather, it is decided at runtime by PHP depending on the context in which.
1 The Stack Class Final Review Fall 2005 CS 101 Aaron Bloomfield.
Applications Development
Stacks and Queues. 2 3 Runtime Efficiency efficiency: measure of computing resources used by code. can be relative to speed (time), memory (space), etc.
Data Types – Reference Types Objective To understand what reference types are The need to study reference types To understand Java standard packages To.
AITI Lecture 18 Introduction to Data Structure, Stack, and Queue Adapted from MIT Course 1.00 Spring 2003 Lecture 23 and Tutorial Note 8 (Teachers: Please.
Chapter 2 Collections. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.1-2 Chapter Objectives Define the concept and terminology related.
Chapter 3 Collections. Objectives  Define the concepts and terminology related to collections  Explore the basic structures of the Java Collections.
1 Stacks (Continued) and Queues Array Stack Implementation Linked Stack Implementation The java.util.Stack class Queue Abstract Data Type (ADT) Queue ADT.
Topic 16 Queues "FISH queue: n. [acronym, by analogy with FIFO (First In, First Out)] ‘First In, Still Here’. A joking way of pointing out that processing.
Introduction to Collections. Collections Collections provide a way of organizing related data in a model Different types of collections have different.
Copyright © Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Java From Control Structures through Data Structures by Tony.
Arrays Chapter 7. MIS Object Oriented Systems Arrays UTD, SOM 2 Objectives Nature and purpose of an array Using arrays in Java programs Methods.
int [] scores = new int [10];
Chapter 4 ADTs Stack and Queue. 4-2 Formal ADT Specifications The Java interface construct lets us collect together method interfaces into a syntactic.
M180: Data Structures & Algorithms in Java Stacks Arab Open University 1.
Click to edit Master text styles Stacks Data Structure.
1 Stacks Abstract Data Types (ADTs) Stacks Application to the analysis of a time series Java implementation of a stack Interfaces and exceptions.
Algorithm Definition An algorithm is a step-by-step solution to a problem.
Algorithm Definition An algorithm is a step-by-step solution to a problem.
Linked Data Structures
User-Written Functions
Topic 16 Queues "FISH queue: n.
structures and their relationships." - Linus Torvalds
Topic 16 Queues "FISH queue: n.
Priority Queues.
Java Programming Language
structures and their relationships." - Linus Torvalds
A type is a collection of values
The Queue ADT Definition A queue is a restricted list, where all additions occur at one end, the rear, and all removals occur at the other end, the front.
Presentation transcript:

Generating GAIGS XML Scripts I Integrating Algorithm Visualization into Computer Science Education Grand Valley State University June 13-16, 2006

Generating Scripts as the Output of Executing Programs GAIGS XML scripts can be generated by programs written in any programming language. However, the JHAVÉ environment is designed to directly support programs written in Java. Input to programs must be specified on the command line. The first command line parameter is the file name the script is to be written to. Support classes are available which can be used to directly generate the required GAIGS XML.

Support Classes for GAIGS XML Generation ShowFile: Handles the actual writing to the script file. Structure Classes: Basically one for each of the GAIGS built-in structures. Linear Structures: GAIGSstack, GAIGSqueue, GAIGSlist Arrays: GAIGSarray (includes bar graphs) Trees and Graphs: GAIGStree, GAIGSgraph Labels: GAIGSlabel Question Classes: Support various aspects of generating questions in scripts. XMLfibQuestion, XMLmcQuestion, XMLmsQuestion, XMLtfQuestion

The ShowFile Class The ShowFile class is responsible for all writing to the script file. Constructors: ShowFile(String fileName) fileName is the name of the file to be written to. file is opened, and preliminary XML written to it. Key Methods: writeSnap(String title, Double titleSize, GAIGSdatastr… ds) writes to the file the XML for a snap with the title and each of the listed structures. titleSize parameter is optional. close() writes any questions and closes the file.

The GAIGSstack Class I GAIGSstack functions in the usual way as a stack (with push and pop operations. But also stores color and other information in a way that can remain hidden (if desired) from the client class. Constructors: GAIGSstack() create a stack using defaults for location and color. GAIGSstack(String n, String c, double x1, y1, x2, y2, size) create a stack with name n, color c, location, and fontSize size.

The GAIGSstack Class II Key Methods: pop() removes the most recently added item from the stack. push(Object o) adds an item to the stack (with the default color). push(Object o, String c) adds an item to the stack with color c. Key Inherited Methods (from GAIGSlist) isEmpty() returns true if the stack has no elements. peek() returns (but does not remove) the most recently added item from the stack.

import exe.*; import java.io.*; public class Example1 { static final String title = "Stack Example"; static final double titleSize = 0.08; public static void main (String [] args) throws IOException { GAIGSstack stack = new GAIGSstack(); ShowFile show = new ShowFile(args[0]); int itemsToAdd = Integer.parseInt(args[1]); for (int i = 0; i < itemsToAdd ; i++) { stack.push(i); show.writeSnap(title, titleSize, stack); } show.close(); } Example 1 Code: Using the ShowFile and GAIGSstack Classes

<!DOCTYPE show PUBLIC "-//JHAVE//DTD GAIGS SHO//EN" "gaigs_sho.dtd"> Stack Example 0 Example 1 Output: itemsToAdd == 1 ShowFile constructor ShowFile writeSnap ShowFile close

GAIGSqueue and GAIGSlist Classes Much like GAIGSstack, these provide, respectively, basic queue and list functionality. GAIGSqueue: enqueue and dequeue operations GAIGSlist: many but not all the operations from the List interface Like the Java collection classes, GAIGSqueue inherits from GAISlist (as does GAIGSstack). Please consult the GAIGS API for details on these classes

import exe.*; import java.io.*; public class Example2 { static final String title = "Stack and Queue"; public static void main (String [] args) throws IOException { GAIGSqueue queue = new GAIGSqueue("Queue", "#666666", 0, 0.2, 0.5, 0.7, 0.1); GAIGSstack stack = new GAIGSstack("Stack", "#DDDDDD", 0.5, 0.2, 1, 0.7, 0.1); ShowFile show = new ShowFile(args[0]); int itemsToAdd = Integer.parseInt(args[1]); for (int i = 0; i < itemsToAdd ; i++) { queue.enqueue(i); stack.push(i); show.writeSnap(title, queue, stack); } show.close(); } Example 2 Code: Multiple Structures in a Snapshot

… Stack and Queue Example Queue 0 Stack 0 … Example 2 Partial Output: This is the First Snap

GAIGSarray I GAIGS provides support for one and two dimensional arrays. Row labels can be specified, and if the array is 2-d column labels as well. If the array is a 1-d array of int, it can be shown either in the usual format or as a bar graph. Here we just briefly consider the 1-d case, please consult the GAIGS API for complete details on this class

GAIGSarray II Constructor: GAIGSarray (String s, boolean bar, color c, double x1, y1, x2, y2, size) create a label with name s, color c, location, and fontSize size. Display as a bargraph if bar == true. Key Methods: set(Object o, int loc) and set(Object o, int loc, String c) set location loc to have value o, optionally with color c get(int loc) return the value at location loc setColor(int loc, String c) set the color of the item at location loc to c. setName(String s) set the name of this structure to s

GAIGSlabel GAIGSlabel is a work-around for the fact that labels are not (yet) supported in GAIGS. It is really just an structure that has no elements, hence only the structure's name is displayed. Constructor: GAIGSlabel (String s, double x1, y1, x2, y2, size) create a label with name s, location, and fontSize size. the label is placed within these bounds, but is not aligned with any of them. Key Method: setLabel(String s) set the label to s.

Exercise: Create a Bubblesort Visualization Our exercise will be to create a complete visualization for the (infamous) bubblesort algorithm Supplied code will create the snapshot shown below: GAIGSarray GAIGSlabel

Supplied Code import java.io.*; import java.util.Random; import exe.*; public class Sort { static final String TITLE = null;// no title static int arraySize;// # of items to sort static GAIGSarray items;// the array of items static GAIGSlabel message;// for status messages Exercise Code: Preamble

public static void main(String args[]) throws IOException { // process program parameters and create the show file object ShowFile show = new ShowFile(args[0]); arraySize = Integer.parseInt(args[1]); // define the two structures in the show snapshots items = new GAIGSarray(arraySize, true, "BubbleSort", "#999999", 0.1, 0.1, 0.9, 0.9, 0.07); message = new GAIGSlabel("Initial Array Values", 0.1, -0.45, 0.9, 0.35, 0.07); // initialize the array to be sorted & show it loadArray(); show.writeSnap(TITLE, items, message); // +++ add bubblesort code here +++ // visualization is done show.close(); } Exercise Code: Main method

// Load the array with values from 1 to the array size, then // shuffle these values so that they appear in random order. private static void loadArray () { Random rand = new Random(); for (int i = 0; i < arraySize; i++) items.set(i+1,i); for (int i = 0; i < arraySize-1; i++) swap(i, i + (Math.abs(rand.nextInt()) % (arraySize - i)) ); } // Swap two items in the array. private static void swap (int loc1, int loc2) { Object temp = items.get(loc1); items.set(items.get(loc2), loc1); items.set(temp, loc2); } Exercise Code: Support Routines

Time to Work! for (int pass = 1; pass < arraySize; pass++) for (int i = 0; i < arraySize-pass; i++) if ((Integer)(items.get(i)) > (Integer)(items.get(i+1))) swap(i, i+1); Below is working code for the bubblesort algorithm. Your job: Incorporate it into the supplied code for this exercise. Decide when snapshots should be taken (when do the interesting events occur?). Use coloring to show the ongoing actions of the algorithm. Use the label and the name of the array to produce useful messages about the status of the algorithm. Bubblesort Code