Programming games in Visual Basic Review programming & VB topics Insertion sort. Best times. Generate questions & answer patterns for quiz Lab/Homework:

Slides:



Advertisements
Similar presentations
Introduction to Algorithms Quicksort
Advertisements

College of Information Technology & Design
MATH 224 – Discrete Mathematics
Introduction to Computer Science Theory
Analysis of Algorithms
Sorting CMSC 201. Sorting In computer science, there is often more than one way to do something. Sorting is a good example of this!
Recursion. Recursion is a powerful technique for thinking about a process It can be used to simulate a loop, or for many other kinds of applications In.
Chapter 6: Arrays Java Software Solutions for AP* Computer Science
Quick Sort, Shell Sort, Counting Sort, Radix Sort AND Bucket Sort
CPS120: Introduction to Computer Science Searching and Sorting.
CompSci 102 Discrete Math for Computer Science
Computability Start complexity. Motivation by thinking about sorting. Homework: Finish examples.
Sorting Algorithms. Motivation Example: Phone Book Searching Example: Phone Book Searching If the phone book was in random order, we would probably never.
CS 206 Introduction to Computer Science II 12 / 09 / 2009 Instructor: Michael Eckmann.
Lecture 25 Selection sort, reviewed Insertion sort, reviewed Merge sort Running time of merge sort, 2 ways to look at it Quicksort Course evaluations.
Quicksort.
Arrays & Strings part 2 More sophisticated algorithms, including sorting.
The Efficiency of Algorithms
Programming Logic and Design Fourth Edition, Comprehensive
CS 206 Introduction to Computer Science II 12 / 08 / 2008 Instructor: Michael Eckmann.
CS 106 Introduction to Computer Science I 10 / 16 / 2006 Instructor: Michael Eckmann.
CHAPTER 7: SORTING & SEARCHING Introduction to Computer Science Using Ruby (c) Ophir Frieder at al 2012.
by Chris Brown under Prof. Susan Rodger Duke University June 2012
Recursion, Complexity, and Searching and Sorting By Andrew Zeng.
Visual Basic Games: Prepare for Hangman
Programming Games in Visual Basic: Data base Catch up questions Data base: generalities & specifics on Visual Basic links Lab: work on projects.
Recursion, Complexity, and Sorting By Andrew Zeng.
Chapter 12 Recursion, Complexity, and Searching and Sorting
Analysis of Algorithms
HKOI 2006 Intermediate Training Searching and Sorting 1/4/2006.
MAT Meyer Week 2 Programming VB: ‘basics’ Review & preview: Events, variables, statements, etc. Images, Control arrays, For/Next Assignment: read.
VB Games: Preparing for Memory Brainstorm controls & events Parallel structures (again), Visibility, LoadPicture, User-defined procedures, Do While/Loop,busy.
Arrays Code: Arrays Controls: Control Arrays, PictureBox, Timer.
CSC 211 Data Structures Lecture 13
“Enthusiasm releases the drive to carry you over obstacles and adds significance to all you do.” – Norman Vincent Peale Thought for the Day.
1 2. Program Construction in Java. 2.9 Sorting 3 The need Soritng into categories is relatively easy (if, else if, switch); here we consider sorting.
CS 361 – Chapters 8-9 Sorting algorithms –Selection, insertion, bubble, “swap” –Merge, quick, stooge –Counting, bucket, radix How to select the n-th largest/smallest.
Visual Basic Games: Week 4 Recap Parallel structures Initialization Prepare for Memory Scoring Shuffling Homework: when ready, move on to next game/chapter.
Review 1 Selection Sort Selection Sort Algorithm Time Complexity Best case Average case Worst case Examples.
Copyright © 2001 by Wiley. All rights reserved. Chapter 6: Using Arrays Control Arrays List Arrays Finding Items in Arrays Multiple Forms 2-Dimensional.
Programming games using Visual Basic Files; files vs. databases Reprise on state of program Lab/HW: work on projects, final project.
Programming Abstractions Cynthia Lee CS106X. Today’s Topics Sorting! 1.The warm-ups  Selection sort  Insertion sort 2.Let’s use a data structure! 
Chapter 9 Sorting 1. The efficiency of data handling can often be increased if the data are sorted according to some criteria of order. The first step.
Chapter 9 Sorting. The efficiency of data handling can often be increased if the data are sorted according to some criteria of order. The first step is.
Winter 2006CISC121 - Prof. McLeod1 Stuff No stuff today!
Data Structures and Algorithms Searching Algorithms M. B. Fayek CUFE 2006.
Visual C++ Programming: Concepts and Projects Chapter 8A: Binary Search (Concepts)
Course Code #IDCGRF001-A 5.1: Searching and sorting concepts Programming Techniques.
ArrayList is a class that implements the List interface. The List interface is a blueprint for its “implementor” classes. There is another implementor.
Computing and the Web Algorithmic Thinking. Overview n Understanding a specific process n Developing an algorithm n Applying the algorithm to computer.
8.1 8 Algorithms Foundations of Computer Science  Cengage Learning.
Fall 2001(c)opyright Brent M. Dingle 2001 Simple Sorting Brent M. Dingle Texas A&M University Chapter 10 – Section 1 (and some from Mastering Turbo Pascal.
CHAPTER EIGHT ARRAYS © Prepared By: Razif Razali1.
Chapter 8 Searching and Sorting © 2006 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
Searching Topics Sequential Search Binary Search.
Computability O(n) exercises. Searching. Shuffling Homework: review examples. Research other shuffling.
Programming games using Visual Basic Detecting a position on top/within a rectangle, near a point, past a line Mouse events.
Review Quick Sort Quick Sort Algorithm Time Complexity Examples
Quicksort This is probably the most popular sorting algorithm. It was invented by the English Scientist C.A.R. Hoare It is popular because it works well.
Computability Sort homework. Formal definitions of time complexity. Big 0. Homework: Exercises. Searching. Shuffling.
COM148X1 Interactive Programming Lecture 8. Topics Today Review.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 8A Binary Search (Concepts)
Winter 2016CISC101 - Prof. McLeod1 CISC101 Reminders Assignment 5 is posted. Exercise 8 is very similar to what you will be doing with assignment 5. Exam.
Warmup What is an abstract class?
Teach A level Computing: Algorithms and Data Structures
Complexity Present sorting methods. Binary search. Other measures.
Winter 2018 CISC101 12/2/2018 CISC101 Reminders
Visual Basic: Week 5 Review User defined functions
Sorting Chapter 8.
Introduction to Computer Programming IT-104
Presentation transcript:

Programming games in Visual Basic Review programming & VB topics Insertion sort. Best times. Generate questions & answer patterns for quiz Lab/Homework: Catch up! Read chapter 10.

Questions/VB technique review Memory –label control array holding name of file and picture control array. The click event on the picture element has the Index parameter that you use for the label control. –Busy wait. Your delay procedure calls the builtin timer function (Recall: functions return values). Delay has a parameter (called interval) Starttime = timer() Do while (timer < (starttime + interval)) Doevents Loop

Review, cont. Hangman –string operator: concatenation. The + or the & will work. –String functions: Mid, Left, Right –Hangman uses an array of strings. Two types of indexing. –Need to check all the letters in the secret word. If there is at least one match, don’t advance the hanging, but need to keep checking. –Feedback to player if form is clicked and not letter.

Review, cont. Cannonball –Staged (incremental) implementation –FIRE! Command button sets up data for flight. timFlight_Timer does horizontal movement and vertical movement separately check for hitting target check for hitting ground –MouseDown, MouseMove and MouseUp events.

Remember Quiz/final There will probably be a practice quiz.

Sorting values in an array Sorting is very common task across many computer applications. How would you sort (a large set--one in which you can’t see the whole set at one time) –a set of elements of known values (for example, deck of cards) –a set of values of known distribution (people’s names) –general set of things

Insertion sort Assume you have a sorted set (lowest to highest), and you need to add a new element, in its proper place Assume an array called intScores of size intSize, a new score intNewScore, and intCurrentSize indicating number currently in intScores. (intCurrentSize < intSize). –You need to ask me a question or make an assumption….

Private Sub addtoscores(intNewScore As Integer) Dim i As Integer, j As Integer If intCurrentSize = intSize Then MsgBox "scores array full" Else For i = 1 To intCurrentSize If intNewScore < intScores(i) Then Exit For End If Next i For j = intCurrentSize To i Step -1 intScores(j + 1) = intScores(j) Next j intScores(i) = intNewScore intCurrentSize = intCurrentSize + 1 End If End Sub

Measuring sorts (and other algorithms) How long does an algorithm take as measured in terms of the problem size (say the size of the set to be sorted)? How long could it take? Answer given as upper bound and in terms of a function "Big O notation" = O(f(n)) more later…

Keeping N best scores Set would probably be in reverse order: highest to lowest. The code must –determine if a new score is to be added –ask for player’s handle –put the score and the name in the right place. This is very similar to the insertion sort. Read chapter 10!

How to sort a whole set? Do insertion sort from the first set to another place or do insertion sort in place. This will involve swap operations, requiring one extra place. Bubble sort other sorts: more complicated to describe but more efficient –Quicksort, heapsort

Bubble sort Assume: intScores, an array to be sorted. intSize is size of array. For i = 1 To intSize - 1 For j = 1 To intSize - i If intscores(j) > intscores(j + 1) Then Call swap(j, j + 1) End If Next j Next i

What is the complexity of the Bubble sort? You may need to compare every element of the set with every other element: n * (n-1) The fact that it is probably some coefficient times n times (n-1) is not important. Answer: O(n 2 ) spoken n squared.

Quicksort Take the set. Think of a number (value) that would likely be in the middle. Compare that number to each element of the set to divide the set into two piles. Repeat for each of the piles and keep repeating (you need to keep picking comparison numbers). This will sort the whole, original set!

Quicksort You have probably used quicksort when alphabetizing lists: –before M and at M or after –Take first pile and compare to F. Second pile, compare to R. –Probably just eyeball and fix the smaller piles.

Complexity of Quicksort? You will be comparing all the elements however many times you divide. Assuming good (though not necessarily perfect) comparison numbers, this is –n * log 2 (n) –This is less than n 2 but more than n. Comparison numbers could be the means (if the elements are numbers.) The complexity of Mean (aka average) is O(n) –add all the numbers and divide by the number of numbers.

Complexity This is just an introduction. Do not panic. Consider taking Discrete Math!