1 Georgia Tech, IIC, GVU, 2006 MAGIC Lab Rossignac Programming Project 2 SORTING Lecture 05, file P2 Due January.

Slides:



Advertisements
Similar presentations
MS-Word XP Lesson 2. Page Setup & Margins 1.Click on file menu 2.Click on page set up menu item 3.Select margins tab sheet (default activated) 4.Type.
Advertisements

1 Georgia Tech, IIC, GVU, 2006 MAGIC Lab Rossignac Project P3: CSG Lecture 08, File P3.ppt Due Feb 14 Individual.
Image Processing … computing with and about data, … where "data" includes the values and relative locations of the colors that make up an image.
Emerging Platform#5: Processing 2 B. Ramamurthy 6/13/2014B. Ramamurthy, CS6511.
1 Georgia Tech, IIC, GVU, 2006 MAGIC Lab Rossignac Programming Project 1 Truth Table Lecture 03, file P1 Due January.
Programming and Data Structure
SORTING AND ASYMPTOTIC COMPLEXITY Lecture 12 CS2110 – Spring 2014 File searchSortAlgorithms.zip on course website (lecture notes for lectures 12, 13) contains.
Text David Meredith Aalborg University.
FrontPage Express By John G. Summerville Ph.D.©, RN.
IAT 334 Lab 2 Computer Graphics: Rocket, PImage. June 4, 2010IAT 3342 Outline  Programming concepts –Programming Computer Graphics –Transformations –Methods.
1 The Excel Spreadsheet Application as Basis for a Computer Assisted Language Learning Activity Authoring System Karl Sklar St. Michaels College School.
Janet Cadman & Mary Kay Gordon EDTC Spring 2011 Instructional Design/ Storyboard for Tutorial/ Interactive Learning Project Storyboard 1)Title :
Click your mouse for next slide Dreamweaver – Merging, Coloring, Fonts Now it’s time to fill your page with some more interesting stuff The first thing.
Lecture 24 Applets. Introduction to Applets Applets should NOT have main method but rather init, stop, paint etc They should be run through javac compiler.
Course Orientation Assignments Tool. If the Assignments tool has been added to the course, use the Assignments link in the Course Menu to access upcoming.
PowerPoint Practice 1.Click SAVE AS and save this file on your network drive. Rename it “powerpoint practice.” 2.Follow the directions on the slides.
IWebFolio Using a Template Tutorial Images in this tutorial:
CPSC 203 Introduction to Computers Tutorial 03 & 29 Jie (Jeff) Gao September 15 & 16.
Review Blocks of code {.. A bunch of ‘statements’; } Structured programming Learning Processing: Slides by Don Smith 1.
Java Programming, 3e Concepts and Techniques Chapter 3 Section 65 – Manipulating Data Using Methods – Java Applet.
Log Files. eValid Log Files eValid validates your WebSite by recognizing and recording both successful and unsuccessful events. Detailed records are stored.
1 Georgia Tech, IIC, GVU, 2006 MAGIC Lab Rossignac Lecture 06: COMPLEXITY Sections 2.2 and 2.3 Jarek Rossignac CS1050:
Interface.  Menu  Document  Insert  Panel Management.
1 Georgia Tech, IIC, GVU, 2006 MAGIC Lab Rossignac Lecture 03: PROOFS Section 1.5 Jarek Rossignac CS1050: Understanding.
P366: Lecture #1 Use of Excel for analysis Lei Chen, MD Jan 6, 2002.
1 Georgia Tech, IIC, GVU, 2006 MAGIC Lab Rossignac Lecture 01a: Overview of the course Jarek Rossignac CS1050: Understanding.
1 k Jarek Rossignac,  2008 Processing  Install Processing  Learn how to edit, run, save, export, post programs  Understand.
Using the JImageViewer classes. JImageViewer classes JImageViewer class JImageViewer class ImagePanel class ImagePanel class Image class Image class.
With Microsoft Excel 2007 Comprehensive 1e© 2008 Pearson Prentice Hall1 Chapter 1: PowerPoint Presentation GO! with Microsoft Excel ® 2007 Comprehensive.
Lecture 131 CS110 Lecture 13 Thursday, March 11, 2004 Announcements –hw5 due tonight –Spring break next week –hw6 due two weeks from tonight Agenda –questions.
Programming for Artists ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 10 Fall 2010.
1 Georgia Tech, IIC, GVU, 2006 MAGIC Lab Rossignac Lecture 02b: Tutorial for Programming in Processing Jarek Rossignac.
B. RAMAMURTHY Simulating Motion and Implementing Animation.
Variables Art &Technology, 3rd Semester Aalborg University Programming David Meredith
1 Georgia Tech, IIC, GVU, 2006 MAGIC Lab Rossignac Lecture 09: SEQUENCES Section 3.2 Jarek Rossignac CS1050: Understanding.
Lecture 121 CS110 Lecture 12 Tuesday, March 9, 2004 Announcements –hw5 due Thursday –Spring break next week Agenda –questions –ArrayList –TreeMap.
1 Georgia Tech, IIC, GVU, 2006 MAGIC Lab Rossignac Project P9 Graphs Jarek Rossignac CS1050: Understanding and Constructing.
1 Georgia Tech, IIC, GVU, 2006 MAGIC Lab Rossignac Lecture 02: QUANTIFIERS Sections 1.3 and 1.4 Jarek Rossignac CS1050:
SC Introduction to Programming Lecture 1: 5 th May 2003.
Click your mouse for next slide Adding Text Click in any text box Type in your text OR.
Words. Characters and Strings Character –A single character inside of single quotes char letter = 'A' ; char digit = '0' ; – Strings Zero or more character.
Computer Science I Recap: variables & functions. Images. Pseudo-random processing.
1 Georgia Tech, IIC, GVU, 2006 MAGIC Lab Rossignac Graphic pipeline  Scan-conversion algorithm (high level)  Pixels.
1 Class 1 Lecture Topic Concepts, Definitions and Examples.
1/25/2016B.Ramamurthy1 Exam3 Review CSE111 B.Ramamurthy.
CS212: Object Oriented Analysis and Design Lecture 22: Generic Class Design.
1 Georgia Tech, IIC, GVU, 2006 MAGIC Lab Rossignac Lecture 17a: ACTIVE ZONES of CSG primitives Jarek Rossignac CS1050:
CS130 Visual Basic Project 4 Lecture Fall New topics in project 4 Database, file (table), records, fields. Application that contains menus, submenus,
Continuous. Flow of Control Programs can broadly be classified as being –Procedural Programs are executed once in the order specified by the code varied.
Copyright © 2006 by The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill Technology Education Copyright © 2006 by The McGraw-Hill Companies,
1 SIC / CoC / Georgia Tech MAGIC Lab Rossignac Processing  Install Processing  Learn how to edit, run, save, export,
Programming for Art: Arrays – 2D ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 16 Fall 2010.
IAT 265 Images in Processing PImage. Jun 27, 2014IAT 2652 Outline  Programming concepts –Classes –PImage –PFont.
1 Georgia Tech, IIC, GVU, 2006 MAGIC Lab Rossignac Lecture 05: SORTING Section 2.1 Jarek Rossignac CS1050: Understanding.
1 Georgia Tech, IIC, GVU, 2006 MAGIC Lab Rossignac Lecture 04: SETS AND FUNCTIONS 1.6, 1.7, 1.8 Jarek Rossignac CS1050:
1 Georgia Tech, IIC, GVU, 2006 MAGIC Lab Rossignac Lecture 09a: PROOF STRATEGIES Section 3.1 Jarek Rossignac CS1050:
Computer Science I Animations. Bouncing ball. The if statement. Classwork/homework: bouncing something. Compress and upload work to Moodle.
1 Georgia Tech, IIC, GVU, 2006 MAGIC Lab Rossignac.
IAT 800 Lecture 8 PImage and PFont. Oct 13, Fall 2009IAT 8002 Outline  Programming concepts –PImage –PFont.
1 Georgia Tech, IIC, GVU, 2006 MAGIC Lab Rossignac Lecture 01: Boolean Logic Sections 1.1 and 1.2 Jarek Rossignac.
Enlisted Association of the National Guard of the United States Data Extract Instructional Guide.
Microsoft Excel.
IAT 265 PImage and PFont.
Lecture 09 Applets.
THIS IS JEOPARDY. THIS IS JEOPARDY With Your Host... Paul Berman.
Based on lecture notes from Dr. Deepak Kumar of Brynmawr
Based on lecture notes from Dr. Deepak Kumar of Brynmawr
How to Use a Mouse The One for a computer.
Based on lecture notes from Dr. Deepak Kumar of Brynmawr
Microsoft PowerPoint Tutorial Graphs BIS 101 Spring 2018.
Presentation transcript:

1 Georgia Tech, IIC, GVU, 2006 MAGIC Lab Rossignac Programming Project 2 SORTING Lecture 05, file P2 Due January 31 before class as a link on your PPP Jarek Rossignac CS1050: Understanding and Constructing Proofs Spring 2006

2 Georgia Tech, IIC, GVU, 2006 MAGIC Lab Rossignac Start with the sample P2 Access the applet at Click in the window and hold mouse down to see animation It sorts random numbers and then animates the sorting

3 Georgia Tech, IIC, GVU, 2006 MAGIC Lab Rossignac Declarations PFont fontUsed; // name of font used for writing on the graphic screen int H=5; // number of entries in the table int T[] = new int[H]; // table (array). Will contain integers int AT[] = new int[H]; // copy of the table for animation int swaps[][] = new int[H*H+1][2]; // record swaps (pair of indices) color myRed = color(250,100,100); color myGreen = color(100,250,100); color myBlue = color(100,100,250); // my colors (R,G,B) in [0,255] int cw, ch; // cell width and height int c=0, mc=150; // animation counter and max int w=0, mw=50; // wait counter and max int swap=0; // index to swaps int swapMax=0; // counter of th enumber of swaps float t=0.0; // animation parameter int s1, s2; // indics of the current pair to be swapped

4 Georgia Tech, IIC, GVU, 2006 MAGIC Lab Rossignac Setup void setup() { // executed only once as initialization size(500, 500); // opens graphic window of 600x600 pixels. \ cw=int(35); // computes cell sizes leaving a margin, Cast to integer ch=int(0.9*height/H); // (height and width of window are keywords) fontUsed = loadFont("Times-Roman-25.vlw"); // this font must be loaded (MENU-BAR > TOOLS > CREATE FONTS) textFont(fontUsed, 20); // selects font and assigns size for (int i=0; i<H; i++) {T[i]=int(random(2*H)); }; // init with random numbers for (int i=0; i<H; i++) {AT[i]=T[i]; }; // copy to animation table println(); println(" *** unsorted list ***"); for (int i=0; i<H; i++) { println("T["+i+"]="+T[i]);}; bubbleSort(); // call to my naive sorting routine }; // end of setup

5 Georgia Tech, IIC, GVU, 2006 MAGIC Lab Rossignac bubbleSort void bubbleSort() { // my simple sorting, replace by yours for (int j=H-1; j>0; j--) { for (int i=0; i<j; i++) { if (T[i]>T[i+1]) {doSwap(i,i+1);}; }; }; }; void doSwap(int s1, int s2) { int temp=T[s1]; T[s1]=T[s2]; T[s2]=temp; // performs the swap swaps[swapMax][0]=s1; // records the swap swaps[swapMax][1]=s2; swapMax++; };

6 Georgia Tech, IIC, GVU, 2006 MAGIC Lab Rossignac Draw // will be executed continuously to refresh the window many frames per second void draw() { background(200); // erases screen and set up a light grey background strokeWeight(2); // lines will be drawn thicker translate(width*0.05,height*0.05); // move the origin to leave a margin if (mousePressed) // moves animation by one step when mouse pressed {advanceAnimation(); }; ShowTable(); // Displays the partially sorted table with animation state if (done) {noLoop();}; // stops when done }; // end of draw

7 Georgia Tech, IIC, GVU, 2006 MAGIC Lab Rossignac advanceAnimation void advanceAnimation () { s1=swaps[swap][0]; s2=swaps[swap][1]; // entries to be swapped are retrieved from list of swaps if (w<mw) {w++;} // advance the wait counter if(w==mw) { // when done waiting t=float(c)/float(mc); // compute animation time in [0,1] c++; // advance animation counter if (c==mc) { // when animation done for this swap w=0; c=0; t=0; // reset time and counters int temp=AT[s1]; AT[s1]=AT[s2]; AT[s2]=temp; // do the actual swap swap++; // next swap if (swap==swapMax) {done=true; swap=swapMax;} // all swaps done };

8 Georgia Tech, IIC, GVU, 2006 MAGIC Lab Rossignac ShowTable void ShowTable() { // displays able animated int ax, ay; // displacements for the cels being swapped color cellColor = myGreen; // default color for cells float r=(s2-s1)*ch; // radius for circular animation int sa=int(r*sin(t*TWO_PI/2.0)/2.0); // horizontal displacement for (int h=0; h<H; h++) { // go through the cells cellColor=myGreen; // default color for non-swapping cells is green ax=0; ay=0; // no displacement for non-swapping cells if (h==s1) {ay=int(t*r); ax=sa; cellColor=myRed; }; // if upper swap cell if (h==s2) {ay=-int(t*r); ax=-sa; cellColor=myBlue; }; // if lower swap cell drawCell(width/2-cw+ax,h*ch+ay,cw,ch,cellColor,AT[h]); }; }; void drawCell(int wp, int hp, int cwp, int chp, color cp, int vp) { fill(cp); rect(wp,hp,cwp,chp); // draws and fills a rectangular region fill(0); text(nf(vp,2),wp+cwp/10,hp+chp*0.8); }; // writes vp on the screen

9 Georgia Tech, IIC, GVU, 2006 MAGIC Lab Rossignac Implement 3 variants of bubblesort Bubble sort is described page 125 Add three alternatives to bubbleSort –A modified bubble sort algorithm that stops when no interchange is required (exercise 37 page 130) –Modified insertion sort If the next n th element is smaller than the one it follows, then bubble it up until it is in the correct place in the sorted list of the first n elements –A modified selection sort (presented at the bottom of page 130) Start with n=1 Assume that the first n–1 elements are sorted. Find the smallest of the remaining elements Swap it with the n th element Increment n

10 Georgia Tech, IIC, GVU, 2006 MAGIC Lab Rossignac Enhance the user interface Increase the size of the array. Let the user press a key for the following actions: “r”: to select a new random set of numbers “n”: to select a nearly sorted set of numbers “b”: to run my naïve bubblesort “e”: to run your modified bubblesort that stops early “i”: to run your modified insertion sort “s”: to run your modified selection sort When the mouse is in the window and pressed, run the animation of the algorithm that was run last (make sure that you write in the graphics window the total number of swaps).

11 Georgia Tech, IIC, GVU, 2006 MAGIC Lab Rossignac Report results Debug your program and make images for each combination Execute all 4 algorithms on several sets of random numbers and on several sets of nearly sorted numbers Watch the 4 algorithms and provide a qualitative characterization of the differences in their behavior for random and nearly sorted numbers Report statistics of the average number of swaps for each algorithm (separating random and nearly sorted sets). Post on your PPP: –images (before and after) with number of swaps for each algorithm on a random and on a nearly sorted set. –your qualitative characterization –statistics with conclusions –links to applet and source code