0% found this document useful (0 votes)
6 views37 pages

001 Set

The document outlines the course 'Introduction to Computer Science' (CS-UH 1001) taught by Alex Delis at NYU-Abu Dhabi, focusing on programming with Python3. It covers fundamental concepts of computer science, including hardware, software, programming languages, and the importance of computational thinking. The course objectives include problem-solving skills, coding proficiency, and understanding the structure of programming languages, alongside academic integrity guidelines and grading criteria.

Uploaded by

gmustafawaqar
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views37 pages

001 Set

The document outlines the course 'Introduction to Computer Science' (CS-UH 1001) taught by Alex Delis at NYU-Abu Dhabi, focusing on programming with Python3. It covers fundamental concepts of computer science, including hardware, software, programming languages, and the importance of computational thinking. The course objectives include problem-solving skills, coding proficiency, and understanding the structure of programming languages, alongside academic integrity guidelines and grading criteria.

Uploaded by

gmustafawaqar
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Introduction to Computer Science

CS-UH 1001, Fall 2022

Alex Delis
NYU-Abu Dhabi
September 2022
Instructors

 Alex Delis, Professor,


URL: [Link],
email: [Link]@[Link]

 Dena Ahmed, Teaching Fellow,


URL: [Link]/en/academics/divisions/science/instructors/
[Link],
email: daa4@[Link]

ª Slides are based on material/notes kindly made available by Thomas Pötsch, Yasir Zaki
and Jerome White.
1
Computing Machinery: Hardware, Software and Networks

 Computers are collections of electronics that can run instructions often writen by
people (a.k.a. code) and communicate with each other through networks.

– These codes or programs help automate computational tasks and make life easier for
people.
– The electorics make up what is known as hardware while the programs are the
software.
– Software is what drives computing machinery.
– Today, nearly all pieces of technology are empowered by computers.
– Clearly knowing how to create programs is immensly useful if one wants to work
and/or contribute to our digital age.

2
The Many Areas and Aspects of Computer Science
Transporation
Biology Pharma Products

Algorithms
 Computer Science is the Medicine Graphics
Statistics
study, design, realization Programming languages Operating Systems

and evaluation of: Engineering


(all disciplines) Databases & Dig Libraries
Software Engineering
Design
– computing machines, Information Retrieval Computer Architecture

– interaction of the Computer and Embedded Systems


Parallel Systems

machines’ internal Physics


Artificial Intelligence VR Numerical Computations Mathematics

components, and Distributed Systems Data Networks GIS

Human Computer Interaction AVs/UAVs


– collective-work of
Comp. Linguistics
networks of such Web-Computing Robotics
Games
Architecture NLP
computing elements. Bid Data

Supercomputing
Logistics

Operations Research
Chemistry

3
Computers (& Computer Science) are all around us!

 Computers are not smart and they need humans to “guide” them through software.

 Programming a computer is not only a challenging task but also it is in practice, an


enormous responsibility for the program designer/developer.

 Systems and Applications include:


– Databases and archives of the human activity.
– Smart phones and contemporary data-network-based communications.
– Applications for the management of the moving (and still) images.
– Authoring suites and program development environments (IDEs).
– Automotive computer systems for (autonomous) movement.
– Geographic and navigational applications.
– Airplane, vehicle, ship and their traffic control systems
– Satellite and space application systems.
– Medical scanning and operating equipment.
4 – etc. etc. etc.
Computer Science: an Exact Science
Mathematics Engineering
Design
Representation Assembly
Notation
Testing &
Logic Evaluation

Computer
Science

Observation
Hypothesis
Modeling
Synthesis
Science

 A key skill for a computer scientist is problem solving using algorithms & structures of
data.
 Programming is the key tool to realize automated solutions to computational problems.

5
Computer Science

 Formalize the Human Thinking

 Computational Thinking

– Solve problems through abstraction and a divide & conquer approach.

– Design recipes for solutions (a.k.a. implementations).

– Use computers to have these solutions run automatically.

 The above is all we routinely do in the many facets of our lives!

6
CS-UH1001: Course Objectives

 Provide an Introduction to CS and Programming with Python3.

 Learn how to approach and tackle CS problems:


– Develop the ability to translate problems to coded solutions/recipes.

 Get familiar with fundamental concepts of programming and develop skills to “read”
through existing code.

 Learn how to write new programs:


– Accumulate sufficient amount of knowledge to write code.

– Develop computational solutions to problems and build arcade-type games (Pacman,


Tetris, Mario&Friends, etc.)

7
Course Material

 All material used ultimately will be placed at [Link]

– Syllabus, Announements, Slides, Homework Assignments, Programming Projects, etc.

 Textbooks for the class are:


1. Tony Gaddis, Starting out with Python, Pearson; 4th edition, ISBN: 97892225852,
available from Bookstore.

2. Peter Wentworth, Jeffrey Elkner, Allen B. Downey and Chris Meyers, How to Think
Like a Computer Scientist: Learning with Python 3, freely available on the Web.

8
Course: Presence - Grading

 Presence in class: a healthy University habbit.


 Grading:
Type Description Percentage
Class Participation Interaction, exercises, etc. 3%
Quizzes Based on all previous material 6%
3 Individual Progr. Assignments Apprx. for 10 days each 27%
1 Group Progr. Assignment Apprx. for 2-3 weeks 14%
Mid-term exam Written Examination 20%
Final exam Written Examination 30%

9
Academic Integrity

 The work you present must be exclusively your own!

 Cheating and plagiarism are serious academic offences.

– Any such suspected plagiarism incident will warrant zero for the assignment to all
parties involved—no question asked.

– Incidents will be reported to the University for disciplinary action.

– Discussion of potential solutions to a problem with colleugues is not an issue at all!

– Sharing of code and presenting code written by others as your own is not permitted
under any circumstances and certainly is a major offence.

10
Examples of Plagiarism

 Copying from Internet or other people is an offence.


– Changing names of variables and manipulating code written by others is not allowed.

– Code extracted from repositories (such as GitHub) cannot be presented as your own
even if you provide a citation for it!

– Code offered by more senior colleuges and presented as your own is an offence.

– Asking/paying others to write code for your is a major offence.

 Education requires both honesty and integrity.

 This course could be a very rewarding class, if you try.

11
A Computer System
> _
tty

 Computer consists of:


– Input/Output (I/O)
Devices,
Operating System
– CPU (Central
Processing Unit) Central
Magnetic
Processing Memory
Monitor tty Solid State Disk(s)
Unit (CPU) (Banks)
– Main-Memory and Disk

Disks > _

(Magnetic/SSDs)
– Interfaces & NICs
Data and
 Operating System: offers Control Bus

all services USB Stick


Memory
CD/DVD Printer NIC Wi-Fi Card

12
CPUs Execute Instructions

 With the help of the OS, the CPU executes sequences of instructions to accomplish
computational tasks.

– These sequences of instructions are called programs.

– A sequence of instructions has to reach the CPU so that the computer carries out its
intended actions (or computation).

– Programs are written in Programming Languages (low- and high-level).

– A language is a basic tool for users to interact with computers.

13
Programming Languages

 All Programming Language offer:

– Instructions expressing specific actions using keywords.

– A set of man-provided symbols along with keywords collectively helps express the
intension of the programmer.

– Instructions that have to do with Input and Output.

– Instructions can be meshed together following the specific Syntax of the language.

14
Types of Programming Languages

 There are 2 types: Low- and High-level Programming Languages.

 Low-level: Assembly and Machine Languages


– Use of mnemonics that are architecture–dependent.
– For every assembly instruction there is an equivalent binary-represention at Machine
Language.
– Such programs are not portable; a piece of code is portable when is not tightly
coupled to a specific hardware platform (i.e., CPU they run on).

 High-level: Python3, C, C++, Java, Go, Rust.


– Use English-like commands and along with Syntax rules and keywords offer the
building blocks for creating programs.
– Specific machine architecture independent.
– Portability is feasible through re-compilation (when different machines are used).
15
Going from a High to Low Level Language

 A sample program in C - easily understood by people:


#include <stdio.h> 1
2
void main(){ 3
printf("Hola Amigos!\n"); 4
} 5

The 1st program in C++ that generates a string


– String is a sequence of characters (or words/lexemes).

16
Going from a High to Low Level Language
 The program gets transformed to x86 Assembly: sequence of instructions (excerpt).
.file "main.c" 1
.text 2
.section .rodata.str1.1,"aMS",@progbits,1 3
.LC0: 4
.string "Hola Amigos!" 5
.text 6
.globl main 7
.type main, @function 8
main: 9
.LFB23: 10
.cfi_startproc 11
endbr64 12
subq $8, %rsp 13
.cfi_def_cfa_offset 16 14
leaq .LC0(%rip), %rdi 15
call puts@PLT 16
addq $8, %rsp 17
.cfi_def_cfa_offset 8 18
ret 19
.cfi_endproc 20
.LFE23: 21
.size main, .-main 22
.ident "GCC: (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0" 23
.section .[Link]-stack,"",@progbits 24
.section .[Link],"a" 25
.align 8 26
.long 1f - 0f 27
.long 4f - 1f 28
.long 5 29
30
.... 31
17
From Assembly to Machine Instructions..

 Ultimately, the Assembly code is interpreted to Machine Level hexadecimal type of


instructions “understood” by the CPU:
– Portion of the code pertinent to the main functionality of the program gets transformed (by
the compiler) to:

.... 1
0000000000001149 <main>: 2
1149: f3 0f 1e fa endbr64 3
114d: 48 83 ec 08 sub $0x8,%rsp 4
1151: 48 8d 3d ac 0e 00 00 lea 0xeac(%rip),%rdi 5
1158: e8 f3 fe ff ff callq 1050 <puts@plt> 6
115d: 48 83 c4 08 add $0x8,%rsp 7
1161: c3 retq 8
1162: 66 2e 0f 1f 84 00 00 nopw %cs:0x0(%rax,%rax,1) 9
1169: 00 00 00 10
116c: 0f 1f 40 00 nopl 0x0(%rax) 11
.... 12

– The second column above is essentially the code that gets to be executed by the core
18 so that the user sees the outcome of her program.
High-Level Programming Languages

 Using Enlgish-like keywords such as for, while, return, print, read, if,
then, else, etc. and variable/structures laid out in set of distinct statements, a
program designates a piece of computation.

– Every statement (often a line of text) corresponds to a number of assembly


instructions and machine language commands (one-to-many).

– It is much easier to write a high-level source code for a program than its respective
set of assembly isntructions.

– Data is referenced using descriptive names called variables.

– Operations can be described using familiar symbols (such as math symbols) in


addition to user-define operations or functions.

19
Syntax in Programming Languages (PLs)

 Syntax is the structure of a program as well as the rules behind the structure:
– The syntax designates the set(s) of legal expressions in that language

 In English, sentences often follows the syntax rule: noun + verb + noun
– John plays chess → legitimate
– John chess plays → non-correct syntax

 PLs do have syntax rules:


– SumOfGrades / NumberOfCourse → often legitimate
– SumOfGrades NumberOfCourse /
→ this is not allowed in the majority of High-Level PLs!

20
Frequent Types of Errors in Programming

 Syntax Errors happen when authoring rules for the PL get violated:
– When illegal/not-permissible expressions are used; for example:
– AlexFindGPA(SumOfGrades,NumberOfCourse)
when AlexFindGPA as an entity (i.e., function) that has not been defined yet!

 Runtime errors occur when program runs but it cannot successfully complete:
– Division by zero
– Invalid input data

 Logical or Semantic Errors:


– Although a program completes execution, it delivers incorrect results.

21
High- vs. Low-Level PLs

 Streams of PL instructions have to be executed by the CPU.

High Level Assembly Machine


Instr. Stream Instr. Seq. Instructions
... ...
movl $46, %edx
.... 8b 55 f4
leaq .LC0(%rip), %rsi
c = a +b ; 8b 45 f8
movl $1, %edi
... 01 d0
movl $0, %eax
... 89 45 fc
...

– High-level source code has to be transformed to Assembly and ultimately to Machine


Code to be “understood” by the CPU.

22
High-Level Source Code Programs Handling

 Compilation vs. Interpretation

Programmer Programmer

Compiler Interpreter

program is dealt with in


a line-by-line fashion
as a whole

Processor
program is

Processor
dealt with

– Compiler: transforms the entire source code program into an executable!


• This executable has to be loaded in Main-Memory to be executed.

– Interpreter: executes a program in a line-by-line fashion.

23
Python3: Our Main Tool for Programming in CSUH1001

 High-level & interpreted language:


– Designed for rapid prototyping and easily maintainable code.
– It can also be compiled.

 Popular and simple(r) to learn.

 Promotes clear and readable syntax.


– Has good documentation [Link]

– Comes into 2 “flavors”: Python2 and Python3!

– Python3 is the version that will be using.

24
Installing Python3

 [Link]
 [Link]

 The terminal or tty interface to running programs (similar for WinsXX and MacOS):

25
Running the 1st Program
 Write a program that displays the string “Hola Amigos” in your terminal.

• Just write the


statement (or
function)
print() on
the tty and
see the result.
• This is the
interactive
way of
authoring and
running a
program.

26
Running a Program using the Command Line (or Inline)

 Edit the program in a text file name [Link] whose content is:
# This is my first attempt 1
2
print("Hola Amigos\n") 3
print("Myname is Alex\n") 4
5
print(450/12) 6

 The out-
come is:

27
Basic Representation of Characters/Numbers into Bytes

 A computer’s memory is divided into small storage locations known as Bytes.

 Each Byte can store a letter of the alphabet or a small int number.

 A Byte consists of 8 Bits:

– Each Bit can have value 1 or 0


– These 2 Bit (Binary) Values are also known as on and off.
– The Bit along with its 2 values create the base upon which the binary system is
founded.

28
Basic Representation of Characters/Numbers into Bytes

• By setting bits to have different values, we can represent 28 distinct values ranging
from 0..255 (in decimal equivalent).

• These different numbers can be stored in Registers, Main Memory, Disk and other
magnetic and SSD-type devices.

• The Byte below has (decimal) value: 77 – how does this come about?

0 1 0 0 1 1 0 1

29
Understanding How the Binary Numbers Work

 Every decimal number can be represented as a binary number and vice versa.
 In a binary number, each bit if set, it “carries” a value along with it.

• The position of each bit has a decimal value assigned to it.


• This assignment goes along the following map:
Byte
Bits[0/1]

20 1
21 2
22 4
23 8
24 16
25 32
26 64
27 128

30
Converting Binary to Decimal Numbers

 For the following 2 binaries, what is the equivalent decimal representation (easily
understood by humans)?

0 0 1 0 1 1 0 1 Bits 1 0 0 0 1 1 0 1 Bits

20 1 20 1
21 2 21 2
22 4 22 4
23 8 (b) 23 8
(a)
24 16 24 16
25 32 25 32
26 64 26 64
27 128 27 128

The Decimal Number is 45 The Decimal Number is 141

• Case (a): 1 ∗ 25 + 1 ∗ 23 + 1 ∗ 22 + 1 ∗ 20 = 45
• Case (b): 1 ∗ 27 + 1 ∗ 23 + 1 ∗ 22 + 1 ∗ 20 = 141

31
Representation of Long(er) Numbers

 How to represent integers larger than 255??


– Place multiple bytes next to each other to offer a longer range.
– If you put, 2 Bytes the range of integers expresses can go up to 65,535.
2 Bytes

1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
15 14 ..... 11 10 9 8 7 .... 3 2 1 0 #of Bit

Most Significant Bit Least Significant Bit

• Value of the above represenation is:


1 ∗ 20 + 1 ∗ 21 + 1 ∗ 22 + 1 ∗ 23 + ... + 1 ∗ 214 + 1 ∗ 215 = 65535

32
Representing Characters

 Characters, symbols and punctuation signs have to represented somehow in computing


devices.

– When such a character is stored in a computer’s memory it is initially converted to a


specific numeric code.

– These codes are known as ASCII codes ⇒ [Link]

– These ASCII codes (or charcaters) are stored as Bytes (with specific value) in memory.
– For example, the code for “a” is 97 and for “W” is 87.
– The respective Binary representations for “a” and “W” are: 01100001 and 01010111.

33
Going from character =⇒ Byte representation
ASCII (dec)
letter 'b' 0 1 1 0 0 0 1 0
Number: 98
Binary Repr. for 'b'
• Remember: reading a Byte can be reading a character or a (portion of) number.
• Python3 can be used to find out the ASCII value of characters.

34
Mini-Tasks

 Install Python3.
1. Print on your screen (i.e., tty) your full name.
2. If you run the Marathon in 2H and 45M, what would be your expected 1-Mile time?
– The Marathon is 42.195Km.
– 1 Mile is 1, 609 Meters.

3. Etisalat uses an Internet unidirectional down-link of 10 Gbps (or GigaBits per


Second). How much data in terms of Megabytes can this link “download” in 1H?

4. Can you run the above 2 programs from the command line?

35
Alex Delis, [Link] -AT+ [Link]
NYU Abu Dhabi

You might also like