Presentation is loading. Please wait.

Presentation is loading. Please wait.

Slide 1 of 56. Lecture A Noam nisan מבוא למדעי המחשב פרופ' נעם ניסן.

Similar presentations


Presentation on theme: "Slide 1 of 56. Lecture A Noam nisan מבוא למדעי המחשב פרופ' נעם ניסן."— Presentation transcript:

1 Slide 1 of 56. Lecture A Noam nisan מבוא למדעי המחשב פרופ' נעם ניסן

2 Slide 2 of 56. Lecture A Noam nisan Lesson A - Introduction Unit A1 – About This Course

3 Slide 3 of 56. Lecture A Noam nisan מבוא למדעי המחשב (מואץ) -- 67101 מרצה: פרופ' נעם ניסן  שעת קבלה: יום ג' 1-2, בנין רוס, חדר 218 מתרגלים  יואב ולד, יעקב וייס ("צארים"), דביר ארן, ליאור ויצמן אתר הקורס: http://moodle.cs.huji.ac.il/cs11/course/view.php?id=67101 קורס מקביל – מבוא למדעי המחשב 67130  מרצה: פרופ' דני לישינסקי  אותו חומר, אותו מבחן, אותם תרגילים, אותן נקודות זכות  שעה פרונטלית יותר בשבוע – מיועד לתלמידים ללא נסיון תכנות קודם

4 Slide 4 of 56. Lecture A Noam nisan תכני הקורס (וכל לימודי מדעי המחשב) -- מלמעלה הפשטה: ממשק ומימוש קורסים: מעבדות תכנות, תכנות מונחה עצמים הנדסת תוכנה  קורסים: מעבדות תכנות, תכנות מונחה עצמים מערכות חישוב ותוכנה  קורסים: מיתוג, מסדי נתונים, מערכות הפעלה אלגוריתמים  קורסים: אלגוריתמים, חישוביות מבני נתונים  קורסים: מבני נתונים, מסדי נתונים שפה ומשמעות  קורסים: מתמטיקה, לוגיקה, חישוביות, שפות תכנות, מהדרים

5 Slide 5 of 56. Lecture A Noam nisan מבנה הקורס חלק I: תכנות בסיסי:  קלט ופלט, משתנים, ביטוים השמות, פקודות, שימוש באובייקטים, בחירות, לולאות, הפשטה והגדרת ממשק, יצירת אובייקטים, מערכים חלק II: אלגוריתמיקה בסיסית:  תכנון, הפרד ומשול, נכונות והוכחתה, יעילות וזמן ריצה, רקורסיה, מיון וחיפוש, אלגוריתמים על מספרים חלק III: תכנות מתקדם יותר:  ירושה ופולימורפיזם, תכנון כחוזה, בדיקת תוכנה, תבניות, מבני נתונים מקושרים, שימוש בספריות

6 Slide 6 of 56. Lecture A Noam nisan דרישות הקורס תרגיל תכנות כל שבוע (לפעמים כל שבועיים).  הרבה עבודה. אין ברירה.  מומלץ לדון עם חברים  אסור!!!!! להעתיק  הבחנה: דיון = דיבורים בעל פה העתקה = שיתוף של חומר כתוב או מודפס או ממוחשב מבחן ציון סופי: 50/50 כדי לעבור את הקורס יש לקבל ציון עובר הן במבחן והן בממוצע התרגילים

7 Slide 7 of 56. Lecture A Noam nisan הודעות בשבוע הראשון ללימודים קבוצות התרגיל יערכו במעבדות המחשבים:  יום רביעי: באקווריום – מעבדות רוטברג (קומה 1-)  יום חמישי: בנין לוי, קומה 1 נא לפתוח חשבון לפני התרגיל הראשון – הוראות בדפים שעל השולחן (וגם באתר)

8 Slide 8 of 56. Lecture A Noam nisan Lecture A: Computability Unit A2: What is Computation?

9 Slide 9 of 56. Lecture A Noam nisan Digital Computation

10 Slide 10 of 56. Lecture A Noam nisan Physical Computation

11 Slide 11 of 56. Lecture A Noam nisan Biological Computation

12 Slide 12 of 56. Lecture A Noam nisan Mathematically defined computation f(x,0) = 1 f(x,y) = g(y,f(x,y-1)) g(z,0) = 0 g(z,w) = h(w,g(z,w-1)) h(r,0) = r h(r,s) = h(r,s-1)+1 public class PrintPrimes { public static void main(String[] args){ for(j = 2; j < 1000; j++) if (isPrime(j)) System.out.println(j); } private static boolean isPrime(int n) { for(int j=2; j < n; j++) if (n%j == 0) return false; return true; }

13 Slide 13 of 56. Lecture A Noam nisan Turing Machines (1936) 0 0 1 1 a a b b z z 0, R, b 1, L, b 0, L, a 1, L, g 0, L, a 1, R, x a a b b z z e e Alan Turing

14 Slide 14 of 56. Lecture A Noam nisan Turing Machine for adding 1 a a b b 0 0 1 1 1, _, b 0, L, a 1, _, b 0, _, b start halt

15 Slide 15 of 56. Lecture A Noam nisan Universal Computers Theoretical version: there exists a single Universal Turing Machine that can simulate all other Turing machines  The input will be a coding of another machine + an input to the other machine Hardware version: stored program computer  von Neumann Architecture (EDIAC 1945) Program + Data

16 Slide 16 of 56. Lecture A Noam nisan The Church-Turing Hypothesis Everything computable is computable by a Turing machine  Physical interpretation  Conceptual interpretation  Definition of Computation  Everything computable is computable by a Java program  All “good enough” computers are equivalent Not everything is computable… How fast can you compute something?  Modern version of CTH – also efficiency is preserved (+/-)

17 Slide 17 of 56. Lecture A Noam nisan CTH, Precision, and Chaos The physical world is analog When we simulate it on a digital device we use a given precision  Input and output are given in finite precision  How many bits of precision do we need?  How much can a small error in the input affect the output?  Normally: a little  Chaotic systems: a lot When we simulate a digital device on an analog device we can encode many bits in one analog signal  Limits to precision of analog systems: atoms, quantum effects  Hard to think of a physical signal of even 64 bits of precision

18 Slide 18 of 56. Lecture A Noam nisan CTH and Quantum Physics Only known challenge to the “efficiency” version of CTH We do not know how to simulate quantum mechanical systems efficiently The quantum “probability amplitudes” are different from normal probabilities Maybe “quantum computers” can efficiently do more than normal randomized computers  Efficient “quantum algorithm” for factoring is known Can quantum computers be built?  Existing physics? New physical laws? Technology? Can quantum computers be simulated efficiently on a randomized Turing machines?

19 Slide 19 of 56. Lecture A Noam nisan CTH and the Brain Is the brain just a computer? Metaphysics: The mind-body problem  Monism: everything is matter -- including humans  Dualism: there is more (“soul”, “mind”, “consciousness” …) Technical differences  Parallel, complicated, analog, …  Still equivalent to a Turing Machine

20 Slide 20 of 56. Lecture A Noam nisan AI שקף מלפני 10 שנים Why can’t we program computers to do what humans easily do?  Recognize faces  Understand human language Processing power? Software?  Scruffy vs. Neat debate

21 Slide 21 of 56. Lecture A Noam nisan The Turing Test

22 Slide 22 of 56. Lecture A Noam nisan And now, back to earth How should we teach introduction to Computer Science? Big ideas, concepts? Theory? Programming!  Understanding by doing  Close gap between theory and practice  But don’t forget the bigger picture

23 Slide 23 of 56. Lecture A Noam nisan Lesson A - Introduction Unit A3 - Introduction to Hardware

24 Slide 24 of 56. Lecture A Noam nisan Our abstraction of a computer Screen Keyboard CPU Java Program Memory Data

25 Slide 25 of 56. Lecture A Noam nisan Computer Organization Overview Keyboard Screen Disk Network Card Bus Operating System Compiler Our Program … Data Software Random Access Memory CPU

26 Slide 26 of 56. Lecture A Noam nisan Binary Representations Digital Computers only deal with 0 and 1 We don’t care (mostly) Anything can be represented by sequences of 0 and 1:  Integers: 13 = “0000 1101”, 14 = “0000 1110” …  Characters: ‘A’ = “0010 0001”, ‘B’ = “0010 0010”... The number of bits determines the number of items that can be represented  2 bits give 4 combinations (00, 01, 10, 11)  8 bits (a byte) give 256 combinations  32 bits (a word) give more than 4,000,000,000 combinations

27 Slide 27 of 56. Lecture A Noam nisan A Sample PC Specification 2001 1.1 GHz Pentium IV Processor 256 MB RAM 20 GB Hard Disk 17” Display 56 KB Modem 2011 3.06 GHz Intel dual core i3 Processor 8GB RAM 1.5TB Hard Disk 21’’ Flat Display 10/100/1000 Mbps Network card

28 Slide 28 of 56. Lecture A Noam nisan More about Hardware Much more to learn Not the topic of this course Other courses deal with computer hardware  Digital Systems course  Computer Architecture course  Digital Communications course  Advanced courses In this course, we stick with our abstraction

29 Slide 29 of 56. Lecture A Noam nisan Lesson A - Introduction Unit A4 – Introduction to Software

30 Slide 30 of 56. Lecture A Noam nisan Problems and Algorithms We need to solve a computational problem  “Simulate an Boeing 767 airplane”  “Convert a weight in pounds to Kg” An algorithm specifies how to solve it, e.g.: 1. Read weight-in-pounds 2. Calculate weight-in-Kg = weight-in-pounds * 0.455 3. Print weight-in-Kg Computers must be given exact instructions A computer program is a computer-executable description of an algorithm

31 Slide 31 of 56. Lecture A Noam nisan Machine languages Each processor has its own machine language An assembly language is a human-readable form of the machine language load R7, value jgt label3 add R7, bonus 0100 0111 1101 0011... 0101 1011 0110 0111... 0110 0111 1010 1100...

32 Slide 32 of 56. Lecture A Noam nisan Humans prefer programming in a high level language A compiler can translate to machine language A Interpreter can execute high-level code High Level Languages load R7, value jgt label3 add R7, bonus If (value < 0) value = value + bonus value = value + bonus Compilation

33 Slide 33 of 56. Lecture A Noam nisan Operating Systems Provides hardware-dependant services in a hardware- independent way Used by application programs OS services to users  Files  Printing  Communication  Running programs OS services to application programs  All of the above  Memory Management  User Interface  Processes

34 Slide 34 of 56. Lecture A Noam nisan Lesson A - Introduction Unit A5 – First Java Program

35 Slide 35 of 56. Lecture A Noam nisan Intro to CS – which programming language? Does it matter?  No: We are interested in principles, not current technology  Yes: We cannot think without a language Possible abstraction levels for 1 st programming language  Assembler  Basic, Fortran, Pascal, C  Java, C++, C#  Python, Scheme

36 Slide 36 of 56. Lecture A Noam nisan The Java Programming Language Invented 1995 by James Gosling at Sun Microsystems. Based on previous languages: C, C++, Objective-C, … Intended to be a safe programming language for the Internet Common choice for first programming language  Object oriented  Encourages good programming habits  Very popular commercially  Simpler and more elegant than C++, but similar to it  Harder to shoot your own leg

37 Slide 37 of 56. Lecture A Noam nisan Hello World Program // My First Program!! public class HelloWorld { public static void main(String[] args){ System.out.println(“Hello World!”); }

38 Slide 38 of 56. Lecture A Noam nisan Java Program Elements Words  Keywords  Identifiers Constants  Numbers  Strings Symbols  ( ) [ ] { },. ; + - * / Comments

39 Slide 39 of 56. Lecture A Noam nisan Java Elements // My First Program!! public class HelloWorld { public static void main(String[] args){ System.out.println(“Hello World!”); } Comment Identifier Symbols Keywords String Constant

40 Slide 40 of 56. Lecture A Noam nisan Java Program Structure A program is composed of a collection of classes Each class contains a collection of methods Each method is composed of a sequence of instructions (commands, statements)

41 Slide 41 of 56. Lecture A Noam nisan Java Program Structure // My First Program!! public class HelloWorld { public static void main(String[] args){ System.out.println(“Hello World!”); } Class Method Instruction

42 Slide 42 of 56. Lecture A Noam nisan Lesson A - Introduction Unit A6 – Running Your Program

43 Slide 43 of 56. Lecture A Noam nisan Running a Java Program Use an editor to enter (type) the program  Save to a file named HelloWorld.java Use the compiler to translate the program into bytecode  javac HelloWorld.java  This produces a file named HelloWorld.class Run the program using the bytecode Interpreter  java HelloWorld

44 Slide 44 of 56. Lecture A Noam nisan Java Compilation Compiler Xxx.java Xxx.class Interpreter Output

45 Slide 45 of 56. Lecture A Noam nisan Entering a Java Program into an Editor

46 Slide 46 of 56. Lecture A Noam nisan Running a Java Program

47 Slide 47 of 56. Lecture A Noam nisan Integrated Development Environments (IDE) Include a combination of:  Editor  Compiler  Debugger  Project Management Popular IDEs  Eclipse  intelliJ IDEA  Microsoft visual studio  …

48 Slide 48 of 56. Lecture A Noam nisan Forte IDE – Screen Capture

49 Slide 49 of 56. Lecture A Noam nisan Debugging You will make many errors! Most of your time will be spent finding them and correcting them -- debugging. There are several types of errors:  Syntax errors detected at compilation time (or even in the IDE)  Run-time errors the program runs and crashes  Logical errors the program does something other than what you want it to do It does exactly what you told it to do The earlier an error is caught, the easier it is to correct   unit-test each component as you write it

50 Slide 50 of 56. Lecture A Noam nisan Lesson 1 - Introduction Unit A7 – Introduction to Objects

51 Slide 51 of 56. Lecture A Noam nisan Large Programs Commercial software may require millions of lines of code Humans can only handle about 7 things together To construct large programs:  break the program into components  then break each component, etc. When you use a component you only use its abstraction. When you construct a component you forget about the rest of the program.

52 Slide 52 of 56. Lecture A Noam nisan Interfaces The interface of a software component is an exact definition of what it can do It does not address how it does what it does When you use a component you only consider its interface A good component will have a clear, narrow interface

53 Slide 53 of 56. Lecture A Noam nisan Objects Objects are the basic components in Java An object has an interface and an internal state. The interface encapsulates (hides) the internal operation The interface specifies the services the object provides Object A that uses Object B Object B

54 Slide 54 of 56. Lecture A Noam nisan A Turtle Object

55 Slide 55 of 56. Lecture A Noam nisan A Turtle Object A Turtle object represents a turtle that walks on the screen with a pen on its tail Turtle object interface:  moveForward(distance)  moveRight(degrees)  moveLeft(degrees)  tailUp()  tailDown() Turtle object internal state  Location on screen  Direction facing  Tail is up or down

56 Slide 56 of 56. Lecture A Noam nisan Using a Turtle public class TurtleDrawing { public static void main(String[] args){ Turtle leonardo = new Turtle(); leonardo.tailDown(); leonardo.moveForward(100); leonardo.turnRight(60); leonardo.moveForward(100); }


Download ppt "Slide 1 of 56. Lecture A Noam nisan מבוא למדעי המחשב פרופ' נעם ניסן."

Similar presentations


Ads by Google