Administrative Notes January 19, 2017

Similar documents
Administrative Notes January 19, 2017

Definition: A data structure is a way of organizing data in a computer so that it can be used efficiently.

Repetition Algorithms

CLICKERS: A TOUCH OF CLASS

CS110D: PROGRAMMING LANGUAGE I

Algorithms. Chapter 8. Objectives After studying this chapter, students should be able to:

8 Algorithms 8.1. Foundations of Computer Science Cengage Learning

Lippincott Procedures General User Training Video

Lecture Transcript While and Do While Statements in C++

Practice Midterm Examination #1

Chapter 8 Algorithms 1

SORTING AND SEARCHING

Comp 151. Control structures.

CPSC 311: Analysis of Algorithms (Honors) Exam 1 October 11, 2002

Lesson Share TEACHER'S NOTES LESSON SHARE. ing by Olya Sergeeva. Overview. Preparation. Procedure

Moodle Quick Start Guide: Scheduling Student Appointments Using the Scheduler

COS 116 The Computational Universe Laboratory 8: Digital Logic II

About this sample exam:

Moodle Quick Start Guide: Scheduling Student Appointments Using the Scheduler

17 February Given an algorithm, compute its running time in terms of O, Ω, and Θ (if any). Usually the big-oh running time is enough.

Pseudocode. ARITHMETIC OPERATORS: In pseudocode arithmetic operators are used to perform arithmetic operations. These operators are listed below:

Chapter 4 Loops. Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved.

CPSC 121: Models of Computation. Module 5: Predicate Logic

Organizing Data The Power of Structure...

Comp 151. Control structures.

CPSC 259 admin notes

Searching Algorithms/Time Analysis

A DarkBasic DataBase By:

CSC258: Computer Organization. Memory Systems

Moodle Quick Start Guide: Scheduling Student Appointments Using the Scheduler

Lab Two Using Wireshark to Discover IP NAME:

Why study algorithms? CS 561, Lecture 1. Today s Outline. Why study algorithms? (II)

COMP 250. Lecture 7. Sorting a List: bubble sort selection sort insertion sort. Sept. 22, 2017

Sorting. Chapter 12. Objectives. Upon completion you will be able to:

CS 137 Part 8. Merge Sort, Quick Sort, Binary Search. November 20th, 2017

Excel: Tables, Pivot Tables & More

MATH 1131Q - Calculus 1.

Introduction to C Final Review Chapters 1-6 & 13

Lecture 02. The "Moves" and Quiz 0

Computer Architecture 2/26/01 Lecture #

To become familiar with array manipulation, searching, and sorting.

1 CSE 100: HASH TABLES

Simple Graph. General Graph

public static <E extends Comparable<? super E>>void BubbleSort(E[] array )

Tutorial 9. SOLUTION Since the number of supported interfaces is different for each subnet, this is a Variable- Length Subnet Masking (VLSM) problem.

Tutorial 1 Creating a Personal Call Flow

Chapter 5 Loops Liang, Introduction to Java Programming, Tenth Edition, Global Edition. Pearson Education Limited

APPOINTMENTS AND EVENTS

Lecture 11. Lecture 11: External Sorting

0.1 Welcome. 0.2 Insertion sort. Jessica Su (some portions copied from CLRS)

Data Structures and Algorithms Sorting

Course contents. Overview: Goodbye, calculator. Lesson 1: Get started. Lesson 2: Use cell references. Lesson 3: Simplify formulas by using functions

Arrays: Higher Dimensional Arrays. CS0007: Introduction to Computer Programming

Statistics: Interpreting Data and Making Predictions. Visual Displays of Data 1/31

January 2018 Exam Timetable

Welcome to CS61A! Last modified: Thu Jan 23 03:58: CS61A: Lecture #1 1

COMP-202: Foundations of Programming. Lecture 4: Flow Control Loops Sandeep Manjanna, Summer 2015

Course No: 4411 Database Management Systems Fall 2008 Midterm exam

PROGRAMMING CONCEPTS

Understanding the problem

CS 261 Spring 2013 Midterm

Logic & Algorithms Foundations of Computer Science Behrouz A. Forouzan, Brooks/Cole Thomson Learning, Pacific Grove, USA, 2003.

Introduction to Functional Programming. Slides by Koen Claessen and Emil Axelsson

2.3 Algebraic properties of set operations

CS 374 Fall 2014 Homework 5 Due Tuesday, October 14, 2014 at noon

Differentiability and Tangent Planes October 2013

Chapter 3: Mirrors and Lenses

EXTERNAL INQUIRIES. Objective of Section: Definition: Rating:

Exam Datastrukturer. DIT960 / DIT961, VT-18 Göteborgs Universitet, CSE

Lines and Planes in 3D

Excel Basics Rice Digital Media Commons Guide Written for Microsoft Excel 2010 Windows Edition by Eric Miller

Arrays Structured data Arrays What is an array?

Microsoft Excel Pivot Tables & Pivot Table Charts

Escher s Tessellations: The Symmetry of Wallpaper Patterns II. Symmetry II

Data Structures and Algorithms Key to Homework 1

Q1 Q2 Q3 Q4 Q5 Total 1 * 7 1 * 5 20 * * Final marks Marks First Question

June 10, Dear Students and Parents,

Lab 5. Using Fpro SoC with Hardware Accelerators Fast Sorting

Sets: Efficient Searching and Insertion

Control Structures II. Repetition (Loops)

Student Outcomes. Lesson Notes. Classwork. Discussion (4 minutes)

Motivations. Chapter 5: Loops and Iteration. Opening Problem 9/13/18. Introducing while Loops

Physics 2660: Fundamentals of Scientific Computing. Lecture 5 Instructor: Prof. Chris Neu

CS 137 Part 7. Big-Oh Notation, Linear Searching and Basic Sorting Algorithms. November 10th, 2017

COSC 311: ALGORITHMS HW1: SORTING

COMMERCIAL BANKING. ChAsE COMMERCIAL ONLINE sm ALERTs ACTIvATE ALERTs. Step. Step 2. From the My Accounts page, click "Manage Account Alerts.

Lesson B Objectives IF/THEN. Chapter 4B: More Advanced PL/SQL Programming

Arrays. Array Basics. Chapter 8 Spring 2017, CSUS. Chapter 8.1

Data Structures and Algorithms in Java. Second Year Software Engineering

High Dimensional Indexing by Clustering

Hot X: Algebra Exposed

Chapter 4 Loops. Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved.

Repetition and Loop Statements Chapter 5

CS4961 Parallel Programming. Lecture 12: Advanced Synchronization (Pthreads) 10/4/11. Administrative. Mary Hall October 4, 2011

COMP 465: Data Mining Classification Basics

Homework 3 Solutions

Introduction to Database Systems CSE 344

MATH10001 Mathematical Workshop. Graphs, Trees and Algorithms Part 2. Trees. From Trees to Prüfer Codes

Turn in a printout of your code exercises stapled to your answers to the written exercises at 2:10 PM on Thursday, January 13th.

Goal Management with Microsoft Outlook. Workbook

Transcription:

Administrative Notes January 19, 2017 Reminder: In the News due on Friday Reminder: Reading Quizzes due next Monday Anne will be away next Monday and Tuesday and will not have office hours on Monday Jessica will teach Tuesday s class on the Internet

How do programs work? Part 2 Snap! code for Sorting 2

Learning goals [CT Building Block] Explain what a variable is in computer programming. [CT Building Block] Be able to trace through code using sequences of instructions, variables, loops, and conditional statements in short programs specified in a visual programming language such as Snap, or in other clearly expressed processes (which may or may not be computer related) 3

Programs, data and lists You ve seen programs that do simple things with data (your age, shoe size, the mouse position, text, etc.) Sorting typically involves lists of data items. We can create lists in Snap! For now, we'll create a short list of five items manually, But a list containing hundreds or more items could imported to Snap from a file

We can give our list a name

We can give our list a name

Why give a name to a list? Names enable us write programs that do useful things with lists, like sort them We ll first use some clicker questions to see how to query what s in a list, compare two items in the list, and more Note that the items in our list are indexed consecutively, starting from 1

Snap! operations on lists Clicker question What will the sprite say, when this code is run? A. 5 B. 7 C. 22 8

Snap! operations on lists Clicker question Suppose we make a new variable, current. What does the sprite say now? A. 3 B. 4 C. 5 D. 7 9

Snap! operations on lists Clicker question And now? A. 2 B. 3 C. 5 D. 7 10

Snap! operations on lists Clicker question Suppose we make yet another new variable, called marked and run the following code fragment Does the following inequality hold? (True or False) A. True B. False 11

Testing if a list is sorted Suppose we have a mystery list with five different positive numbers. How could we test whether it is sorted in increasing order? In groups, develop an algorithm to do this. Write down your algorithm in English. (Imagine that you have a list of cards.)

Testing if a list is sorted Student algorithm What are your algorithms?

Testing if a list is sorted Here s an algorithm that we ll code in Snap: Compare items 1 and 2; if item 1 is greater than item 2, then report that the list is not sorted and stop Compare items 2 and 3; if item 1 is greater than item 2, then report that the list is not sorted and stop Continue in this way until the end of the list is reached, and (if the algorithm has not already stopped) report that the list is sorted

Testing if a list is sorted Code for the step of comparing items 1 and 2:

Testing if a list is sorted Code for the step of comparing items 1 and 2: How would you change this code to do the right thing for items 2 and 3?

Testing if a list is sorted Code for the step of comparing items 1 and 2, plus 2 and 3:

Testing if a list is sorted For a list with five items, how many if blocks would we need?

Testing if a list is sorted For a list with five items, how many if blocks would we need? And for a list with a million items? Writing all that code would be tedious! Is there a better way to code repetitive tasks?

Testing if a list is sorted Student ideas (better coding of repetition) Express the code in terms of add one each time, rather than listing each step explicitly Refer to the length of list rather than using a number Use a repeat loop

Testing if a list is sorted: using a repeat loop Set a counter i to be 1 Repeat the following 4 times: Compare items i and i+1; if item i is greater than item i+1, then report The list is not sorted and stop Increment i by 1 Report The list is sorted

Testing if a list is sorted: using a repeat loop First try: make variable i, set it to 1, and compare items i and i+1

Testing if a list is sorted: using a repeat loop Second try: add the repeat loop:

How many variables are in this code? Clicker question A. 1 C. 3 B. 2 D. 4

Finding the smallest item in a list Recall how we did this with cards

Finding the smallest item in a list Recall how we did this with cards We ll use a variable called marker to store the index of the smallest item found in the list so far We ll use another variable called current to help us work through the other items in the list and compare them with the marked item

Finding the smallest item in a list How to initially set marker and current?

Finding the smallest item in a list How many times should we repeat?

Finding the smallest item in a list

What if we want to change a list?

What if we want to change a list? We can add and delete things from lists

What if we want to change a list? We can add and delete things from lists

What if we want to change a list? What will the list look like after the following code? A. B.

What if we want to change a list? What will the list look like after the following code? A. B.

What if we want to change a list? What will the list look like after the following code? A. B.

What if we want to change a list? What will the list look like after the following code? A. B.

We re ready to sort!

We re ready to sort! First, create a new list, called sorted-list, which initially has no items in it

We re ready to sort! Then repeat the following: Find the smallest item in the unsorted list Add it to (the end of) the sorted list Delete it from the unsorted list

We re ready to sort!

Learning Goals Revisited [CT Building Block] Explain what a variable is in computer programming. [CT Building Block] Be able to trace through code using sequences of instructions, variables, loops, and conditional statements in short programs specified in a visual programming language such as Snap, or in other clearly expressed processes (which may or may not be computer related) 41