COS201 Lecture 1
COS201 Lecture 1
LECTURE 1
INTRODUCTION
What is a Program?
A computer program is a list of instructions that tell a computer what to do. Everything a
computer does is done by a computer program. A computer program is a sequence or set of
instructions in a programming language for a computer to execute. A computer program in its
human-readable form is called source code. A computer program can also be defined as a finite
sequence of instructions that a computer follows to solve a particular problem.
What is Programming?
Computer programming is the process of designing, writing(coding), testing, debugging and
maintaining the source code of computer programs.
Markup Language
Markup languages prepare a structure for the data or prepare the look or design of a page. These
are presentational languages and it doesn’t include any kind of logic or algorithm, for example,
HTML. HTML is not asking any kind of question to the computer or it’s not comparing things
and it’s not asking any logical question. It’s just used to represent a view inside a web browser. It
tells the browser how to structure data for a specific page, layout, headings, title, table and all or
styling a page in a particular way. So basically it involves formatting data or it controls the
presentation of data. Examples of Markup languages are HTML, CSS or XML. These languages
are most widely used to design a website.
Scripting Language
As the name suggest, it’s all about giving the script to perform some certain task. Scripting
languages are basically the subcategory of programming languages which is used to give
guidance to another program or we can say to control another program, so it also involves
instructions. It basically connects one language to one another languages and doesn’t work
standalone. JavaScript, PHP, Perl, Python and VBScript, these all are the examples of scripting
language. Scripting languages need to be interpreted (Scanning the code line by line, not like
compiler in one go) instead of compiled. There is no scope of compiler in scripting languages.
Scripting languages are most widely used to create a website.
Programming Paradigm
A paradigm is the preferred approach to programming that a language supports. A
programming paradigm is a relatively high-level way to conceptualize and structure the
implementation of a computer program. A programming language can be classified as supporting
one or more paradigms.
2. Declarative Programming: Code declares properties of the desired result, but not how to
compute it, describes what computation should perform, without specifying detailed state
changes compared to imperative programming.
(a) Functional: It is paradigm where one applies pure functions in sequence to solve
complex problems. A desired result is declared as the value of a series of function
evaluations. Examples are Haskell, SML, Lisp and Scheme.
(b) Logic: It is a programming, database and knowledge representation paradigm based on
formal logic. A logic program is a set of sentences in logical form, representing
knowledge about some problem domain. Examples include Prolog, Answer Set
Programming (ASP) and Datalog.
Note: Structured programming is a programming paradigm aimed at improving the clarity,
quality, and development time of a computer program by making extensive use of the structured
control flow constructs of selection (if/then/else) and repetition (while and for), block structures,
and subroutines. Examples include ALGOL 58 and ALGOL 60.
Algorithm
Algorithm is a step-by-step procedure, which defines a set of instructions to be executed in a
certain order to get the desired output. Algorithms are generally created independent of
underlying languages, i.e. an algorithm can be implemented in more than one programming
language.
From the data structure point of view, following are some important categories of algorithms −
● Search − Algorithm to search an item in a data structure.
● Sort − Algorithm to sort items in a certain order.
● Insert − Algorithm to insert item in a data structure.
● Update − Algorithm to update an existing item in a data structure.
● Delete − Algorithm to delete an existing item from a data structure.
Characteristics of an Algorithm
Not all procedures can be called an algorithm. An algorithm should have the following
characteristics
● Unambiguous − Algorithm should be clear. Each of its steps (or phases), and their
inputs/outputs should be clear and must lead to only one meaning.
● Input − an algorithm should have 0 or more well-defined inputs.
● Output − an algorithm should have 1 or more well-defined outputs, and should match the
desired output.
● Finiteness − Algorithms must terminate after a finite number of steps.
● Feasibility − should be feasible with the available resources.
● Independent − an algorithm should have step-by-step directions, which should be
independent of any programming code.
Algorithms tell the programmers how to code the program. Alternatively, the algorithm can be
written as −
Step 1 − START ADD
Step 2 − get values of a & b
Step 3 − c ← a + b
Step 4 − display c
Step 5 – STOP
In design and analysis of algorithms, usually the second method is used to describe an algorithm.
It makes it easy for the analyst to analyze the algorithm ignoring all unwanted definitions. He
can observe what operations are being used and how the process is flowing.
Writing step numbers is optional. We design an algorithm to get a solution to a given problem. A
problem can be solved in more than one way.
Hence, many solution algorithms can be derived for a given problem. The next step is to analyze
those proposed solution algorithms and implement the best suitable solution.