Download presentation
Presentation is loading. Please wait.
Published byEstella Wilcox Modified over 9 years ago
1
2012 CSE-BEACON camp1 Computer Science Concepts 1. What is an algorithm? 2. Binary information coding 3. Programming concepts via Scratch Designed for learners 10 years old up to 100.
2
Materials for hands on activities 2012 CSE-BEACON camp2 1)a set of cards with numbers, say, 42, 17, 43, 55, 20, 32, 12 2)A set of cards with binary place values: 1, 2, 4, 8, 16 3) Scratch downloaded from www.scratch.mit.eduwww.scratch.mit.edu 4) www.learnscratch.org for tutorials for homeworkwww.learnscratch.org
3
2012 CSE-BEACON camp3 What is an algorithm? Algorithms for average and min An algorithm for sorting
4
2012 CSE-BEACON camp4 Algorithm for computing the average of two numbers Let the first number be A; say A=12 And the second number be B; say B=15 To compute the average _____________ So the average of 12 and 15 = ________ WHAT IS THE AVERAGE ALGORITHM?
5
2012 CSE-BEACON camp5 What is an algorithm? An algorithm computes some output from the given input using precise steps that a machine can follow (machine or other agent)
6
Hands on activity: finding MIN Organize into 2-person teams Team has “person A” and “person B” Each team has a stack of cards There is one number on each card No one looks at numbers yet 2012 CSE-BEACON camp6
7
7 problem: finding min Person B is the “worker” for A. Person A has cards, but cannot look at the numbers. A must find the min of all cards. B can look at only 2 numbers at a time -- B returns to A the smaller smaller first. HOW CAN PERSON A FIND THE MIN? Shuffle the cards A and B switch roles: new person A finds MIN
8
2012 CSE-BEACON camp 8 review: team finding the min Person A can look at no numbers! No numbers can be seen by A, EVER! Person B can look at only two numbers on cards given by person A. Person B gives back to A first the card with the smaller number (if numbers are = then it doesn’t matter which is given first) Person A must find the min and show it to the instructor WITHOUT EVER SEEING IT A and B should switch roles and repeat.
9
Thought Questions If A has 10 cards with numbers, how many times does A call on B? _____ If A has 100 cards, how many times does A call on B? _____ If A has N cards, how many times does A call on B? _____ Finding the MIN of a list of numbers has “complexity” _______ 2012 CSE-BEACON camp9
10
Thought Question Suppose A has 2 assistants – B and C Can A find the MIN any faster? HOW? Computers and computer programs can be structured to do more than one operation at a time. 2012 CSE-BEACON camp10
11
2012 CSE-BEACON camp11 Problem: how to sort? Use set of cards for each team. How can A sort using B as comparer? TRY IT: instructor will check your final output
12
2012 CSE-BEACON camp 12 Sorting two-person activity This is a 2-person exercise. Person A CANNOT see the numbers – EVER! To solve the sorting puzzle, person A must form an ordered list of cards, which the instructor will check for order (this is the OUTPUT). Person B can only compare two numbers by seeing the numbers. Person B gives A the smaller number card first (precise operations). Person A can only ask Person B which of two cards has the smaller number. Person A never ever looks at any numbers. To solve the sorting puzzle, person A must start from an unordered list of cards (this is the INPUT).
13
2012 CSE-BEACON camp13 Sorting thought questions How many times will A call on B to sort 10 numbers? _____ How many calls to sort 100 numbers? _____ How many calls to sort N numbers? _____ There are many sorting algorithms. Some are fast when N is small but slow when N is big. Some are the opposite. Computer scientists learn these algorithms and many others.
14
Algorithms often do operations over and over Called “looping” Also called “iteration” or “repetition” “Recursion” is a related idea – first select the MIN from the list and then “recurse” on the rest of the list 2012 CSE-BEACON camp14
15
2012 CSE-BEACON camp15 Binary Information Coding 1. Only 2 symbols: WHY? 2. Can we code numbers, characters, music, images, movies, car designs using just 2 symbols?
16
Coding activities 1. Guessing the number of fingers in decimal 2. Guessing 1 finger versus 0 fingers 3. Encoding small integers using binary cards 4. Coding using animate versus inanimate objects (“My teacher plays rock, paper, scissors with me.”) * Instructor quickly brings, say, 7 fingers from behind the back. Students make errors in guessing the number. Few errors in 0 versus 1 discrimination. 2012 CSE-BEACON camp16
17
Fundamental coding principle Can rep 2 “things” with 1 bit: yes/no; smiley/sad; high/low; odd/even Can rep 4 “things” with 2 bits; 00:clubs; 01:diamonds; 10:hearts; 11:spades Can rep 8 things with 3 bits 0 00 1 00 0 01 1 01 0 10 1 10 0 11 1 11 2012 CSE-BEACON camp17
18
Fundamental coding principle Each time we add one more bit, we __________ the number of binary strings There are _____ binary strings of length N=7 (think about ASCII code) There are thus ______ possible binary strings of length N bits 2012 CSE-BEACON camp18
19
Recursive description Append a 0 to all 0 00 0 01 0 10 0 11 “all” is what we had before Append a 1 to all 1 00 1 01 1 10 1 11 WHY are all 8 different? 2012 CSE-BEACON camp19
20
2012 CSE-BEACON camp20 ASCII code for characters CHAR CODE A 001000001 a 001100001 B 001000010 b 001100010 C 001000011 c 001100011 + 000101011. 000101110 * 000101010 % 000100101
21
How many characters does a computer need to use? Old Univac system used 6 bit char – a design disaster: _____ symbols max IBM 8-bit code enabled ____ symbols (digits, caps, small letters, punctuation, graphic symbols, bell, null, etc.) Unicode uses 16 bits to code all of the above and international characters: ______ symbols. 2012 CSE-BEACON camp21
22
2012 CSE-BEACON camp22 CD has many tracks of spots Shiny spot is 0 Burned spot is 1 5 billion spots total 700 MB total 44,000 x 16 spots for just 1 second of high fidelity music Laser reads shiny versus dull spots CD CD spins What’s a “CD”?
23
Even parity to detect errors To the 7-bit ASCII code, append one parity bit to have an even # of 1 bits Sender always sends an even number of bits If some disturbance causes a bit to change, receiver gets an odd number or 1-bits in the char code. If error, receiver asks for retransmit. 2012 CSE-BEACON camp23
24
2 nd coding fundamental Any object can be represented by a bit string in a computer A symbol from an alphabet A word from a dictionary One second of music A movie An engine design Your genetic code 2012 CSE-BEACON camp24
25
Numbers as bit strings Binary Places Decimal Cave Man 16 8 4 2 1 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 1 0 2 0 0 1 1 1 7 1 0 1 0 1 21 … 2012 CSE-BEACON camp25
26
2012 CSE-BEACON camp26 Binary Ops easy for machine Addition has few rules. Multiplication has few rules These can be carried out in nanoseconds by computer circuits 0+0 = 0 0+1 = 1+0 = 1 1+1 = 0 with 1 carry 0x0 = 0x1 = 0 1x0 = 0 1x1 = 1
27
1 is 0 is What number? 272012 CSE-BEACON camp
28
0 is 1 is What number? ____ What number? ____ What number? 282012 CSE-BEACON camp
29
0 is 1 is What number? ______ 292012 CSE-BEACON camp
30
Binary coding in a computer Symbol 0 can be represented by +5V and 1 by -5V 0 can be darkness and 1 lightness, as used on CDs and DVDs or in optical fibers 2012 CSE-BEACON camp30
31
Using your “binary cards” Make your age The month of your birth The day of your birth Your father’s age Algorithm: precisely how to do it? 2012 CSE-BEACON camp31
32
Intuitive algorithm 1 Need a list of powers of 2 Go down the list to find the largest power of 2 less than the decimal # Use that power of 2 Subtract it from the decimal # If nothing left, then DONE, else RECURSE 2012 CSE-BEACON camp32
33
2012 CSE-BEACON camp33 Conversion of decimal to binary: Algorithm #1 Let D1 be a decimal integer Let R1 = remainder of D1 divided by 2; R1 is the 1’s bit Let D2 be the dividend of D1/2 Let R2 = remainder of D2 divided by 2; R2 is the bit in the 2’s place. & so on
34
Decimal to binary conversion 2012 CSE-BEACON camp34 INPUT: a decimal number OUTPUT: a binary number PRECISE STEPS: repeated division by 2; recording the remainder TERMINATES?: always (why?) CORRECT?: why?
35
Guessing games 2012 CSE-BEACON camp35 Guessing birthdays: just day of month Guessing month and day Guessing face value of cards Guessing suit and face value
36
36 Programming concepts via Scratch Free download of software available at www.scratch.mit.edu Video tutorials for learning available at www.learnscratch.org 2012 CSE-BEACON camp
37
37 What can we do with Scratch? Learn some computing concepts. Learn some practical algorithms. Use Scratch as computing tool. Have fun with Scratch creating stories, games, art. 2012 CSE-BEACON camp
38
38 Start scratch and let’s go! In the lab, Click on the cat icon Scratch programming environment comes up First do simple things 2012 CSE-BEACON camp
39
39 Explore Scratch environment Stage is at upper right (where actors act and information is displayed) Sprite is another name for actor. Instruction menus/panel at left (instructions for the actors) A script is another name for program or method; a script tells the actor what to do. Programming area in center; here is where we construct scripts for the sprites 2012 CSE-BEACON camp
40
The VARIABLES Menu Implement an average algorithm Make a variable “FIRST” and set it to 12 Make a variable “Second” and set to 15 Make variable “Average” Use OPERATIONS Menu to set the Average to (FIRST+SECOND)/2 Test Scratch and algorithm 2012 CSE-BEACON camp40
41
Square root by repetition Guess sqrt(N) to be 1.0 Set root1 = 1.0 (first factor) Set root2 = N/root1 (second factor) root1 is not likely to = root2 Reset root1 to the average of root1 and root2 (it will be in between them, why?) Reset root2 = N/root1 Repeat all of the above until root1 and root2 are “very close” 2012 CSE-BEACON camp41
42
Algorithm study is RICH! Algorithm to find your BEST mate? What if you had the coding of genes for all possible mates? Algorithm to make bet on Big 10 game? Algorithm to find best molecule to bond with a given input molecule? Algorithm to bond 2 molecules to create “best properties”. 2012 CSE-BEACON camp42
43
Information theory is RICH SETI: Search for Extra Terrestrial Intelligence Jodi Foster movie “Contact” What are the chances that a random signal from space codes “I love you”? Or “X^2+Y^2 = R^2”? 2012 CSE-BEACON camp43
44
44 The LOOKS menu Has instructions for setting the color, size, and visibility of a sprite. Costumes will be used later. 2012 CSE-BEACON camp
45
45 The “hello” script (program) Choose the Looks menu Click on the “say hello” lego block Check your sprite behavior at the right Then click “say hello for 2 secs” Your very first Scratch program! 2012 CSE-BEACON camp
46
46 Try some other looks operations (click on menu items) Change color effect by 25 Change color effect by 25 again Hide Show Change size by 10 Change size by 10 again Set size to 100% 2012 CSE-BEACON camp
47
47 Let’s write a script to Say “hello” for 2 seconds Then change color by 25 Then think “Hmm..” for 4 seconds Then change color by 75 Then change size by 200 Drag each instruction from the menu to the center script area. Connect them into a single block. Edit the parameters to get the numbers we want. 2012 CSE-BEACON camp
48
48 Our script (program) 2012 CSE-BEACON camp
49
49 A sequence or block is a simple script or program The first instruction is done first The second instruction is done second The last instruction is done last. (if any one instruction is done, then every on of them is done) 2012 CSE-BEACON camp
50
50 The WAIT instruction WAIT is needed to slow down the acting so we can see or hear it properly (computers are too fast sometimes) Get the wait instruction from the CONTROL menu. Ignore the other menu options for now. Insert a wait in our looks script 2012 CSE-BEACON camp
51
51 3 second pause between changing color and size 2012 CSE-BEACON camp
52
52 Student exercise: write a script to do the following Double the size of the sprite Wait 2 seconds Change the color of the sprite to green Wait 4 seconds Change the whirl effect to 100 Say “That’s all folks!” 2012 CSE-BEACON camp
53
53 The MOTION menu How to locate and orient a sprite; and, how to move a sprite. 2012 CSE-BEACON camp
54
54 Position on the stage Using the Looks menu, shrink our cat to 25%. Click on the Motion menu. Click to check the box for x- position and y- position Drag your cat around and note its x-y position. 2012 CSE-BEACON camp
55
55 Exercises: goto instruction (do you know about coordinates?) In the Motion menu, drag the “goto xy” instruction to the script panel. Edit the coordinates and click to see the sprite’s position A) goto x=200, y=0 B) goto x=-200, y=0 C) goto x=200, y=-100 Where does the cat go? 2012 CSE-BEACON camp
56
56 The “glide-to” instruction Drag the “glide-to” instruction into your script panel. Edit the coordinate values and click to see where your sprites goes. 2012 CSE-BEACON camp
57
57 Exercise Create a script to glide the sprite along the sides of a triangle. The first vertex of the triangle is (-100, -100). The second vertex is (200, -100). The third vertex is (50, 100). Make sure you complete the triangle. Change the speed of gliding and run again. New feature: click on Pen Down in the Pen Menu and run it again 2012 CSE-BEACON camp
58
Exercise: A fun looping program Position your sprite at the lower left Put the pen down Do the following forever Rotate +5 degrees Move around an equilateral triangle as before (turning 120 degrees each angle) 2012 CSE-BEACON camp58
59
Exercise: bat flying randomly 2012 CSE-BEACON camp59 Make a bat fly by flapping between 2 bat “costumes”. Use random values of coordinates x and y. Use arrows keys to control the bat’s position. * Use a forever loop to make the bat continue to fly when the flag is clicked * See if you can create a “score” variable and use it to count how many times the user clicks on the bat.
60
Exercise: find the MIN of a list Explore how to create a list variable Explore how to input numbers to the list Explore how to pass through the list to set a variable MIN to the minimum in the list Some hints follow 2012 CSE-BEACON camp60
61
Make list L and also a variable for its Length Our list 612012 CSE-BEACON camp
62
Ask the user for list length after the user hits key ‘L’ 622012 CSE-BEACON camp
63
Repeat Length times, ask the user for item k of the List The user has given 3 items and is being asked for item k=4. 632012 CSE-BEACON camp
64
Exercises in Scratch These exercises accompany the EGR 2010 Summer Camp Scratch for session of 5 hours or more.
65
Bat fluttering script Study the example bat-fluttering script A) change the background B) add a variable SPEED to control the speed of the bat C) when clicked on, HIDE the bat for 5 seconds D) add a SCORE variable. Increase the score by 2 when the bat is clicked on; decrease it by 1 when the click misses the bat
66
Mad Lib story Open up the stored example story Mad Lib Study the scripts so you can do the following A) Change the background B) make the little whale do a 1080 flip instead of a 360 C) Change Cassie’s costume every time a whale speaks D) Double Cassie’s size at the end of story
67
Final project A Make a baseball story with these features Baseball field background, batter sprite, ball sprite, and glove sprite Batter can hit grounder with right arrow key Batter can hit fly ball with up arrow key Variable controls speed of ball User can catch ball by dragging glove to it
68
Final project B Create a “knock-knock” story with these features Uses two or more backgrounds and two sprites Uses three or more scenes Final scene has third sprite laughing
69
Final project C Create a pollution balloon bursting game Game ends in 20 seconds Game has 5 balloon sprites; they rise out of a pond [and get smaller as they rise] If mouse click on balloon, then +Y points (Y is the height of the balloon) and hide balloon If balloon reaches height Y=150, then hide it
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.