This document provides an introduction to problem solving techniques and programming languages. It discusses algorithms, flowcharts, pseudocode, and program control structures. It then covers the four generations of programming languages:
1) First generation languages used machine code and assembly languages.
2) Second generation languages included compiled languages like FORTRAN and COBOL.
3) Third generation languages improved on previous generations with features like data abstraction and modular programming.
4) Fourth generation and beyond focused on visual and non-procedural languages.
2. INTRODUCTION
I. Introduction: Fundamentals of digital computers.
II. Problem Solving Techniques: Algorithm, Flow
Chart, Pseudo code, Program Control Structures,
Programming Paradigms.
III. Programming languages: Generations of
Programming Languages, Language Translators,
and Features of a Good Programming Languages.
2
3. II.Problem Solving Techniques
ALGORITHM
Definition
• Algorithm is defined as a step by step procedure
for solving any problem.
• It is also a precise rule (or set of rules) specifying
how to solve a problem.
• An algorithm is a sequence of finite instructions,
often used for calculation and data processing.
3
4. • After the preparation of a suitable plan
for developing the program by its logic.
• i.e., the correct sequence and procedure
of instructions required to carryout the
task, the algorithms is often used to refer
the logic of a program.
4
5. Representation of Algorithm
• Algorithm has a starting point and a final point. Between these two points
are the instructions that solve the problem.
• Algorithms often have steps that repeat or require decisions (such as logic
or comparison).
• Algorithms can be expressed in any language from natural languages (like
English, French, etc.) to programming languages (like Basic, Fortran,
python, etc..)
• Algorithm is the basis for most of the programs. Each rule in an algorithm
is written in a programming language. All these rules are collectively called
a Program.
5
6. Algorithm (Find the Area)
1. Start
2. Read the value of radius r
3. Calculate - Area=3.14*r*r
4. Print the Area of the circle
5. Stop
Now test the algorithm with sample data
Consider the value of radius r=5
Area=3.14*5*5 =78.5
6
7. Characteristic Of Algorithm
• Algorithm has a finite number of inputs.
• Every instruction should be precise and unambiguous.
• Ensure that the algorithm has proper termination.
• Effectiveness of each step is very important.
• The desired output must be obtained only after the
algorithm
• The algorithm should be written in sequence.
7
8. Qualities of an Algorithm
• Accuracy : Algorithm should provide accurate
result than others.
• Memory : It should require minimum
computer memory.
• Time : The time taken to execute any program
is considered as a main quality. Lesser the
time taken better the quality.
• Sequence : The procedure of an algorithm
must be in a sequential form.
8
9. BUILDING BLOCKS OF ALGORITHM
• Statements
1. Simple Statement
2. Compound Statement
• State
• Control flow
• Functions
9
10. Instruction/Statements
• In computer programming, a statement is the
smallest standalone element that expresses some
action to be carried out.
• It is an instruction written in a high-level language
that commands the computer to perform a specified
action.
• A statement may have internal components (e.g.,
expressions).
10
12. Compound statements
• block: begin ------- end
• do-loop: do -------- while (i < 10);
• for-loop: for (…)
• if-statement: if ----
• else----
• switch-statement: switch (c) { case ‘a’: alert(); break;
case ‘q’: quit(); break; }
• while-loop: while (…) DO -----
12
13. State
• An algorithm is deterministic automation for
accomplishing a goal which, given an initial
state, will terminate in a defined end-state.
• Data is read from an input source or device,
written to an output sink or device, and/or
stored for further processing.
13
14. Control flow
• The order function calls, instructions, and
statements are executed or evaluated when a
program is running.
1. Sequence Control Structure
2. Selection Control Structures
14
15. Sequence Control Structure
• The sequential control structure is used to
perform the actions one after another.
• It performs process A and then performs process
B and so on.
• This structure is represented by writing one
process after another.
• The logic flow is top to bottom approach.
15
16. Selection Control Structures
• Selection control structures (or) Decision
structures allows the program to make a choice
between two alternate paths whether it is true or
false.
• IF...THEN or IF..THEN..ELSE or a case structures are
the selection structures.
• This logic is used for making decisions.
16
17. Functions
• Functions are “self contained” modules of code that
accomplish a specific task.
• Functions usually “take in” data, process it, and “return” a
result.
• Once a function is written, it can be used over and over and
over again.
• Functions can be “called” from the inside of other functions.
17
18. Contin..
• When a function is “called” the program “leaves” the current section of
code and begins to execute the first line inside the function.
Thus the function “flow of control” is:
• The program comes to a line of code containing a “function call”.
• The program enters the function (starts at the first line in the function
code).
• All instructions inside of the function are executed from top to bottom.
• The program leaves the function and goes back to where it started from.
• Any data computed and RETURNED by the function is used in place of the
function in the original line of code.
18
19. Functions contain:
• Name - describes the purpose of the function. such as “compute
Average”, or just “average”.
• Inputs - called parameters (Formal/Actual parameters). Describe
what data is necessary for the function to work and gives each
piece of data a Symbolic Name for use in the function.
• Calculation - varies for each function
• Output - Usually one (but sometimes zero or sometimes many)
values that are calculated inside the function and “returned” via the
output variables.
19
22. • Pseudocode is a kind of structure english for
designing algorithm.
• Pseudocodes came from two words. Pseudo and
code pseudo means imitation and code refer to
instructions, written in a programming language.
• Pseudocode cannot be compiled nor executed, and
there are no real formatting or syntax rules
• The benefit of pseudo code is that it enables the
programmer to concentrate on the algorithms
without worrying about all the syntactic details of a
particular programming language.
23
23. Guidelines for Writing Pseudocode
• Write only one Statement per Line
• Capitalize initial keyword :
Few keywords we use:-
READ,WRITE,IF, ELSE, ENDIF, WHILE,
ENDWHILE, REPEAT, UNTIL
• Indent to show hierarchy :
Indentation is a process of showing
the boundaries of the structure.
24
24. Pseudocode is made up of the following logic
structure ,
• Sequential logic
• Selection logic
• Iteration logic
25
26. Sequence Logic :
• It is used to perform instructions in a sequence,that is one after another
• Thus,for sequence logic ,pseudocode instructions are written in an order
in which they are to be performed.
• The logic flow of pseudocode is from top to bottom.
Eg:1
A pseudocode to add two numbers and display the results:
READ num1, num2
result = num1 + num2
WRITE result.
Sequence logic
27
27. Selection Logic
• It is used for making decisions and for
selecting the proper path out of two or
more alternative paths in program logic.
• It is also known as decision logic.
• Selection logic is depicted as either an
IF..THEN or an IF…THEN..ELSE Structure.
28
28. Eg.: Pseudocode greatest of two numbers
START
READ a and b
IF a>b THEN
PRINT “A is big”
ELSE
PRINT “B is big”
ENDIF
STOP
29
29. Repetition Logic
• It is used to produce loops when one or more
instructions may be executed several times
depending on some conditions .
• It uses structures called DO_WHILE,FOR and
REPEAT__UNTIL
30
30. Pseudocode to print first 10 natural numbers
START
INITIALIZE a = 0
WHILE a<10
PRINT a
a=a+1
ENDWHILE
STOP
31
31. Guess its Type!!!
Swapping using temporary variables.
READ the value of a, b
Interchange the values using a variable t
t = a
a = b
b = t
WRITE the swapped value of a, b
Stop
32
32. FLOWCHART
• A flow chart is a diagrammatic
representation, that illustrates the sequence
of operations to be performed to arrive at the
solution.
• Each step in the process is represented by a
different symbol and contains a short
description of the process step.
• The flow chart symbols are linked together
with arrows showing the flow direction of the
process.
33
36. Advantages of Flowcharts
• Communication
• Effective analysis
• Proper documentation
• Efficient Coding
• Proper Testing & Debugging
• Efficient Program Maintenance
37
37. Flowchart and Pseudocode is made up of the
following logic structure
• Sequential logic
• Selection logic
• Iteration logic
38
38. Sequence Logic
• In a computer program or an algorithm,
sequence involves simple steps which are to
be executed one after the other.
• The steps are executed in the same order in
which they are written.
39
40. Selection Logic
• Selection is used in a computer program or
algorithm to determine which particular
step or set of steps is to be executed. This is
also referred to as a ‘decision’.
• A selection statement can be used to
choose a specific path dependent on a
condition.
41
42. Repetition Logic
• Repetition allows for a portion of an algorithm or
computer program to be executed any number of
times dependent on some condition being met.
• An occurrence of repetition is usually known as a
loop.
• The termination condition can be checked or
tested at the beginning or end of the loop, and is
known as a pre-test or post-test, respectively.
43
50. Programming Paradigm
• A programming paradigm is a fundamental style of
computer programming, serving as a way of building the
structure and elements of computer programs.
• Comparing with a software development methodology,
it is a style of solving specific software engineering
problems.
51
51. History
• Different approaches to programming have developed
over time.
• The concept of a "programming paradigm" as such
dates at least to 1978.
• The lowest-level programming paradigms are machine
code.
• In the 1960s, assembly languages were developed
followed by development of procedural languages.
52
52. Why study so many
programming languages ?
• To Improve our ability to Develop Effective algorithms.
• To improve Use of Existing Programming Languages.
• To allow a better choice of Programming Language.
• To make it Easier to design a new language.
53
54. 1. Procedural Programming
• Often thought as a synonym for imperative programming.
• Specifying the steps the program must take to reach the
desired state.
• Based upon the concept of the procedure call.
• Procedures, also known as routines, subroutines, methods,
or functions that contain a series of computational steps to
be carried out.
55
55. Contin.,
• The syntax of such languages generally has the form
statement 1;
statement 2;
--------------
statement n;
56
56. Contin.,
• The ability to re-use the same code at different
places in the program without copying it.
• The ability to be strongly modular or structured.
• Example of procedural programming are C,
Pascal, Basic, FORTRAN etc.
57
57. 2. Functional Programming
• Functional programming is a programming
paradigm that treats computation as the
evaluation of mathematical functions and avoids
state changes and mutable data.
• Programs written using the functional
programming paradigm are much more easily
representable using mathematical concepts.
58
58. Contin.,
• The syntax of such languages is :
functionn { …function2 { function1 (data)} …}
• LISP was the first operational functional programming language.
• The Haskell programming language was released in the late 1980s
in an attempt to gather together many ideas in functional
programming research
59
59. Contin.,
• Not been very popular except for a restricted number of
application areas, such as artificial intelligence.
• Examples of Functional Programming are C, LISP, ML .
60
60. 3.Logical Programming
• Also known as Rule based programming and
Declarative programming.
• Rule based programming checks for presence for a
certain condition and when present execute an
appropriate action
61
61. Contin.,
• The syntax of such Languages generally is similar to the
following.
enabling condition1→action1
enabling condition2→action2
..........................
enabling conditionn→actionn
62
62. 4.Object Oriented Programming
• Object-oriented programming (OOP) is a
programming paradigm that uses "objects" – data
structures encapsulating data fields and procedures
together with their interactions – to design
applications and computer programs
• Programming techniques may include features such
as data abstraction, encapsulation, modularity,
polymorphism, and inheritance.
63
63. Contin.,
• Though it was invented with the creation of the Simula
language in 1965, and further developed in Smalltalk in the
1970s, it was not commonly used in mainstream software
application development until the early 1990s.
• Many modern programming languages now support OOP.
• Examples of Object oriented Programming are C++, java,
Smalltalk, simula etc.
64
65. A programming language is a set of rules that provides
a way of telling a computer what operations to
perform.
A programming language is a set of rules for
communicating an algorithm
It provides a linguistic framework for
describing computations
66
66. A programming language is a notational system for
describing computation in a machine-readable and
human-readable form.
A programming language is a notational system for
describing computation in a machine-readable and
human-readable form.
67
A programming language is a tool for developing
executable models for a class of problem domains.
A programming language is a tool for developing
executable models for a class of problem domains.
67. • English is a natural language.
• It has words, symbols and grammatical rules.
• A programming language also has words,
symbols and rules of grammar.
• The grammatical rules are called syntax.
• Each programming language has a different set of
syntax rules.
68
68. Why does some people speak French?
Programming languages have evolved over time as
better ways have been developed to design them.
69
◦ First programming languages were developed in the
1950s
◦ Since then thousands of languages have been developed
Different programming languages are designed for
different types of programs.
69. High-level program
70
class Triangle {
...
float surface()
return b*h/2;
}
Low-level program LOAD r1,b
LOAD r2,h
MUL r1,r2
DIV r1,#2
RET
Executable Machine code 0001001001000101
0010010011101100
10101101001...
71. • First Generation Languages
•Second Generation Languages
•Third Generation Languages
•Fourth Generation Languages
•Fifth Generation Languages
72
72. Machine language
73
◦ Operation code – such as addition or subtraction.
◦ Operands – that identify the data to be processed.
◦ Machine language is machine dependent as it is the
only language the computer can understand.
◦ Very efficient code but very difficult to write.
73. Assembly languages
74
◦ Symbolic operation codes replaced binary operation
codes.
◦ Assembly language programs needed to be “assembled” for
execution by the computer.
◦ Each assembly language instruction is translated into one
machine language instruction.
◦ Very efficient code and easier to write.
74. Closer to English but included simple mathematical
notation.
75
◦ Programs written in source code which must be translated
into machine language programs called object code.
◦ The translation of source code to object code is
accomplished by a machine language system program
called a compiler.
75. Alternative to compilation is interpretation which is
accomplished by a system program called an
interpreter.
Common third generation languages
76
◦ FORTRAN
◦ COBOL
◦ C and C++
◦ Visual Basic
76. A high level language (4GL) that requires fewer
instructions to accomplish a task than a third
generation language.
Used with databases
77
◦ Query languages
◦ Report generators
◦ Forms designers
◦ Application generators
77. Declarative languages
78
Functional(?): Lisp, Scheme, SML
◦ Also called applicative
◦ Everything is a function
Logic: Prolog
◦ Based on mathematical logic
◦ Rule- or Constraint-based
79. Two broad groups
80
◦ Traditional programming languages
Sequences of instructions
First, second and some third generation languages
◦ Object-oriented languages
Objects are created rather than sequences of instructions
Some third generation, and fourth and fifth generation
languages
80. FORTRAN
81
◦ FORmula TRANslation.
◦ Developed at IBM in the mid-1950s.
◦ Designed for scientific and mathematical applications by
scientists and engineers.
81. COBOL
82
◦ COmmon Business Oriented Language.
◦ Developed in 1959.
◦ Designed to be common to many different computers.
◦ Typically used for business applications.
82. BASIC
83
◦ Beginner’s All-purpose Symbolic Instruction Code.
◦ Developed at Dartmouth College in mid 1960s.
◦ Developed as a simple language for students to write
programs with which they could interact through
terminals.
83. C
◦ Developed by Bell Laboratories in the early 1970s.
◦ Provides control and efficiency of assembly language
while having third generation language features.
◦ Often used for system programs.
◦ UNIX is written in C.
84
84. Simula
85
◦ First object-oriented language
◦ Developed by Ole Johan Dahl in the 1960s.
Smalltalk
◦ First purely object-oriented language.
◦ Developed by Xerox in mid-1970s.
◦ Still in use on some computers.
85. C++
86
◦ It is C language with additional features.
◦ Widely used for developing system and application
software.
◦ Graphical user interfaces can be developed easily with
visual programming tools.
86. JAVA
87
◦ An object-oriented language similar to C++ that
eliminates lots of C++’s problematic features
◦ Allows a web page developer to create programs for
applications, called applets that can be used through a
browser.
◦ Objective of JAVA developers is that it be machine,
platform and operating system independent.
87. Scripting Languages
88
◦ JavaScript and VBScript
◦ Php and ASP
◦ Perl and Python
Command Languages
◦ sh, csh, bash
Text processing Languages
◦ LaTex, PostScript
88. HTML
89
◦ HyperText Markup Language.
◦ Used on the Internet and the World Wide Web (WWW).
◦ Web page developer puts brief codes called tags in the
page to indicate how the page should be formatted.
102. Formerly: Run Time Performance
(Computers were more expensive than programmers)
Now: Life cycle (human) cost is more important
Ease of designing,coding
Debugging
Maintenance
Reusability
103
103. Writability: The quality of a language that enables a
programmer to use it to express a computation clearly,
correctly, concisely, and quickly.
Readability: The quality of a language that enables a programmer
to understand and comprehend the nature of a computation
easily and accurately.
Orthogonality: The quality of a language that features
provided have as few restrictions as possible and be
combinable in any meaningful way.
Reliability: The quality of a language that assures a program will not
behave in unexpected or disastrous ways during execution.
Maintainability: The quality of a language that eases errors can be
found and corrected and new features added.
104
104. Generality: The quality of a language that avoids
special cases in the availability or use of constructs and
by combining closely related constructs into a single more general
one.
Uniformity: The quality of a language that similar features
should look similar and behave similar.
Extensibility:The quality of a language that provides
some general mechanism for the user to add new
constructs to a language.
Standardability: The quality of a language that allows
programs written to be transported from one computer to another
without significant change in language structure.
Implementability: The quality of a language that
provides a translator or interpreter can be written. This can
address to complexity of the language definition.
105