Intro to Algorithms in SNAP!

Slides:



Advertisements
Similar presentations
Summer Computing Workshop. Introduction to Variables Variables are used in every aspect of programming. They are used to store data the programmer needs.
Advertisements

Mr. Wortzman INTRO. TO COMPUTER SCIENCE. UNIT 1 – CUSTOM BLOCKS.
Mrs. Chapman. Tabs (Block Categories) Commands Available to use Script Area where you type your code Sprite Stage All sprites in this project.
Program Design and Development
Chapter 2: Algorithm Discovery and Design
Mr. Wortzman. Tabs (Block Categories) Available Blocks Script Area Sprite Stage All sprites in this project.
CSC 1701B Computing: Science and Creativity. Outline  Types  Variables  Operators  Control: sequence, selection, repetition  Functions (block headings.
Programming Logic Program Design. Objectives Steps in program development Algorithms and Pseudocode Data Activity: Alice program.
Invitation to Computer Science, Java Version, Second Edition.
UC Berkeley EECS Sr Lecturer SOE Dan Garcia printing-aims-to-prevent-a-piracy-plague/ Quest.
The role of data mining in the last presidential election. A mind-blowing piece on how the Obama campaign used various sources of data to target voters.
CPS120: Introduction to Computer Science Decision Making in Programs.
8-1 Compilers Compiler A program that translates a high-level language program into machine code High-level languages provide a richer set of instructions.
8.1 8 Algorithms Foundations of Computer Science  Cengage Learning.
Introduction to Computer Programming - Project 2 Intro to Digital Technology.
UC Berkeley EECS Sr Lecturer SOE Dan Garcia printing-aims-to-prevent-a-piracy-plague/ Quest.
CS 104 – Fall 2011 Exploring Computer Science Build Your Own Blocks September 19, 2011.
11 Making Decisions in a Program Session 2.3. Session Overview  Introduce the idea of an algorithm  Show how a program can make logical decisions based.
Functions / Blocks.
Topic 1: Transformations and Congruence & Geometry Notation
AP CSP: Creating Functions & Top-Down Design
Creativity of Algorithms & Simple JavaScript Commands
Unit 2 Technology Systems
Week 2 - Wednesday CS 121.
Create a Halloween Computer Game in Scratch
Computer Programming.
AP CSP: The Need for Programming Languages and Algorithms
Scratch for Interactivity
Learning to Program D is for Digital.
Lesson #6 Modular Programming and Functions.
A basic tutorial for fundamental concepts
Lesson #6 Modular Programming and Functions.
The Beauty and Joy of Computing Lecture #4 Functions
GC211Data Structure Lecture2 Sara Alhajjam.
UNIT 3 – LESSON 5 Creating Functions.
Intro to Programming with Scratch
Yenka Portfolio Level for this topic: Student Name : My Levels
CS 240 – Lecture 11 Pseudocode.
Sentinel logic, flags, break Taken from notes by Dr. Neil Moore
Learning to program with Logo
Lesson #6 Modular Programming and Functions.
Sentinel logic, flags, break Taken from notes by Dr. Neil Moore
This Lecture Substitution model
Loops CIS 40 – Introduction to Programming in Python
Computational Thinking for KS3
Coding Concepts (Basics)
Introduction to TouchDevelop
Lesson 3.2 Review: Identifying concepts
Programming We have seen various examples of programming languages
Problem Solving Designing Algorithms.
A look at Python Programming Language 2018.
Flowcharting & Algorithms
Unit 3: Intro to Programming Snap! Introduction
Algorithms and Problem Solving
Lesson #6 Modular Programming and Functions.
Flowcharts and Pseudo Code
JavaScript objects, functions, and events
COMPUTATIONAL THINKING COMPUTATIONAL THINKING IN PROGRAMMING
For loops Taken from notes by Dr. Neil Moore
The structure of programming
Using Decision Structures
This Lecture Substitution model
The structure of programming
This Lecture Substitution model
Creating a Simple Game in Scratch
Thinking procedurally
Lecture 6 - Recursion.
Presentation transcript:

Intro to Algorithms in SNAP! Unit 2: AlgorithmDevelopment

Warm Up: What did your parent mean by “clean your room”? CleanRoom There is a lot “hidden” “behind” the instruction “clean your room” Fold clothes – Fold jeans + Fold shirts – Fold in half vertically with the arms together. Fold the arms back onto shirt. Fold horizontally, so that the hem of the shirt touches the neck. Flatten the shirt. Vacuum + Dust + This is called a “procedure” or a “function”

Reminder: Algorithms CANNOT be ambiguous EX: Algorithms need to be expressed in a context-free, unambiguous way for all participants!

What is Abstraction? The hiding/layering of information Ex: swipe on an iPhone, light switch, pushing any button. These single actions set a chain of many “abstracted” events by programming or invention. The ability to abstract away many of the details of algorithms in subprograms makes it possible to construct, read, and understand large programs. This Photo by Unknown Author is licensed under CC BY-SA

Why do we need to understand abstractions in the form of Processes/Procedures? to bundle processes to manage complexity to create modularity to facilitate collaborative programming of large projects, etc. Basically, they provide a way for a program to specify that some process is to be done, without providing the details of how it is to be done. THIS IS CRUCIAL TO THE PROGRAMMING PROCESS.

You Try. What is an abstraction you use every day You Try! What is an abstraction you use every day? Write An Algorithm for one! Getting Ready for School GetReadySchool How is GetReady School an abstraction? GetReadySchool is an abstraction (in that it hides other parts of for an algorithm with several other functions, such as GetDressed and EatBreakfast. Once GetDressed is completed, the algorithm moves to the next item in the sequence, EatBreakfast, and so on, completing each task in the order presented in the algorithm. GetDressed - Find favorite pair of pants Choose a shirt from the closet EatBreakfast + BrushTeeth + Grab backpack

What should I name my functions?

Last one! What is an algorithm for drawing a square? draw_square

How do we make a square in Snap? This is just ONE way to draw a square in Snap! How do we make a square in Snap? Grab your computer, go to http://snap.berkeley.edu/ Play around with the blocks until you have drawn a square. Hint: use the blue Motion blocks Don’t forget to put the pen down If you need review : https://www.youtube.com/watch?v=cgBmm8edHpU&feature=youtu.be

Which way is “better”? What makes correctly working code “good” code—is it the brevity, the clarity? or some combination? This is the use of iteration (defined on next slide)

Building Blocks of Algorithms Sequencing – the application of each step and an algorithm in a given order Selection – the use of Boolean condition to select which of two parts to do Iteration – the act of repeating a process Recursion - when a function calls itself one or more times in its body

Could we create a procedure (aka function) to always draw a square in this way? In this dialog box, you can choose the block's palette, shape and name. There is also an “Other” option that makes grey blocks in the Variables palette for blocks that don’t fit any category There are three block shapes: - The jigsawpuzzle-piece shaped blocks are Commands, and don’t report a value. - The oval blocks are Reporters - The hexagonal blocks are Predicates, which is the technical term for reporters that report Boolean (true or false) values.

Build your Function that will draw a square! This is a type of “abstraction”

What is a Function in Math? A relationship that has exactly one output for every input. EXS: y = x + 2 y = x² y = sin(x) Plus5 is the function N the input (a number Returns a single value

In Programming, a function is An abstraction that takes in 0 or more inputs, returning exactly 1 output The same inputs MUST yield same outputs Past history of function is (like other inputs that have been called on) don’t affect the current/new one Think of this like a walled world. It can’t do anything else. Just does its job (EX: won’t make something move around or send something to the printer unless that was its job)

What is the difference between an algorithm and a function? An algorithm is a concept of how to accomplish a task. Is language agnostic, usually written in pseudocode EX: A function (aka Procedure) is the implementation of an algorithm in a particular language EX: Different langauges are better suited for different algorithms

Why use Functions? Let’s say you want to make two kinds of Milkshakes: Strawberry or banana Does it make sense to write out two full recipes if you are using the same base, just changing one line for a different fruit? No Way! Its better to use generalization and a common pattern!

Why use functions? They allow for generalization of code They are like building blocks of our programs They can be composed together They help break big problems down into smaller ones (functional decomposition)

Data Types sentences words characters letters If were talking about what were going to pass to a function, we need names of those A SINGLE LETTER CAN ALSO BE A WORD (EX: a )

What is allowed in a function as input and output? THINK DOMAIN AND RANGE FROM MATH CLASS DOMAIN – The characterization or “class” of inputs that a function takes in RANGE – the possible “return” values that a function outputs EXAMPLES y = 𝑥 D: non-negative numbers R:Non-negative numbers Length_of D: Sentence, word, number R:non-negative integer _ < _ D: sentence, word, number R: Boolean (T or F) EX: going to a country with your phone charger and it doesn’t work EX: two words being compared in the dictionary

You can edit your block so that you can adjust the size by adding a parameter! A parameter is a variable that must be given a specific value during the execution of a program Instead of making code for every single size square you want … make a function that takes in a parameter “size”

Then you can make a new block that draws any shape QuickQuizQuestion: What is a custom block called? A procedure What are the inputs called? parameters This might seem familiar from your Unit1/2 modules!

U1 L3 and L5 for classwork! Sprite Line Art and Ping Pong for HW!

What happens if you forget where to find the block? If you forget what palette (color) a block is, but you remember at least part of its name, type control-F and enter the name in the text block that appears in the palette area.