Algorithms November 27, 2001. Administrivia Homework Assignment 6 –If you forgot to put your name on it, let me know Homework Assignment 7 –Due next Tuesday.

Slides:



Advertisements
Similar presentations
Pecan cinnamon cookies. Walnut Cinnamon Cookies 1/2 cup unsalted butter 3/4 cup granulated sugar, divided 1/4 cup packed light brown sugar 1 large egg.
Advertisements

Chocolate Chip Cookies. Ingredients: ½ cup butter (1 stick) 1/3 c. brown sugar (packed) 1/3 c. granulated sugar (white) 1 egg 1/ 2 t. vanilla 1 cup +
Announcements The Algorithmic Model Programming Languages Data Assignment Arithmetic.
The Efficiency of Algorithms
Basics of Computer Programming Web Design Section 8-1.
Baking Chocolate Chip Cookies Ms. Davis Life Skill Class July 11th, 2004.
Fractions with Mom’s Chocolate Chip Jumbles By Margie MacDonald.
Cookies In All Kinds and Colors My favorite cookies by Ms. Kampner.
White Chocolate Orange Cookies. 1 cup butter softened 1/2 cup white sugar 1/2 cup brown sugar 1 egg 1 tablespoon orange zest 2 1/4 cups all-purpose flour.
Computability Start complexity. Motivation by thinking about sorting. Homework: Finish examples.
Sorting and selection – Part 2 Prof. Noah Snavely CS1114
What is a program? IT skills: none IT concepts: computer components, program, executing (running) a program, algorithm, information flow inside the computer,
Algorithms (Contd.). How do we describe algorithms? Pseudocode –Combines English, simple code constructs –Works with various types of primitives Could.
What makes a good language Does the task you want Keeps you from making mistakes Supports debugging when you need it Has a strong tool kit.
Sorting and Searching Arrays CSC 1401: Introduction to Programming with Java Week 12 – Lectures 1 & 2 Wanda M. Kunkle.
Streptococcus pneumoniae. Fig. 6.3b Avery, McCarty and MacLoed, 1944.
How to Make Chocolate Chip Cookies By Sara Hokkala.
1.02 I Preparation Tasks List 11.02I Listing Preparation Tasks.
Baking Cookies English Club eats chocolate chip cookies!
Overview of Computing. Computer Science What is computer science? The systematic study of computing systems and computation. Contains theories for understanding.
Problem Solving 101 DEFN An algorithm is a group of instructions (often expressed informally) for performing some task. DEFN An algorithm is a group of.
Lecture 2 Fundamental Data Types. Variable Declaration.
CHAPTER 09 Compiled by: Dr. Mohammad Omar Alhawarat Sorting & Searching.
Computer Science & Engineering An Introduction (and Some Advanced Concepts Too!) Prof. Paul Sivilotti Dept. of Computer Science & Engineering The Ohio.
Warm Up Photosynthesis Prediction Cards – Using the cards, work with a partner to predict the process of photosynthesis from beginning to end.
1.02 C Work Plans 1 The secret for success!. Why use a work plan? Helps meal preparation run smoothly Implement these steps: 1.02CWork Plans2 Steps 1-
The Algorithmic Model. What is Computer Science What is Programming Algorithms –Definition –Properties of Good Algorithms –Describing Algorithms –Examples.
Instructional Video Read the Recipe Select Ingredients And Equipment Prepare The Recipe BAKING COOKIES IN THE VIRTUAL WORLD HELP About LO.
Chapter 13 Recursion. Learning Objectives Recursive void Functions – Tracing recursive calls – Infinite recursion, overflows Recursive Functions that.
CSIS 123A Lecture 9 Recursion Glenn Stevenson CSIS 113A MSJC.
LECTURE 40: SELECTION CSC 212 – Data Structures.  Sequence of Comparable elements available  Only care implementation has O(1) access time  Elements.
Computer Science An Introduction and Some Advanced Concepts Too! Prof. Paul Sivilotti Dept. of Computer & Info. Science The Ohio State University
Cookies !. Ingredients: 3/4 cup granulated sugar 3/4 cup packed brown sugar 1 cup butter or margarine, softened 1 teaspoon vanilla 1 egg 2 cups Gold Medal.
What you’ll need 2 ½ cups of all – purpose flour 1 teaspoon baking soda 1/2 teaspoon of salt 1 cup granulated sugar 2 eggs.
Functional Text. What is “functional text?” Instruction manuals Recipes Lists of facts (ex: nutrition facts) Table of contents Index Directions That is.
How to make chocolate chip cookies By Rose Savage.
How to Make Chocolate Chip Cookies Caity Jozwiak Period 6.
The 5 Parts of a Recipe Obj. F2.01 Remember recipe parts & resources.
Chapter 11Java: an Introduction to Computer Science & Programming - Walter Savitch 1 Chapter 11 l Basics of Recursion l Programming with Recursion Recursion.
Algorithms A well-defined computational procedure that takes some value as input and produces some value as output. (Also, a sequence of computational.
ICS201 Lecture 21 : Sorting King Fahd University of Petroleum & Minerals College of Computer Science & Engineering Information & Computer Science Department.
Introduction to design and analysis algorithm
INVITATION TO Computer Science 1 11 Chapter 2 The Algorithmic Foundations of Computer Science.
How to Make Chocolate Chip Cookies
REESES PEANUT BUTTER CUP COOKIES By:Darnita Coles.
Chocolate Chip Cookies Measurements. Measure Smarter 18 (v) oz. all-purpose flour 1/3 T baking soda 3/4 t & 2 pinches salt 2 sticks butter, softened 12.
1 The Role of Algorithms in Computing. 2 Computational problems A computational problem specifies an input-output relationship  What does the.
How to Make Chocolate Chip Cookies Fast, Easy, and Yummy Original Author Unknown Modified By: CTAE Resource Network.
1 Introduction to design and analysis algorithm. 2.
Kitchen Measuring Equipment. Measuring 2 Categories of Measuring Equipment Liquid Dry.
How to Make Peanut Blossom Cookies By Aubrey Hillman November English 393.
Recipe Notes.
Basics of Computer Programming
Lecture 2: Static Methods Expressions reading: 1.4 – 2.1
Basics of Computer Programming
Basics of Computer Programming
Basics of Computer Programming
Teach A level Computing: Algorithms and Data Structures
Maple Peanut Butter Thumbprint Cookies
Chocolate Chip Cookies
Algorithm Discovery and Design
Welcome back to Software Development!
Welcome back to Software Development!
Let’s make Cookies!.
Algorithms vs. Programming
COOKIE BAKING LESSON.
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Chapter 13 Recursion Copyright © 2010 Pearson Addison-Wesley. All rights reserved.
Algorithms vs. Programming
Presentation transcript:

Algorithms November 27, 2001

Administrivia Homework Assignment 6 –If you forgot to put your name on it, let me know Homework Assignment 7 –Due next Tuesday Lab 6 (Visual Basic Part 2) –This week; due Friday

The big picture We built a computer We built an operating system to control the computer We attached the computer to a network We wrote a compiler to make programming the computer easier We share CPU and disk across the network Need to talk about algorithms

Algorithms Recipes for doing computations The underpinnings of programming –Think out your algorithm –Show that it works –Determine it’s efficiency –Write it as a program

What is an algorithm Algorithm is a recipe Has –Inputs –Rules –Evaluation Criteria –Output

When do we use algorithms? Always! Assignment 5 –Step 1 -- Create a message of between 150 and 200 characters that you wish to transmit. –Step 2 -- Give an encoding of the alphabet –Step 3 -- Use the compression ideas we discussed to compress your message. –Step 4 -- Write your compressed message as a sequence of hexadecimal digits in this encoding. –Step 5 -- Now you are ready to create the message to be hidden. Your message will … – Step 6 -- We now consider a picture that could be displayed on your web page.

Examples of problems Baking cookies Putting things in alphabetical order Being a web search engine

Chocolate chip cookies

Input –flour (2 ¼ c) –baking soda (1t) –salt (1t) –butter (1c) –granulated sugar (3/4 c) –brown sugar(3/4c) –vanilla(1t) –eggs (2) –chocolate chip morsels (2c) –chopped nuts (1c) Output –5 dozen cookies

Chocolate chip cookies Steps in the algorithm –Combine flour, baking soda, and salt in small bowl. –Beat butter, granulated sugar, brown sugar and vanilla in large bowl –Add eggs one at a time Beating after adding each egg –Gradually beat in flour mixture –Stir in morsels and nuts –Drop by rounded tablespoons onto ungreased baking sheets –Bake 9-11 minutes –Let stand for 2 minute

Chocolate chip cookie algorithm Primitives –Inputs Flour, baking soda, salt, butter, brown sugar, granulated sugar, vanilla, egg, morsels, nuts Alternatively, chocolate chip cookie mix Alternatively, wheat, sugar cane, hen, … –Operators Combine, Beat, Gradually beat, Stir, Drop, Bake, Let stand

Chocolate chip cookie algorithm Execution –First 2 steps can be done in parallel? Parbegin (Combine(),Beat()) Parend –Machine dependencies Ovens vary (Bake 9-11 minutes) Ingredients vary and so need to be handled differently

Chocolate chip cookie algorithm Algorithm testing –Proof of the pudding is in the eating –How do we mechanize this?

Chocolate chip cookie algorithm Comparing different algorithms –Quality of input/output map –User time –Machine (oven) time

Putting things in alphabetical order Data set sizes –Course list for COS students –PU directory assistance10,000 people –Manhattan phone book1 million people –Social Security database1 billion records –Long distance call billing records 100 billion/year Different methods for different tasks –Fast for large –Simple for small

A simple method for sorting Find smallest value -- put it first in list Find second smallest value -- put it second … Find next smallest value – put it next … When no more values, you’re done

How it works

How it works Find smallest value -- put it first in list

How it works Find second smallest value -- put it second

How it works Finish the sorting

A simple method for sorting To sort array x = {x[1],x[2], …, x[n]} For I = 1 to n For J = I+1 to n If (x[I] > x[J]) Then swap their values next

Another sorting algorithm Sorting by Merging Key idea  It’s easy to merge 2 sorted lists Sort larger lists by –Sort smaller lists –Merge the results How do we sort smaller lists?

Merging 2 sorted lists

Merging 2 sorted lists Start at the top of each list

Merging 2 sorted lists is bigger than 155

Merging 2 sorted lists Record 155 and move the arrow

Merging 2 sorted lists is less than 255

Merging 2 sorted lists Finished when at the end of each list

Sort then merge Subdivide

Sort then merge Subdivide Sort pieces By merging

Sort then merge Subdivide Sort pieces By merging Merge

SortMerge algorithm Function SortMerge(x,1,n) If n = 1 then Return End if Mid = (1+ n)/2 SortMerge(x,1, Mid ) SortMerge(x, Mid +1, n) Merge(x,1, Mid, Mid +1, n) End Function

Does it work? Have to be careful about stopping There are always a lot of things going on Sort(n) Sort(n/2) Merge Sort(n/4) Merge Sort(n/2) Merge Sort(n/8) Merge Sort(n/4) Merge Sort(n/2) Merge

Divide and conquer Use recursion –reduce solving for problem of size n to solving two problems of size n/2 –then combine the solutions S(n) = 2 S(n/2) + M(n/2,n/2) Solving a sorting problem of size n requires solving 2 sorting problems of size n/2 and doing a merge of 2 sets of size n/2

Comparing running times NInsertion (ms) SortMerge(ms) , , ,000,

Comparing running times NInsertion (ms) SortMerge(ms) , , ,000, Reducing 20 hours to 3 seconds

Searching Once a list is in alphabetical order, how do you find things in it? For example, is COS 111 on the list of courses that satisfy the (EC) Epistemology and Cognition requirement?

EC courses PHI 201 PHI 204 PHI 301 PHI 304 PHI 312 PHI 321 PHI 333 PHI 338 PSY 255 PSY 306 PSY 307 PSY 316 AAS 391 ANT 201 COS 302 FRS 135 FRS 137 GER 306 HUM 365 LIN 213 LIN 302 LIN 306 LIN 315 PHI 200

Searching for COS 111 Compare to the middle AAS 391 ANT 201 COS 302 FRS 135 FRS 137 GER 306 HUM 365 LIN 213 LIN 302 LIN 306 LIN 315 PHI 200 PHI 201 PHI 204 PHI 301 PHI 304 PHI 312 PHI 321 PHI 333 PHI 338 PSY 255 PSY 306 PSY 307 PSY 316 COS 111

Searching Compare to the middle If smaller search first half If larger search second half AAS 391 ANT 201 COS 302 FRS 135 FRS 137 GER 306 HUM 365 LIN 213 LIN 302 LIN 306 LIN 315 PHI 200 PHI 201 PHI 204 PHI 301 PHI 304 PHI 312 PHI 321 PHI 333 PHI 338 PSY 255 PSY 306 PSY 307 PSY 316 COS 111

Repeat Compare to the middle If smaller search first half If larger search second half AAS 391 ANT 201 COS 302 FRS 135 FRS 137 GER 306 HUM 365 LIN 213 LIN 302 LIN 306 LIN 315 PHI 200 COS 111

Building indices PHI 201 PHI 204 PHI 301 PHI 304 PHI 312 PHI 321 PHI 333 PHI 338 PSY 255 PSY 306 PSY 307 PSY 316 AAS 391 ANT 201 COS 302 FRS 135 FRS 137 GER 306 HUM 365 LIN 213 LIN 302 LIN 306 LIN 315 PHI 200 AAS ANT COS FRS GER HUM LIN PHI PSY

Search indices then data PHI 201 PHI 204 PHI 301 PHI 304 PHI 312 PHI 321 PHI 333 PHI 338 PSY 255 PSY 306 PSY 307 PSY 316 AAS 391 ANT 201 COS 302 FRS 135 FRS 137 GER 306 HUM 365 LIN 213 LIN 302 LIN 306 LIN 315 PHI 200 AAS ANT COS FRS GER HUM LIN PHI PSY COS 111

How do we describe algorithms? Pseudocode –Combines English, Visual Basic constructs –Works with various types of primitives Could be + - / * Could be more complex things –Describes how data is organized –Describes operations on the data –Is meant to be higher level than programming

Searching with indices (pseudocode) Build the indices –Do this by going through the list and determining where department names change –Store the results in an array called Indices Search the indices –Do a binary search on the array Indices Do this by comparing to the middle element –Then use binary search to compare to the upper half –Or use binary search to compare to the lower half

Building a web search engine Crawl the web Organize the results for fast query processing Process queries

Crawl the web Every month use TCP/IP to go to all reachable web pages –1.5B pages, 10 Kbytes/page, so 15 terabytes Can compress an average page to 3Kbytes Numeracy –Crawl 1.5B pages in 14 days so Crawl 100M pages per day Crawl 4M pages per hour Crawl 1,000 pages per second

Organize the results Put into alphabetical order Build indices Make multiple copies so that searching can proceed in parallel. When you update, you rebuild the indices

Process queries Look up indices Look up words/phrases –Advertiser can buy a word or phrase This search gives you internal addresses of web pages –Look them up to build results page

Searching time Want to answer a query in less than ½ second Use PageRank to get good results

Page Rank The web is a collection of links –A document’s importance is determined by How many pages point to it How important those pages are –This is its PageRank Used for determining –How often to crawl a page –How to order pages presented.

Remaining subtask Matching strings –Is this the word computer? Comparing strings –Did the word computer occur before or after?

How does string matching work? State machines –Move along states as long as you keep matching –Back off when you miss a match

State machine – looking for abcd Read a Read bRead c Read d Other SaSa SbSb ScSc SdSd OK

State machine – looking for abcd Read a Read bRead c Read d Other SaSa SbSb ScSc SdSd OK What happens if input is abccadbacabcd? S a S b S c S d S a S b S a S a S b S a S b S c S d OK

State machine – looking for abcd Read a Read bRead c Read d Other SaSa SbSb ScSc SdSd OK What happens if input is abcabcd? S a S b S c S d S a S a S a S a

State machine – looking for abcd Read a Read bRead c Read d Other SaSa SbSb ScSc SdSd OK Read a

Larger search challenges Allow strings to have don’t cares –Starts with a and ends with e –Has come number of copies of the substring ab Finding strings close to your string –For spelling corection

Algorithms -- summary Methods of modeling processes Understand at a high level Make sure your reasoning is correct Worry about efficiency in situations where that matters Write as pseudocode

What’s next Problems for which there are no algorithms Problems for which all algorithms run slowly Applications of problems where algorithms run slowly