1 / 230

CS 101 – Jan. 9

CS 101 – Jan. 9. What is this class about? Using the computer to solve problems How to make computers useful for people Understanding what goes on inside (and outside) the machine Commitment Find 5 software companies. What are they best known for? Why is their product useful or popular?.

zorana
Télécharger la présentation

CS 101 – Jan. 9

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CS 101 – Jan. 9 • What is this class about? • Using the computer to solve problems • How to make computers useful for people • Understanding what goes on inside (and outside) the machine • Commitment • Find 5 software companies. What are they best known for? Why is their product useful or popular?

  2. Machine that stores and processes information With memory, machine can be programmed. Memory stores software and other files. Information inside memory is all in binary! CPU’s job is to obey instructions from a program. What is a computer? Memory CPU + * – / % √  Σ file file file

  3. What is CS? • The study of how we… • Solve problems • Classify problems; insight from solutions • Represent information, languages • How to design better computing system • What is knowledge/information? Comes in various types

  4. Software functions What does software need to do? • Input or capture information • Store information for future use • Process: manipulate information and present it in a meaningful form • Output, i.e. allow retrieval of info • Communicate / transmit info to another location • Observe that information can be input to and output from a computer program.

  5. What we need • Computer: an electronic device that can process and store information • Communication network • Know-how: the skills needed to make best use of the computer system • In problem solving, we’d like: • Solutions / results useful for people • Find systematic ways of solving problem, so that the method or solution can be adapted to new problems • Speed • Consistency and reliability • Precision

  6. Human history • Agricultural age (up to ~ 1800) • Industrial age (1800 – 1950) • Information age (1950 --) • We live in an information-based society. In other words, many tasks are defined in terms of doing something with information. • People and businesses depend on IT to get things done. • Not all countries follow this timeline.

  7. Computer History • Analog machines • Abacus • Mechanical calculators, adding machines, cash registers • Babbage suggested a programmable machine • Hollerith adapted Jacquard’s punch cards • Digital machines • ENIAC, ABC, Mark I, Colossus • Became commercially successful in 1950s • Became increasingly affordable by 1980s • Innovations often respond to needs

  8. CS 101 – Jan. 11 • Continue overview • Computer origins • Algorithms • Abstraction

  9. Before 1940s • Only analog machines, moving parts • Specific purpose • Office machines: typewriter, cash register, adding machine • Herman Hollerith’s tabulator • Sunrise/sunset, celestial navigation • General computing only theoretical interest • Alan Turing

  10. 1940s • Code-breaking machines in WW 2 • First general purpose electronic computers • ENIAC, U. of Pennsylvania • ABC, Iowa State • Z3, Konrad Zuse in Germany • Transistor (1947) to have impact later • von Neumann concept forms basis of computer organization

  11. US Army photo

  12. 1950s & 1960s • Commercially produced computers • UNIVAC • IBM • Programming languages developed to facilitate commands to the machine • Colleges begin to teach computing • Large and expensive, gradually adopted in industry • Moore’s Law

  13. 1970s & 1980s • Integrated circuit (1971) allows computers to become much smaller • Intel chips 4004, 8008, 8086, 80286, etc. • Personal (home) computing • Applications for non-specialists: word processing, personal finance, games • Intense competition in HW and SW • Internet initially only used in large companies, universities: low bandwidth

  14. 1990s & 2000s • Computer for communication and mass medium • Internet as a virtual library & soapbox • Tech companies (Apple, Microsoft, Intel, Nokia,…) mature and gain clout • Growing need to manage information

  15. HW & SW • Hardware – physical computer components • CPU, memory, I/O devices, network • Software – programs that run on machine • Allows computer to do useful work (or play) • Tell the computer exactly what to do • Behind any program is its algorithm • The secret to how it really works • Clearly defined list of steps to solve a problem • Needs to be precise, and spell out details • Analogy: • a restaurant building, versus the actual restaurant

  16. Algorithm example • Euclidean algorithm: Given two numbers, find their greatest common divisor…. • Let m = larger, and n = smaller number • Let r = remainder after dividing m/n • If r = 0, then our answer is n, and we’re done. But if r ≠ 0, let m = n, and let n = r, and go to step 2. • Try it out…Do you understand the steps? Does the procedure work? • BTW, an algorithm should also clearly specify its input and output. √

  17. CS 101 – Jan. 13 • Most essential skill: problem solving using the computer • Telling the machine exactly what we want it to do. • Also: making sure result of software is packaged in a way that ordinary people will understand. • Problem solving procedure • What does a solution look like? • Learn by example, and generalize.

  18. Review: Algorithm example • Euclidean algorithm: Given two numbers, find their greatest common divisor…. • Let m = larger, and n = smaller number • Let r = remainder after dividing m/n • If r = 0, then our answer is n, and we’re done. But if r ≠ 0, let m = n, and let n = r, and go to step 2. • Try it out…Do you understand the steps? Does the procedure work? • BTW, an algorithm should also clearly specify its input and output. √

  19. Abstraction • Our way to manage complex problems • Big picture first, then the details • Details omitted until they become important • “top-down” design • Ex. Road map • We can study a machine without knowing how to build one

  20. Why software? • Want computational power • To have direct control of machine • Sometimes, existing software is not sufficient, doesn’t give what you want • Programs can be useful or fun for people to use (e.g. game, converting data to image, …) • Need to use a computer language • E.g. Javascript, PHP, Python, C++, etc. • Machine independent • Many common calculations are pre-defined, such as sorting, opening files, surfing the Web, creating a form button, etc.

  21. Program • One specimen of software is called a computer program • Small or large, purpose is to solve 1 problem. • Works like a recipe • List of necessary ingredients • List of instructions for CPU to obey. • A simple program normally has 3 phases. • Input • Calculations • Output

  22. Recipes • Cooking may be a good analogy, because it solves the problem “I’m hungry”  • What do we see in recipes? Here’s one: • Brown the beef 15 min. Drain grease. • Dice carrot, celery, onion (aka mirepoix) • Cut up and boil 6 potatoes until soft. • Mash potatoes • Add flour, spices, sauce, mirepoix to beef. • Put meat mixture into casserole; top with potatoes. • Bake in oven at 400 for 30 minutes.

  23. Recipes (2) • A computer program has some of the same elements as a recipe. • In recipes, we see: • Ingredients (the “nouns” of the problem) • Steps to perform (the “verbs”) • In some steps, we continue/wait for something • Sometimes we check things • Are potatoes fully mashed? • Should I add more _____ to the mixture?

  24. Recipes inside recipes • But we don’t eat the same stuff every day. Once we know a few recipes, we can put together a menu for choices. if (have all ingredients), make Shepherd’s pie. if (no potatoes), just make soup instead. if (no veggies), make hamburger. if (no beef), make pasta. • When you view a whole menu as a program, then “making soup” becomes a sub-program. • A large program is composed of several parts. • In industry, sometimes each part is implemented by different people, like a kitchen having many chefs.

  25. Problem-solving • Understand problem; inputs and outputs • Write solution in English “pseudo-code” • Write code in a programming language • Compile • Run and test • When program works, can refine or generalize.

  26. CS 101 – Jan. 18 • What is a program? √ • Problem solving procedure √ • Step #2 is most important: write solution (algorithm) in English • Structure of solution: • Sequence of steps (1, 2, 3, …) • Sometimes make a choice • Sometimes need to repeat • Examples • Commitment: • Look over practice problems

  27. Problems • The earliest problems given to a computer were mathematical. • Sometimes there is no clean formula • Many equations can’t be solved analytically. For example: try cos(x) = x. Need to solve numerically. • Ex. Heat equation is a partial differential equation (PDE). Most PDEs have to be solved numerically. • Ex. Calculating a square root. • Even if there is a clean formula, a computer can help automate the calculations.

  28. Problems (2) • What kinds of problems do we solve? • Finding directions • Predicting trends (weather, finance) • Games • Record keeping in a business • Networking and communication • Multimedia (e.g. image processing, animation and graphics) • Compressing and encrypting data • Searching for something (spell check) • …

  29. Algorithm • A clear sequence of steps to arrive at a solution to a problem. Must specify: • Ingredients • Input, output, variables and operations used • The order in which steps are taken • Means that anybody should be able to follow your directions. There is no ambiguity. • Ideally, each step should perform 1 calculation: • Input or output of 1 value • 1 calculation, or 1 decision to make • Calculations usually limited to basic math • In your algorithm, tedious details can be put off until later. Explain big picture first.

  30. Examples • Discuss in general how you would solve these problems: • Print the numbers from 1 to 100. • In this list (3, 2, 7, 5, 4) where is the number 5? • Which room contains my umbrella? • Have 2 people play Tic-Tac-Toe. • Let’s practice fully with these problems: • Ask the user to enter 2 numbers, and output their sum. • Determine a person’s weekly wage, given the number of hours worked and hourly rate. Don’t forget to figure in overtime. • Add the numbers from 1 to 5.

  31. Solutions • Algorithm to add 2 numbers • Ask the user to enter 2 values. • Obtain the input, and call the values a and b. • Set a new variable sum and set it to: sum = a + b. • Output sum. • Weekly wage • Get hours and rate from the user. • Set the wage as follows: • If (hours > 40), use overtime formula • Otherwise, use regular formula • Output wage

  32. CS 101 – Jan. 20 • Example problems requiring a loop • “How many iterations?” • Practice problems • See handout • Work in pairs to devise solution to 1 problem • We’ll discuss results • Commitment: • Prepare more solutions to practice problems

  33. Solutions (2) • Add up the numbers from 1 to 5 • No input! • Need 2 variables: sum and count • The count variable will go from 1 to 5, one at a time. • The sum will start at 0, and we continually add to the sum. • Sum = 0 • Count = 1 • For each value of count from 1 to 5: • Sum = sum + count • Output sum • If we can add 1-5, we can just as easily add 1-1000!

  34. Mystery • What does this algorithm do? • No input. • Create two variables: sum and count. • Sum = 0 • Count = 1 • For each value of count from 1 to 20: • Introduce new variable called temp • Temp = count * count • Sum = sum + temp • Output sum

  35. CS 101 – Jan. 23 • Continue working practice problems • Commitment: Consider these problems • How would you find the largest/smallest number in a list? • How would you count the number of values that are positive? • Counting vowels in a word.

  36. CS 101 – Jan. 25 • Consider these problems • Review searching • Finding largest/smallest • Counting things in a list • More practice problems

  37. Search error • What is wrong with this technique for searching for the value 3 in a list? list = [ 8, 5, 2, 8, 3, 6, 1, 9, 4 ] for each number in the list if that number is 3 found = true else found = false • How should we fix the mistake?

  38. Largest / smallest • How would you find the largest number in a list? • Assume first number is the largest. • For each of the other values, ask if it is larger than what we think the largest value is. If so, update the largest value. • Also keep track of the location of the largest value, in case that is also desired. • Finding the smallest number is analogous • What should we change?

  39. Pseudocode list = { 5, 7, 4, 2, 3, 8, 1 } largest = list[0] location = 0 for count = 1 to 6 inclusive: if list[count] > largest: largest = list[count] location = count Output the largest and location in a sentence, e.g. “I found the value 8 at position 5.”

  40. Counting • To determine how many values in a list are positive… • First, need a separate variable, numPositive, initialized to zero. • Ask each number if it’s positive. If so, add 1 to numPositive. No “else” clause is needed. list = [ -6, 0, 8, 4, 1, -2 ] numPositive = 0 for count = 0 to 5 if list[count] > 0 add 1 to numPositive Output the value numPositive in a sentence.

  41. Vowels • A word can be thought of as a list/array of characters. • Need a numVowels variables, initialized to zero. • For each character in the word, see if it’s a vowel (a, e, i, o or u). If so, add 1 to numVowels. word = "serendipity" length = the length of word numVowels = 0 for each letter c in the word if c is a,e,i,o or u add 1 to numVowels Output numVowels in a sentence.

  42. Programming note • In Python and other languages, if you need to ask several questions inside in if-condition, you need to separate each one with and/or as appropriate. • Each individual condition must be a complete question. • Illegal: if (c == ‘a’ or ‘e’ or ‘i’ or ‘o’ or ‘u’): if (x > 10 and < 20): • Legal: if (c == ‘a’ or c == ‘e’ or c == ‘i’ or c == ‘o’ or c == ‘u’): if (x > 10 and x < 20):

  43. Practice problems • Given a list of numbers, how many are multiples of 5? • Given a year, is it a leap year or not? • Given a number, is it a prime number? • Remaining practice problems from handout.

  44. CS 101 – Jan. 27 • Finish practice problems: designing solutions in English • Various ways of sorting • Handout: • Getting to know Python

  45. Examples • Given a year, is it a leap year or not? • Julian definition • Gregorian definition • Given a number, is it a prime number? • Remaining practice problems from handout. • Double letter (repeated value in a list) • Recognizing a 4 digit number • We know how to find the largest number in a list  • What about finding the 2nd largest or 3rd largest…?

  46. Sorting • Much studied problem in computing – many ways to do it. • Given a list, need to arrange it “in order”. Either ascending or descending. • Some methods do better based on type of data or how the values are distributed. • Enjoy this Web site demo of sorting methods: http://cg.scs.carleton.ca/~morin/misc/sortalg

  47. Some Methods • Selection sort: Find the largest value and swap it into first, find 2nd largest value and put it 2nd, etc. • Bubble sort: Scan the list and see which consecutive values are out of order and swap them. • Insertion sort: Place the next element in the correct place by shifting other ones over to make room. • Merge sort: Split list in half until just 1-2 elements. Merge adjacent lists by collating them.

  48. Homework • Due Monday, at the start of the lab period • Write a short report. Identify 5 software companies. For each one: • What is the company best known for? • Why is their software popular? In other words, why do people find their programs useful? • Quantify how well the company is doing financially. For example, what is the company’s revenue averaged per employee? • Describe employment opportunities at the company (e.g. according to their Web site). • Use highly reputable sources of information, and include all citations/references. Don’t plagiarize. • Turn in a typed document; aim for about 1000 words total.

  49. CS 101 – Jan. 30 • Sorting • Selection and Bubble √ • insertion: place next element in correct place by shifting over other ones to make space • Merge: Repeatedly split list in half until 1-2 elements each. Then merge adjacent lists by collating them. • Computer languages • 3 kinds of software errors

More Related