CS 201 Introduction to Computing SPRING 2017
This course will give you Basic computer science notions Mostly C++ programming concepts with emphasis on computational problems Object Oriented Programming language At the end of this course, you will be able to develop algorithms write programs using C++ but not-so-big-applications
Course Information CS201 – Introduction to Computing Website http://myweb.sabanciuniv.edu/gulsend/courses/cs201/ also follow SUCourse an e-mail list will be set up for announcements so you are responsible to check your e-mails (sabanciuniv account) Instructor: Gülşen Demiröz, FENS L015, gulsend@sabanciuniv.edu Textbook: A Computer Science Tapestry, by Owen Astrachan – several copies in the library Weekly or Biweekly Homework Assignments
Course Information Lecture Schedule (in FENS G077): Monday 13:40 - 15:30 Tuesday 15:40 - 16:30 Recitations will start first week See your schedule for date, time and location Recitations will also be used as labs, so please take your laptops with power cables to recitations Freshmans could not register yet. Ask for Special Approval to the recitation: Go to the recitation section that you will add. Attend all. It is to your benefit. Recitation Attendance: %4 of your grade.
Course Policy Grading (might change) Two Midterm Exams + One Final Exam Midterm 1 (23%): March 27th Monday 19:40 – 21:30 Midterm 2 (23%): May 2nd Tuesday 19:40 – 21:30 Final Exam (30% ): scheduled by registrar Recitation Attendance (%4): %1 is left to the TA as “kanaat” Homeworks (20% total): 7 homework will be assigned and they are not of equal weight Important Notice about grading: Weighted average is not the only criterion in letter grading; exam average compared to homework average will also be taken into consideration.
Course Policy No late homework without penalty One late day is allowed at cost of 10% of full grade Plagiarism is not tolerated All homeworks have to be personal. We use tools to detect plagiarized homework. Cooperation is not an excuse If you do not know how to cooperate, don’t do it Grades will be divided into the number of people who cooperated. First case –100 (minus hundred), second fails the course! Detailed policy is on the web site of the course
Course Policy Make-ups (detailed policy is on the web) reports must come before or during the exam you must be really sick to take a make-up exam according to the by-laws, acceptance of report is up to the instructor a medical report does not guarantee taking a make-up exam make-ups will be much more harder
Before CS 201 Maybe you are afraid of computers Maybe you hate How do you use computers. Maybe you used computers just for fun before
During CS 201 You may have bad dreams at the beginning And you may think of you are going nuts But if you work properly and spend considerable amount of time ... Be patient.
At the End of CS 201 Success is yours!
The Burning Question What is Computer Science and Engineering? 10
The Burning Question What is Computer Science and Engineering? What is Science? Science is the study and understanding of the possible (and beyond.) Science is mainly analytic, that is, it tries to analyze, understand and describe nature Observe, hypothesize, predict, evaluate, and refine 11
The Burning Question What is Computer Science and Engineering? What is Engineering? Engineering is the study of the feasible, that is, what is possible within time, space and money constraints. Engineering aims to synthesize the artificial, but, one should have very good analytical skills, also! 12
What is Computer Science? Computer science is the study and the science of the theoretical foundations of information and computation and their implementation and application in computer systems. Information – data Computation – processing, problem solving A computer is a machine that manipulates data according to a list of instructions. The discipline is called informatics in many countries especially in Europe
History of Computer Science Computer Science is a relatively young discipline More than 50 years First graduate program at CMU (then Carnegie Tech) in 1965 in Turkey first CS department in 1977 Turing machine (1937) abstract machine theoretically capable of any computation that we can do with modern computers today
Alan Turing (1912--1954) A scientist and mathematician Watch the movie The Imitation Game Instrumental in breaking a German coding machine during WW II Developed mathematical model of a computer called a Turing Machine (before computers) Showed there are problems that cannot be solved by a computer Was a long distance runner committed suicide
What is Computer Engineering? An engineering discipline for building hardware and software systems that store transmit process information. 16
What do Computer Engineers do? They build systems that process information. They do research into how to build systems: that are new (incorporating new ideas and technology), that solve an important problem unsolved satisfactorily that are “cheap” (so that they are affordable) 17
Building Systems Computer Engineers build information processing systems by bringing together hardware software so that the system works, i.e. has (almost) no bugs is fast, maintainable, robust, and affordable. 18
Computer Science & Engineering Computer Science & Engineering is more than programming!!! Hardware Engineering developing hardware products Software Engineering developing software products Operating Systems Windows, Linux/UNIX, MacOS Graphics animation, entertainment, games Computer Security hacking, digital signatures Computer Networking made internet a reality Artificial Intelligence thinking machines, learning Scientific Computing biocomputing Theoretical CS analyze algorithms …….
Problems, Algorithms, and Programs Problem: A situation that needs to be dealt with Algorithm: Computational procedure for solving a problem. Program: Implementation of an algorithm using a specific programming language to execute on specific platforms Problem Algorithm Program
Problem In general: a situation that needs to be dealt with Some problems: Finding the best phone to buy Tiding up your books so that you can find what you want easier Going from SU Campus to Taksim Square Problems defined more precisely: Finding the cheapest phone to buy Putting your books in alphabetical order so that you can find what you want easier Going from SU Campus to Taksim Square by using a car not having an OGS/HGS I would spend 55 minutes defining the problem and then 5 minutes solving it. -- Albert Einstein
Problem In CS: a situation that needs to be dealt with, by a using computer Some problems in CS: Finding the smallest number in a given set (Finding the cheapest phone to buy) Sorting a given set of items (Putting your books in alphabetical order) Finding a path in a graph (Going from SU Campus to Taksim Square by using a car not having an OGS/HGS)
Algorithms Arabic-originated word Step-by-step process that solves a problem do this, then do that, ... eventually stops with an answer general process rather than specific to a programming language
Algorithms Example algorithms to solve a problem An example algorithm to go from SU Campus to Taksim: Turn right after leaving the campus Drive 2-3km and turn left … A more precise algorithm to go from SU Campus to Taksim: Drive 2512 meters and turn left
Example Algorithms – Find The Heaviest Ball C 3 seemingly identical steel balls A two arm balance scale
Example Algorithm - Find the minimum Initial list: 4 6 7 3 9 1 4 5 Should we sort? 1 3 4 4 5 6 7 9 About (n.log(n)) operations, where n is the number of elements Optimal algorithm - About n operations Pick 4 as the minimum Compare 4 to 6 - min is still 4 Compare 4 to 7- min is still 4 Compare 4 to 3 - Pick 3 as the minimum Compare 3 to 9- min is still 3 Compare 3 to 1 - Pick 1 as the minimum Compare 1 to 4- min is still 1 Compare 1 to 5 - We are done and the minimum is 1
Algorithms Issues correctness complexity and efficiency I picked a number between 1 and 100 You will guess it I’ll respond “high”, “low”, “correct”. how many guesses needed (worst case)?
Programs A program is an implementation of an algorithm using a specific programming language to execute on specific platforms Programming language are needed, because natural languages are vague ambiguous hard to reason about
Programming Languages A programming language is a formal constructed language to communicate instructions to a machine, particularly to a computer High-level programming languages C++, Java, C, C#, Perl, Fortran, Lisp, Scheme, Visual BASIC, ... Low-level programming languages Assembly language
High-Level vs. Low-Level Languages Rather than instruct computers at the level of 0’s and 1’s, higher level languages have been developed. Flexible and easier programming
High-Level vs. Low-Level Languages int main() { int x, y, z; x = 7; y = 12; z = x * y; return 0; } main: pushl %ebp movl %esp,%ebp subl $12,%esp movl $7,-4(%ebp) movl $12,-8(%ebp) movl -4(%ebp),%eax imull -8(%ebp),%eax movl %eax,-12(%ebp) xorl %eax,%eax jmp .L1 .align 4 compiler assembler high-level low-level (assembly) lowest-level (binary)
Compilers Translate a high level language, such as C++, into machine-specific executable program (0s and 1s) The compiler is a program, input is C++ program, output is an executable binary program In theory, C++ source code works on any machine given a compiler for the machine for other languages different compilers are needed
Levels of Programming Language - assembly Machine specific assembly language, Sparc on left, Pentium on right, both generated from the same C++ code main: main: save %sp,-128,%sp pushl %ebp mov 7,%o0 movl %esp,%ebp st %o0,[%fp-20] subl $12,%esp mov 12,%o0 movl $7,-4(%ebp) st %o0,[%fp-24] movl $12,-8(%ebp) ld [%fp-20],%o0 movl -4(%ebp),%eax ld [%fp-24],%o1 imull -8(%ebp),%eax call .umul,0 movl %eax,-12(%ebp) nop xorl %eax,%eax st %o0,[%fp-28] jmp .L1 mov 0,%i0 .align 4 b .LL1 xorl %eax,%eax nop jmp .L1
Data Representation in Computers All types of data are represented in numeric format characters – ASCII (Unicode) codes ‘+’ = 43, ‘A’=65, 'C’=67, ‘Z’=90 colors – RGB values Music files, such as .mp3 files, and video files, such as .mov files are also represented in numbers Emails, tweets, facebook messages Low-level machine instructions And everything else
Data Representation in Computers Internal representation (at the lowest level) is in binary form, i.e., in base-2 numeral system 0s and 1s all arithmetic in binary too Examples 410 = 1002 510 = 1012 6710= 010000112 4310= 001010112
Representation vs. Interpretation Programs instruct computers on how to interpret these binary numbers For Example 0100001100101011001010112 can be interpreted as As string ‘C++’ 0100001100101011001010112 As RGB color C + red green blue
A Simple Scenario Problem Algorithm Program Given 3 numbers, compute their sum Algorithm Display a prompt for data entry Input 3 numbers: number1, number2, number3 sum number1 + number2 + number3 Output sum Program First, we will write a C++ program and run it using MS Visual Studio (sum3num.cpp) Then we will see an animation about the steps taken during the execution
MS Visual Studio .NET (2012) One way of developing C++ programs You will install to your laptops Help will be available in first week labs Check website for instructions on how to install, if you prefer to install before the labs You can install over the network \\software\microsoft\VisualStudio\Visual_Studio_2012 step-by-step installation screenshots are on course web site
A Simple Program – Execution steps
Central Processing Unit COMPUTERS Central Processing Unit (CPU) executes primitive instructions
COMPUTERS Central Processing Unit Random Access Memory (CPU) (RAM) executes primitive instructions Random Access Memory (RAM) stores instructions & data
Memory Primary memory is generally RAM fast data access volatile electricity gone, data gone expensive Secondary memory (storage) Disks, tapes, CD-ROMs, floppies, flash memory non-volatile slow data access cheap ROM (Read-only memory) BIOS (Basic Input Output System) - to start the system (before the operating system)
COMPUTERS Central Processing Unit Random Access Memory (CPU) (RAM) motherboard … bunch of other hardware … Central Processing Unit (CPU) executes primitive instructions Random Access Memory (RAM) stores instructions & data bus instructions & data
COMPUTERS Central Processing Unit Random Access Memory (CPU) (RAM) executes primitive instructions Random Access Memory (RAM) stores instructions & data instructions & data bus keyboard mouse monitor printer hard disk CD-ROM input devices provide instructions and data to the system output devices return data from the system input/output (IO) devices are input and output devices at the same time
A Typical Computer System
A Motherboard
Important Parameters CPU Speed: Hz, MHz(106 Hz), GHz (109 Hz ), etc. Memory Capacity: Megabytes, Gigabytes, etc. Central Processing Unit (CPU) executes primitive instructions Random Access Memory (RAM) stores instructions & data 46
How Much Memory Is That? Bit A basic unit of information storage Stores a binary decision yes/no, or 0/1 47
How Much Memory Is That? Byte 8 bits 1 byte: One character 140 bytes: Longest possible tweet (under certain assumptions) 48
How Much Memory Is That? Kilobyte 1,024 bytes; 210; approx. 1,000 or 103 1 Kilobyte: Joke; (very) short story 2 Kilobytes: Typewritten page 10 Kilobytes: Page out of an encyclopedia 50 Kilobytes: Image of a document page, compressed 100 Kilobytes: Photograph, low-resolution 200 Kilobytes: Two boxes (4000) punched computer (Hollerith) cards 500 Kilobytes: Five boxes, one case (10,000 of punched computer (Hollerith) cards 49
How Much Memory Is That? Megabyte 1,048,576 bytes; 220; approx 1,000,000 or 106 1 Megabyte: Small novel; 3-1/2 inch diskette 2 Megabytes: Photograph, high resolution 5 Megabytes: Complete works of Shakespeare; 30 seconds of broadcast-quality video 10 Megabytes: Minute of high-fidelity sound; digital chest X-ray; Box of 3-1/2 inch diskettes 20 Megabytes: Two boxes of 3-1/2 inch diskettes 50 Megabytes: Digital mammogram 100 Megabytes: Meter of books on a shelf; two encyclopedia volumes 700 Megabytes: CD-ROM 50
How Much Memory Is That? Gigabyte 1,073,741,824 bytes; 230; approx 1,000,000,000 or 109 1 Gigabyte: Paper in the bed of a pickup; symphony in high-fidelity sound; broadcast quality movie 2 Gigabytes: 20 meters of books on a shelf 20 Gigabytes: Audio collection of the works of Beethoven; VHS tape used to store digital data 50 Gigabytes: Library floor of books on shelves 51
How Much Memory Is That? Terabyte 1,099,511,627,776 or 240; approx. 1,000,000,000,000 or 1012 1 Terabyte: All the X-ray films in a large technological hospital; 50,000 trees made into paper and printed; 2 Terabytes: Academic research library 10 Terabytes: Printed collection of the U. S. Library of Congress 50 Terabytes: Contents of a large mass storage system (Google uses many many of these) 52
How Much Memory Is That? Petabyte 1,125,899,906,842,624 bytes or 250 approx. 1,000,000,000,000,000 or 1015 2 Petabytes: All U. S. academic research libraries 20 Petabytes: 1995 production ALL hard-disk drives 200 Petabytes: All printed material; 53
Petabyte Memory What would YOU store if you had a petabyte disk in your laptop? 54
Petabyte Memory What would YOU store if you had a petabyte disk in your laptop? Everything your eyes see Everything you hear/say 55
How Much Memory Is That? Exabyte 1,152,921,504,606,846,976 bytes or 260 approx. 1,000,000,000,000,000,000 or 1018 5 Exabytes: All words ever spoken by human beings. 56
How Much Memory Is That? Exabyte 1,152,921,504,606,846,976 bytes or 260 approx. 1,000,000,000,000,000,000 or 1018 5 Exabytes: All words ever spoken by human beings. Not very clear you would want that in your laptop! Source: How Much Data is That? 57
A Little bit of History Where are we coming from?
First Generation (1951-1959)
First Generation (1951-1959) 1950’s hard drive
Punched Cards Punched Card Input? What Is that?
Punched Cards Punched Card Input? What Is that?
Punch Machines 63
Punched Cards Input with punch cards 64
Second Generation (1959-1965) 1960’s 100 KHz Machines (IBM 1620) 20-30 KB Memory Punched Card Input Teletypes and Line Printers 10-20 MB Disks Consume kilowatts, needs AC cooling ARPANET starts about here also Magnetic disks
Third Generation (1965 - 1971) Integrated circuits Keyboard and monitor Transistors for memory construction 66
Forth Generation (1971 - ?) Large scale integrated circuits The phrase “personal computer” (PC) was coined Apple, Tandy/Radio Shack, Atari, Commodore, Sun, … 67
Very Large Scale Integrated Circuit Technology Xbox One SoC, 2013 5 trillion transistors 853 MHz 768 cores Sparc M7, 2014 More than 10 trillion transistors 3.x GHz: More than 600 times that of 8086 32 cores 9mm 12mm
Historical Perspective Wireless networks take off (3G, IEEE 802.11, Bluetooth, Wi- Max) Broadband reaches households Mobile computing Convergence of hand-held devices (telephone, PDA, Mp3 player, radio, camera) Convergence of home information and entertainment appliances (PC, TV, DVD & CD players) 69
Historical Perspective 2010+: Cars, appliances, telephones, everything have some computing power somewhere, High network bandwidth (and wireless too), Speech and visual interfaces, ubiquitous computing, and gods knows what else. Wearable computers 70
Moore’s “Law” Transistors double every 18-24 months Memory capacity doubles every 18-24 months
Moore’s Law 72
Where we are heading? Single CPU Multiple Users 1 CPU per Person Many CPUs per Person 74
COMPUTER SYSTEMS The Onion Skin Analogy Hardware 75
COMPUTER SYSTEMS The Onion Skin Analogy Operating System (XP, Linux, etc) Hardware 76
COMPUTER SYSTEMS The Onion Skin Analogy Application Support (Window Managers, Graphics, User Interfaces, Development Env.) Operating System (XP, Linux, etc) Hardware 77
COMPUTER SYSTEMS The Onion Skin Analogy Application Support Applications (Word, Firefox, iTunes) Application Support (Window Managers, Graphics, User Interfaces, Development Env.) Operating System (XP, Linux, etc) Hardware 78
COMPUTER SYSTEMS Structural Complexity Hardware – Several trillion transistors Software – 10’s of millions of lines of code Windows XP: 45 millions of lines of source code Premium-class automobile: 100 millions of lines of code So developing a computer system is a VERY, VERY COMPLEX affair.
COMPUTER SYSTEMS Managing this complexity is THE MAJOR PROBLEM in building computer systems. So, such (software) systems are also built in again a hierarchical fashion like the onion-skin analogy. Rather similar to building something with a Lego kit.
COMPUTER SYSTEMS We have small pieces that have certain functionality and interface how they “fit” with others We put them together to achieve a goal The interfaces have to fit The final functionality is what we want
First Program Problem Algorithm Program How many 3-digit positive numbers are there that are divisible by 7, but not divisible by 4? Algorithm Try all 3-digit numbers between 100 and 999 If a number is divisible by 7 but not by 4, increment a counter Display the value of the counter Program myfirstprogram.cpp