Download as pdf or txt
Download as pdf or txt
You are on page 1of 34

INTRO TO

ALGORITHMS
AND
PROGRAMMING
TODAY'S AGENDA
DEFINITION OF ALGORITHM
PROPERTIES OF ALGORITHM
DEVELOPING AN ALGORITHM
CATEGORIES OF OPERATIONS USED TO CONSTRUCT
ALGORITHM
WHAT ARE VARIABLES?
- VARIABLES AND DATA TYPES
- NAMING OF VARIABLES
FLOWCHARTS
PSEUDOCODES
WHAT IS AN
ALGORITHM?
The word Algorithm means “a process or set of rules to be followed in
calculations or other problem-solving operations”. Therefore Algorithm
refers to a set of rules/instructions that step-by-step define how a
work is to be executed upon in order to get the expected results.

INPUT A SET OF
INSTRUCTIONS OUTPUT
EXAMPLE:
Problem Task: Prepare tea

Algorithm to complete the task:


•Fill water in kettle
•Boil the water.
•Put teabag, milk, and sugar in a cup.
•Pour hot water into the cup.
•Mix the contents of the cup.
PROPERTIES OF
ALGORITHM

DEFINITENESS FINITENESS

INPUT ALGORITHM OUTPUT

EFFECTIVENESS
INPUT An Algorithm should have some inputs.

At least one output should be returned by the algorithm after the completion
OUTPUT of the specific task based on the given inputs.

DEFINITENESS Every statement of the algorithm should be unambigous.


FINITENESS No infinite loop should be allowed in an algorithm.

Writing an algorithm is a prior process of actual implementation of the


algorithm. So, a person should analyze the algorithm in a finite amount of
EFFECTIVENESS time with a pen and paper to judge the performance for giving the final
version of the algorithm.
CHARACTERISTICS
OF ALGORITHM
1. IT IS A STEP BY STEP PROCEDURE FOR
SOLVING ANY PROBLEM SAYS AN
ALGORITHM.

2. AN ALGORITHM IS A FINITE SET OF


INSTRUCTIONS, IF FOLLOWED AND
ACCOMPLISHES A PARTICULAR TASK.

3. IT IS A SEQUENCE OF COMPUTATIONAL
STEPS THAT TRANSFORM THE INPUT INTO
A VALUABLE OR REQUIRED OUTPUT.
ALGORITHM
DEVELOPMENT
IS THE ACT OF DESIGNING THE STEPS
THAT SOLVE A PARTICULAR PROBLEM FOR
A COMPUTER OR ANY OTHER DEVICE TO
FOLLOW NOT EXCLUDING HUMAN BEING,
BUT IN THIS CASE COMPUTERS ONLY AND
COMPUTER LIKE DEVICES.
STEPS IN DEVELOPMENT OF
ALGORITHMS
1. PROBLEM DEFINITION
2. DEVELOPMENT OF A MODEL
3. SPECIFICATION OF ALGORITHM
4. DESIGNING AN ALGORITHM
5. CHECKING THE CORRECTNESS OF
ALGORITHM
6. ANALYSIS OF ALGORITHM
7. IMPLEMENTATION OF ALGORITHM
8. PROGRAM TESTING
9. DOCUMENTATION PREPARATION
ALGORITHM
REPRESENTATION
An Algorithm can be expressed, developed, written, or
represented in one of the following languages or forms:

1. Narrative
2. Flowchart
3. Pseudocode
CATEGORIES OF OPERATIONS
USED TO CONSTRUCT
ALGORITHM
a.Sequential operations: A single well defined task (or
instruction)

b.Conditional operations: The “question-asking” operations


whereas the next operation is based on the answer to the
question.

c.Iterative operations: The looping operations of the


algorithm. Doing the same thing over and over with maybe
minor changes or no changes. Only an update condition so
that we can stop at some point in time.
WHAT ARE VARIABLE?
Variables are the names you give to computer memory
locations which are used to store values in a computer
program.
BASIC VARIABLE TYPE
A VARIABLE IS NOTHING BUT A NAME GIVEN TO A STORAGE AREA THAT OUR PROGRAMS CAN MANIPULATE.
EACH VARIABLE IN C HAS A SPECIFIC TYPE, WHICH DETERMINES THE SIZE AND LAYOUT OF THE
VARIABLE'S MEMORY; THE RANGE OF VALUES THAT CAN BE STORED WITHIN THAT MEMORY; AND THE SET OF
OPERATIONS THAT CAN BE APPLIED TO THE VARIABLE.

CHAR INT
Typically a single octet(one byte). It is an The most natural size of integer for the
integer type. machine.

FLOAT DOUBLE
A single-precision floating point A double-precision floating point value.
value.

VOID
Represents the absence of type
VARIABLE DEFINITION IN C
A VARIABLE DEFINITION TELLS THE COMPILER WHERE AND
HOW MUCH STORAGE TO CREATE FOR THE VARIABLE. A
VARIABLE DEFINITION SPECIFIES A DATA TYPE AND
CONTAINS A LIST OF ONE OR MORE VARIABLES OF THAT
TYPE AS FOLLOWS −
REHTEGOT
EZYLANA DNA
SSUCSID S'TEL
CREATING VARIABLES
Creating variables is also called declaring variables in C
programming. Different programming languages have different
ways of creating variables inside a program

FOR EXAMPLE, C PROGRAMMING HAS THE FOLLOWING SIMPLE


WAY OF CREATING VARIABLES -
REHTEGOT
EZYLANA DNA
SSUCSID S'TEL
SIMILARLY, WE CAN CREATE VARIABLES TO STORE LONG, FLOAT,
CHAR OR ANY OTHER DATA TYPE. FOR EXAMPLE -

STORE VALUES IN VARIABLES


REHTEGOT
EZYLANA DNA
SSUCSID S'TEL
ACCESS STORED VALUES IN VARIABLES

WHEN THE ABOVE PROGRAM IS EXECUTED, IT PRODUCES THE


FOLLOWING RESULT
REHTEGOT
EZYLANA DNA
SSUCSID S'TEL
ACCESS STORED VALUES IN VARIABLES

WHEN THE ABOVE PROGRAM IS EXECUTED, IT PRODUCES THE


FOLLOWING RESULT
DATA TYPES
Data types in c refer to an extensive system used for
declaring variables or functions of different types. The type
of a variable determines how much space it occupies in
storage and how the bit pattern stored is interpreted.
THE DATA TYPES IN C CAN BE
CLASSIFIED AS FOLLOWS -
BASIC TYPES ENUMERATED
TYPES
They are arithmetic types and are further
classified into: (a) integer types and (b) They are again arithmetic types and they are used to
floating-point types. define variables that can only assign certain discrete
integer values throughout the program.

THE TYPE VOID DERIVED TYPES


The type specifier void indicates that no They include (a) Pointer types, (b) Array types, (c)
value is available. Structure types, (d) Union types and (e) Function types.
DATA TYPES IN C
PROGRAMMING LANGUAGE

WHAT IS A FLOWCHART?
A FLOWCHART IS A PICTURE OF THE SEPARATE STEPS
OF A PROCESS IN SEQUENTIAL ORDER. IT IS A
GENERIC TOOL THAT CAN BE ADAPTED FOR A WIDE
VARIETY OF PURPOSES, AND CAN BE USED TO
DESCRIBE VARIOUS PROCESSES, SUCH AS A
MANUFACTURING PROCESS, AN ADMINISTRATIVE OR
SERVICE PROCESS, OR A PROJECT PLAN.

ALSO CALLED: PROCESS FLOWCHART, PROCESS FLOW


DIAGRAM

ELEMENTS THAT MAY BE INCLUDED IN A FLOWCHART


ARE A SEQUENCE OF ACTIONS, MATERIALS OR
SERVICES ENTERING OR LEAVING THE PROCESS
(INPUTS AND OUTPUTS), DECISIONS THAT MUST BE
MADE, PEOPLE WHO BECOME INVOLVED, TIME
INVOLVED AT EACH STEP, AND/OR PROCESS
MEASUREMENTS.
REHTEGOT
EZYLANA DNA
SSUCSID S'TEL
FLOWCHART SYMBOLS
REHTEGOT
EZYLANA DNA
SSUCSID S'TEL
GUIDELINES FOR
DEVELOPING
FLOWCHARTS
These are some points to keep in mind while developing a
flowchart −
Flowchart can have only one start and one stop symbol
On-page connectors are referenced using numbers
Off-page connectors are referenced using alphabets
General flow of processes is top to bottom or left to right
Arrows should not cross each other
REHTEGOT
EZYLANA DNA
SSUCSID S'TEL
EXAMPLE FLOWCHARTS
Here is the flowchart for going to the market to purchase a pen.
REHTEGOT
EZYLANA DNA
SSUCSID S'TEL
EXAMPLE FLOWCHARTS
Here is a flowchart to calculate the average of two numbers.
REHTEGOT
EZYLANA DNA
SSUCSID S'TEL
EXAMPLE FLOWCHARTS
WHAT IS
PSEUDOCODES?
PSEUDOCODE IS AN INFORMAL WAY OF
PROGRAMMING DESCRIPTION THAT DOES NOT
REQUIRE ANY STRICT PROGRAMMING LANGUAGE
SYNTAX OR UNDERLYING TECHNOLOGY
CONSIDERATIONS. IT IS USED FOR CREATING AN
OUTLINE OR A ROUGH DRAFT OF A PROGRAM.
PSEUDOCODE SUMMARIZES A PROGRAM’S FLOW, BUT
EXCLUDES UNDERLYING DETAILS. SYSTEM DESIGNERS
WRITE PSEUDOCODE TO ENSURE THAT PROGRAMMERS
UNDERSTAND A SOFTWARE PROJECT'S REQUIREMENTS
AND ALIGN CODE ACCORDINGLY.
REHTEGOT
EZYLANA DNA
SSUCSID S'TEL
THE MAIN CONSTRUCTS OF
PSEUDOCODE
The core of pseudocode is the ability to represent 6 programming
constructs (always written in uppercase): SEQUENCE, CASE,
WHILE, REPEAT-UNTIL, FOR, and IF-THEN-ELSE. These constructs
— also called keywords —are used to describe the control flow of
the algorithm.

1. SEQUENCE represents linear tasks sequentially performed one


after the other.
2. WHILE a loop with a condition at its beginning.
3. REPEAT-UNTIL a loop with a condition at the bottom.
4. FOR another way of looping.
5. IF-THEN-ELSE a conditional statement changing the flow of
the algorithm.
6. CASE the generalization form of IF-THEN-ELSE.
REHTEGOT
EZYLANA DNA
SSUCSID S'TEL
THE MAIN CONSTRUCTS OF
PSEUDOCODE
REHTEGOT
EZYLANA DNA
SSUCSID S'TEL
RULES OF WRITING
PSEUDOCODE
Here are some simple rules that help make pseudocode more
universally understood.
1. Always capitalize the initial word (often one of the main 6
constructs).
2. Have only one statement per line.
3. Indent to show hierarchy, improve readability, and show
nested constructs.
4. Always end multiline sections using any of the END keywords
(ENDIF, ENDWHILE, etc.).
5. Keep your statements programming language independent.
6. Use the naming domain of the problem, not that of the
implementation. E.g., “Append the last name to the first name”
instead of “name = first+ last.”
7. Keep it simple, concise, and readable.
REHTEGOT
EZYLANA DNA
SSUCSID S'TEL
EXAMPLE PSEUDOCODE

You might also like