S-02-ALG-1

.pdf
School
University of British Columbia**We aren't endorsed by this school
Course
CPSC 100
Subject
Computer Science
Date
Jan 6, 2025
Pages
50
Uploaded by JudgeIceManatee52
Administrative NotesSeptember 10, 2024Labs start this weekGet to know your TAs Start forming the project groupsLab 1 is due September 17Last day to add/drop the course is September 161
Background image
Recall – Computational Thinking is “Computational thinking is the thought processes involved in formulating problems and their solutions so that the solutions are in a form that can be effectively carried out by an information-processing agent” [Cuny, Snyder, Wing 10]. 2
Background image
Recap – What is an algorithm? Pick the bestanswerA.A series of steps written to solve a specific problem with specific inputsB.A series of steps written to solve a specific problem with non-specific inputsC.A series of steps written to solve a non-specific problem with specific inputsD.A series of steps written to solve a non-specific problem with non-specific inputs3
Background image
4
Background image
Metacog (MC) Activity – 1 min Think about the answers to the following questions:When you use a calculator app on your phone/computer, where is the data stored?What are the different types of storage that exist on your computer? What are those GB/TB mean when you buy one?What is the relationship between an app on your phone and an algorithm?5
Background image
Learning GoalsCT FoundationsDistinguish the difference between hardware, applications, and the operating system.Differentiate between the different forms of computer memory.Describe Moore’s law and explain its impact on computing.Give examples of a problem for which there are different algorithms, give examples of cases where one algorithm works better than the other.Weigh the tradeoffs to determine which algorithm is likely to work better overall.CT ImplicationsDiscuss the implications of consumeristic approach to hardware development on developing nations6
Background image
Hardware, Memory, TransistorsDistinguish the difference between hardware, applications, and the operating system.Differentiate between the different forms of computer memory.Describe Moore’s law and explain its impact on computing.7
Background image
Hardware vs. SoftwareHardwarerefers to the physical devicesSoftwarerefers to programs that run on the hardware to implement applications8
Background image
Assume positive logic:high voltage = TRUE = 1, low voltage = FALSE = 0.Information represented in digital computers by binary digits (bits).Binary preferred over decimal so circuit operations reliable and repeatable with variations in voltages.Information Representation 2
Background image
How can we store those 0/1 states?Today: 3 nm!20111 µm = 1 millionth of a meter1 nm = 1 billionth of a meter35µm11
Background image
TransistorIt typically has three terminals: the base, the collector, and the emitter. The flow of electric current between the collector and emitter is controlled by the current at the base.12
Background image
Transistor + Capacitor => 1 Bit13
Background image
How do we use so many?ENIAC (1945): Modern laptop:~18,000 ~9,000,000,000,000pieces of datapieces of data14
Background image
Computer memory vs. laundry: registersThe CPU/“chip” actually does the workIt includes registers, which hold the data that the computer is actively working withThis is a bit like the clothes that you are actually wearingIt’s very small, very fast to access15
Background image
Computer memory vs. laundry: cacheThe CPU also has several layers of caches – fast memory that is actually on the chipThis is a bit like keeping clean laundry in a small pile near where you put it on.16
Background image
Computer memory vs. laundry: RAMThe computer also has RAM. It’s not on the chip, but is on the motherboard.This is slowerto access than the cache and a bit bigger, but fairly fast and fairly smallThis is a bit like keeping clothes in a small closet17
Background image
Computer memory vs. laundry: Hard driveThe computer also has a hard drive/solid state drive (ssd)This is not on the motherboard. It’s very slow to access, but generally much, much biggerThis is a bit like keeping clean laundry in a storage locker or at your parents’18
Background image
How far could that be with the electricity speed?19
Background image
Even though these distances seem small, they make a real differenceAdmiral Grace Hopper explains the nanosecond20
Background image
From Transistor to Your Laptop21Transistor (1940s)A transistor is a semiconductor device that can amplify, control, and generate electrical signals. Transistors are usually made from silicon, a semiconductor material that can conduct electricity under certain conditions.Integrated Circuits (1950 -60s)• Combination of multiple transistors to form a chipMicroprocessors (1970s)• 1000s to millions of transistors as a compact unit that function as the central processing unit Advances in Computing Hardware (1980s)• Personal Computers!• GUI, Graphic cards• Floppy disks, CDs• NetworkingDevelopment of Software and Operating Systems (1980s)• WordStar• MS-DOS, UNIX• C, Ada
Background image
Moore’s LawComputer speed and memory on a chip will double every 18 months to 2 years."Intel cofounder Gordon Moore observed in 1965 that every year twice as many [transistors] could fit onto a chip, and in 1975 adjusted the pace to a doubling every two years.”22
Background image
23
Background image
Moore’s Law no longer holds Making chips smaller also makes them faster, but that’s come to an endIn 2019 leading experts (MIT Charles Leiserson, Nvidia CEO Jensen Huang, ARM CTO Mike Muller)note that Moore’s law no longer holds trueThe trend persists but it is slowing down. 24
Background image
Why do you think it is becoming harder to double the number of transistors on a chip?25
Background image
Why do you think it is becoming harder to double the number of transistors on a chip?26https://www.researchgate.net/figure/One-dimension-of-a-nanomaterial-should-be-in-the-1-100-nm-range-As-a-comparison-other_fig1_281278530
Background image
Fortunately, not all computing speed up is due to hardwareWhite line is hardware speedupGreen line includes software speedup (note log plot)27
Background image
Software28
Background image
Special note: Operating SystemAn operating system is a special kind of software that allows the other software to runMost of you probably use Windows or Mac OS29
Background image
So how does software work?Software works by programmers writing down algorithmsin a special language that the computer can understand.Reminder: an algorithmis a precise, systematic method for producing a specified result.30
Background image
That problem was human, but not very common. Let’s look at sorting againYour “computer” sorts things for you every dayE-mailsContactsMusicThere’s so much sorting that a LOT of time has been devoted to coming up with ways to sort.31
Background image
Implication. Research and discuss the following:What are the implications of Apple releasing an iPhone every year on people living in the developing countries?32
Background image
Evaluating Algorithms[CT BB] Give examples of a problem for which there are different algorithms, give examples of cases where one algorithm works better than the other.[CT BB] Weigh the tradeoffs to determine which algorithm is likely to work better overall.[CT BB] Evaluate and compare algorithms in terms of its efficiency (time and space requirements).33
Background image
Sequential Algorithm for Signaling WordsJean-Dominique Baubywas a journalist who had locked-in syndrome. He used the partner-assisted scanning system to dictate a 130 page book by blinking 34
Background image
Sequential Algorithm for Signaling Words“It is a simple enough system,'' Baubyexplains. ''You read off the alphabet . . . until, with a blink of my eye, I stop you at the letter to be noted. The maneuver is repeated for the letters that follow, so that fairly soon you have a whole word.”In other words, you go through each letter, row by row, and read off all the letters.35
Background image
Let’s assume that our goal is to minimize the number of letters that have to be looked at to spell a word. So each letter you look at has a cost of “1”We also have to decide if there’s any extra “cost” to having the “signals”. Let’s say each signal also costs “1”36Counting the Cost
Background image
Example of cost counting: letter FSequential 8 to get to the letter F+ 1 to signal “F”_________________________________9 total costABCD12EFGH34IJKLMNOPQRSTUVWXYZ56789037What is the cost to signal the word “FAN”?
Background image
Clicker QuestionABCD12EFGH34IJKLMNOPQRSTUVWXYZ56789038What is the cost to signal the word “FAN”?A. 26B. 28C. 29D. 30E. 31
Background image
Pay attention to the algorithm in the video. We’ll call the algorithm the Breaking Bad algorithm39Breaking Bad Algorithm
Background image
Example of cost counting: letter FBreaking Bad2 to get to the “E” row1 to signal the “E” row2 to get to “F” in the row+1 to signal “F”________________________________6 total costABCD12EFGH34IJKLMNOPQRSTUVWXYZ56789040
Background image
Clicker QuestionABCD12EFGH34IJKLMNOPQRSTUVWXYZ56789041What is the cost to signal the word “FAN” using the breaking bad algorithm?A.17B.18C.19D.20E.21
Background image
Social Learning (2 minutes)Breaking Bad2 to get to the “E” row1 to signal the “E” row2 to get to “F” in the row+1 to signal “F”_______________________6 total costSequential 8 to get to the letter F+1 to signal “F”____________________9 total costFind a word that works better the Sequential way.Find a word that works better the Breaking Bad way.Which algorithm is better and why?Both words must be at least 4 letters! Use the same chartABCD12EFGH34IJKLMNOPQRSTUVWXYZ56789044
Background image
To calculate the cost to signal a word you created an algorithmYour signal algorithms useddecomposition: breaking the problem down into smaller tasksabstraction: describing the solution in a general way that's applicable no matter what order the letters/numbers are in the table45
Background image
Clicker questionSo which is best in general?A.The first method (sequentially)B.The second method (Breaking Bad)46
Background image
Which way is best? Sequential or Breaking Bad Method?47
Background image
There are many ways to evaluate an algorithm In addition to validity, there are many ways to evaluate (i.e., define “best”)Common ones are time and spaceWe’ll start with spaceThings that take space include: memory slots for cardsmarkers, dividersWe’ll concentrate on memory slots50
Background image
Let’s sort! Sorting algorithm #1: Simple sort1.Moving left-to-right across top row, compare smallest card* so farto remaining cards* to identify smallest card.2.Move smallest card to leftmost empty slot in bottom row.3.If there are any non-king cards in top row, return to step 1.* Empty slots in the top row are treated as kings (larger value than any other card) for the purpose of comparisons.
Background image
How many slots do we need?I will sort 7 cards in two rows, and you keep count of the number of slots we need!52A. 7B.8C.14D. 15E.Other1.Moving left-to-right across top row, compare smallest card* so farto remaining cards* to identify smallest card.2.Move smallest card to leftmost empty slot in bottom row.3.If there are any non-king cards in top row, return to step 1.* Empty slots in the top row are treated as kings (larger value than any other card) for the purpose of comparisons.
Background image
How about time?There are lots of things that we can look at that take timeCopiesSwapsComparisonsLet’s concentrate just on comparisons54
Background image
How many comparisons are needed for Simple Sort(With 7 cards)A. 7B.8C.21D. 42E.Other551.Moving left-to-right across top row, compare smallest card* so farto remaining cards* to identify smallest card.2.Move smallest card to leftmost empty slot in bottom row.3.If there are any non-king cards in top row, return to step 1.* Empty slots in the top row are treated as kings (larger value than any other card) for the purpose of comparisons.
Background image
Last thing for today:Project group finding time!Back of the roomI want to pass!I work early! I procrastinate!Can’t live without A+!Front of the room75
Background image