0% found this document useful (0 votes)
50 views

Chapter - 1 Introduction To Computer Science

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views

Chapter - 1 Introduction To Computer Science

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 69

Introduction to Computer

Science
By
G. Lavanya
Objectives
• Essence of computer problem solving.
• What is a computer algorithm?
• Fundamental components of digital hardware
• Role of binary representation in digital computing
• What is an operating system?
• Fundamental concepts of computer software
• Fundamental features of IDLE in python
• Modify and execute a simple python program
1.1What is a Computer Science
• Motivation
• Computing technology has changed, and is continuing to change the world.
• Every aspect of life has been impacted by computing.
• There are fundamental principles of computation to be learned that will never change.
• In addition to these principles , of course, there is always changing technology.
• That is what makes the field of computer science so exciting.
• There is constant change and advancement, but also a foundation of principles to draw
from.
Computing Related Specialized Fields
What is Computer Science?
Computer Science
• Fundamentally about the computational problem solving
• Computational problem –solving problems by the use of computation
• What is computation?
• Computation- type of arithmetic or non-arithmetic calculation that is
well defined.
• Examples: Mathematical equations
Computer algorithms
• Mechanical or electronic devices that perform computation are
known as computers.
1.1.1The Essence of computational problem
solving
• To solve a problem computationally, two things are needed
1. Representation-captures all the relevant aspects of the problem
2. Algorithm-solves the problem by the use of representation

• Let’s consider a problem known as the Man, Cabbage, Goat, Wolf


problem
• There is a simple algorithmic approach for solving this problem by
simple trying all possible combinations of items that may be rowed
back and forth across the river.
• Trying all possible solutions to a given problem is known as brute
force approach.
• What would be an appropriate representation for this problem?
• Relevant aspects of the problem need to be represented.
• All the irrelevant details can be omitted.
• A representation that leaves out details of what is being represented
is a form of abstraction.
• In this case unrelevant data are width of the river, name of the man.
• Relevant information is where each item is at each step.
• Collective location of each item → refers to state of the problem.
Start state of the problem can be represented as follows

In which all objects are on the west side of the river


• https://commons.wikimedia.org/wiki/File:Animasi_untuk_musang,_a
ngsa_dan_kekacang_teka_teki.png#/media/File:Animasi_untuk_musa
ng,_angsa_dan_kekacang_teka_teki.png
Sequence of steps to solve the problem
1.1.2 Limitations of Computational Problem
Solving

Example:

For problems such as Traveling Salesman problem in which a


brute-force approach is impractical to use, more efficient
problem-solving methods must be discovered that find either
an exact or an approximate solution to the problem.

Travelling Salesman Problem


1.2 Computer Algorithms
• Algorithm
Finite number of clearly described, unambiguous “doable” steps that
can be systematically followed to produce a desired result for given
input in a finite amount of time( that is eventually terminates).
• Algorithm solve general problems(determining whether any given
number is a prime number).
• Not specific ones(determining whether 30753 is a prime number).
• Therefore, Algorithms are general computational methods used for
solving particular problem instances.
• Algorithm is derived from the ninth –century
Arab mathematician, Al-Khwarizmi, who worked
on “written processes to achieve some goal”.
• Computer algorithms are central to computer
science.
• They provide step-by-step methods of
computation that a machine can carry out.
• The computation that a given computer performs
is only as good as the underlying algorithm used.
1.2.2 Algorithms and Computers: A perfect
Match
• Algorithms and computation→1930s to 1940s(Beginnings of modern
computing)→ studied centuries ago.
• Study of Algorithms does not depend on the existence of computers.
• Most algorithms are not as simple or practical to apply manually.
• Mostly we are using the computers either because they would
require too much for a person to apply, or involve so much detail as to
make a human error likely.
• Because computers can execute instructions very quickly and reliable
without error, algorithms and computers are a perfect match.
• Example algorithm for determining the day of the week for any date
between January 1, 1800 and December 31, 2099.
1.3 Computer Hardware
• Physical part of a computer system.
• Important components- Central Processing unit (CPU) and main
memory.
• Peripheral components- keyboard, monitor, mouse and printer.
1.3.1 Digital Computing
• Essential → computer hardware → reliable and error free.
• Hardware gives incorrect → program→ unreliable
• Rare occurrence of hardware error was discovered in 1994.(Widely
used intel processor shows incorrect results when certain numbers
were divided.)
• The key to developing reliable systems is to keep the design as simple
as possible.
Decimal Digitalization
• In digital computing, all information represented as a series of digits.
• To represent numbers using Base-10
• Digits 0-9
• Consider if information were represented
within a computer system this way
• Each digit is represented by a different
voltage level.
• The more voltage levels → more complex
the hardware design becomes.
• Results in greater chance of hardware design
errors
Binary Digitilization
• Information represented →two digits(0 and 1)
• Similar to switch (ON/OFF)
• Computer hardware is based on the use of simple
electronic on/off switches called transistors(Switch
at very high speed)
• Integrated circuits(Chips)→ building blocks of computer hardware→
Comprised of millions or even billions of transistors.
• Bit→ Binary digit
• Byte→ Group of bits operated on as a single unit → Eight bits
1.3.2 The Binary Number System
Fundamental Hardware Components
• CPU-is the brain of a computer system, containing digital logic circuitry able
to interpret and execute instructions.
• Main Memory- where currently executing programs reside, which the CPU
can directly and very quickly access. Main memory is volatile; that is, the
contents are lost when the power is turned off.
• Secondary Memory- non volatile → provides long term shortage of
programs and data.→ Examples : Magnetic (Hard drive), optical ( CD or
DVD) or non volatile flash memory ( such as in a USB drive)
• Input/Output devices- that allows for input( Mouse and Key board)
Output( Such as monitor or printer)
• Buses- transfer data between components within a computer system such
as between the CPU and main memory.
1.3.4 Operating systems- Bridging
Software and Hardware
• OS is software that has the job of managing and interacting with the
hardware resources of a computer.
• System Software
• Middle man between the hardware and executing application
programs
• Provide a particular user interface.
• Thus, it is the operating system installed on a given computer that
determines the “look and feel” of the user interface and how the user
interacts with the system, and not the particular model computer.
1.3.5 Limits of Integrated Circuits
Technology: Moore’s Law
• In 1965, Gordon E. Moore , one of the pioneers in the development of integrated circuits and
cofounder of Intel Corporation, predicted that as a result of continuing engineering developments,
the number of transistors that would be put on a silicon chip would roughly every two years,
allowing the complexity and therefore the capabilities of Integrated circuit to grow exponentially.

• This prediction became known as Moore’s Law.

• Amazingly, to this day that prediction has held true.


1.4 Computer Software
• First Computer Programmer → Ada Lovelace
• Computer Software: is a set of program instructions,
including related data and documentation, that can
be executed by computer.
• Two types: System Software, Application Software.
• System Software: intrinsic to a computer system
• Application Software : fulfill’s user’s needs.
1.4.1 Types of
Software
Relation between System and
Application software
1.4.2 Syntax, Semantics and Program
Translation

• Syntax defines what is grammatically valid in a programming


language
➢Set of grammatical rules.
➢E.g., In English, a sentence cannot begin with a period.
➢Must be formal or exact or there will be a ambiguity in a
programming language.
• Semantics→ Meaning of the program units
-- expressions ,statements, declarations
• Every language has its own syntax and semantics
• A program that is syntactically correct is not necessarily
logically(Semantically) correct.
• A program will always do what we tell it to do, not what we meant to
tell it to do.
Program Translation
• A CPU is designed to interpret and execute a specific set of
instructions represented in binary form(i.e., 1s and 0s) called
machine code.
• Only programs in machine code can be executed by a CPU.
Types of programming languages
• Writing programs at low level is tedious and error prone.
• So, most programs are written in a high-level programming language
such as Python.
• The instructions of high level language programs are not in machine
code that a CPU can execute. So, we need a translator program to
convert a high-level language to machine language.
• For that we have two types of translators→ Compiler, Interpreter.
Compiler
• Translates programs directly into machine code to be executed by the
CPU.
Interpreter
• Immediately execute instructions as they are entered.
• INTERACTIVE MODE
• Very useful feature for program development.
• Python→ Interpreter.
Program Debugging : Syntax Errors
Vs Semantic Errors
• Program debugging is the process of finding and correcting
errors(“bugs”).
• Two type of errors: Syntax Errors, Semantic Errors
• Syntax Errors: Caused by invalid syntax(entering prnt instead of print)
Translator cannot understand instructions containing
syntax errors.
• Semantic Errors: errors in program logic.
cannot be automatically detected.
Translators cannot understand our intention.
• Average of three numbers:

• Computers do not understand what a program is meant to do, it only


follows the instructions given.
1.4.3 Procedural Vs. Object- Oriented
Programming
• Two types
1. Procedural(Imperative) Programming
2. Object-oriented Programming
• Each provides different way of thinking about computation.
• While most programming languages only support one paradigm,
Python supports both.
1.5 The process of Computational
Problem Solving
• Computational problem solving does not simply involve the act of
computer programming.
1.5.1 Problem Analysis
• Understanding a problem- knowing what constitutes a solution
• Program Design- Describing the data needed
-Describing the needed algorithms
• Program Implementation
• Program Testing
The Python Programming Language
• Creator of Python programming language→ Guido van
Rossum→ in the early 1990s.
• Simple Syntax
• Programs are clear and easy to read.
• Provides powerful programming features and is widely
used.
• Companies and organizations that use Python include
You Tube, Google, Yahoo and NASA.
• Well supported
• Freely available at www.python.org
Guido van Rossum
1.6.2 The IDLE Python Development
Environment
• IDLE –Integrated Development Environment(IDE)
Bundled set of software tools for program development.
• This includes editor, translator and program debugger.
• Editor- for creating and modifying programs
• Translator- for executing programs
• Program debugger-provides a means of taking control of the
execution of a program to aid in finding program errors.
• Most commonly translated by the use of an interpreter.
Contd..

• Provides very useful ability to execute in interactive mode.


• The window that provides interaction is referred to as the Python
Shell.
Here, the
entered
expression is
1+2,ath the shell
prompt(>>>), idle
responds
immediately with
the result 3.

Python Shell
1.6.3 The Python Standard Library
• Is a collection of built –in-modules, each providing specific
functionality.
• Math module provides additional mathematical functions.
• Random module provides the ability to generate random numbers.
• In order to utilize the capabilities of a given module in a specific
program, an import statement is used.
1.6.4 A Bit of Python
• Begin writing some simple programs.
• All computer programs → input data, process the data and output
results.
• How to use variables, perform some simple arithmetic calculations,
how to do simple input and output.
Variables
• In detail we can discuss later.
• Brief
• A simple description of a variable is a name that is assigned to a value”
• Example n=5 (variable n is assigned the value 5)
• Whenever variable n appears in calculation, current value of n is assigned.
• n+10→5+10→15
• If we changed n to 10→n=10
• n+20→10+20→30
Some Basic Arithmetic Operators
• Addition(+)
• Subtraction(-)
• Multiplication(*)
• Division(/)
• Exponentiation(**)
• Truncated Division(//)
• Multiplication is never denoted by the use of parenthesis. Parenthesis
may be used to denote subexpressions.
Basic Input and Output
• Print:
➢Used to display information on the screen
• Input:
• Used to request and get
information
Yo u
a n k
T h

You might also like