0% found this document useful (0 votes)
92 views15 pages

Lecture Note: Week 1

The document discusses algorithms and flowcharts for designing computer-based solutions. It defines an algorithm as a well-organized approach to solving complex problems and describes the key properties of algorithms. The document also explains different algorithm design methods like stepping, looping, and choosing. Additionally, it describes guidelines for drawing flowcharts, common flowchart symbols, and basic flowchart structures for sequences, selections, and repetitions. Flowcharts provide benefits like effective communication and analysis but can become complex and costly for large programs.

Uploaded by

Devesh Gupta
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
92 views15 pages

Lecture Note: Week 1

The document discusses algorithms and flowcharts for designing computer-based solutions. It defines an algorithm as a well-organized approach to solving complex problems and describes the key properties of algorithms. The document also explains different algorithm design methods like stepping, looping, and choosing. Additionally, it describes guidelines for drawing flowcharts, common flowchart symbols, and basic flowchart structures for sequences, selections, and repetitions. Flowcharts provide benefits like effective communication and analysis but can become complex and costly for large programs.

Uploaded by

Devesh Gupta
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 15

Lecture Note

WEEK 1

Designing Solution to Computer Based


Problem

School of Computer Science & IT, DAVV Indore


Algorithm
“An algorithm is a well-developed, organized approach to solving a
complex problem.”

Developing an Algorithm

1.Identify the Inputs


2.Identify the Processes
3.Identify the Outputs

1.2 An algorithm must have following properties

 There must be no ambiguity in any instruction.


 There should not be any doubt about which instruction is to be executed next.
 The description of the algorithm must be finite.
 The execution of the algorithm should conclude after a finite number of steps.
 After performing the instruction that is after the algorithm terminates the desired
result.

1.3 Three methods used for creating an algorithm


• Steeping
• Looping
• Choosing

Steeping
This is where all the instructions needed to solve our problem are set out one after to
another. Here is an example

Example: Write an Algorithm of Addition of two numbers


STEP 1: START
STEP 2:READ VALUE OF FIRST NUMBER AND SECOND NUMBER
STEP3: CALCULATE ADDITION OF FIRST NUMBER AND SECOND
NUMBER:
SUM=FIRST NUMBER+SECOND NUMBER
STEP 4:DISPLAY SUM
STEP 5: STOP

Example: Write an Algorithm of simple interest (SI=P*R*T/100)

STEP 1: START

School of Computer Science & IT, DAVV Indore


STEP 2:READ VALUE OF P, R AND T
STEP3: CALCULATE SIMPLE INTREST BY USING FORMULA:
SI=P*R*T/100
STEP 4:DISPLAY SIMPLE INTREST
STEP 5: STOP

Looping
Repeat an instruction or a set of instructions a number of times. In this case use loops

 The Repeat until loop


 The While loop
 The For loop

 The Repeat until loop

This type of loop keeps carrying out a command a command UNTIL a given
condition is satisfied. The condition is given with the UNTIL command. Here is an
example

Example: Write an Algorithm to print five times “Hello”.

STEP 1: START
STEP 2: INITILIZE NUM TO 1
STEP3: REPEAT
STEP 4: PRINT HELLO
STEP 5: UNTIL THE NUM IS NOT FIVE
STEP 6: STOP

 The While loop

In this type of loop the condition is given along with the WHILE command and end
with END WHILE command. Here is an example

Example: Write an Algorithm to print table of 2.


STEP 1: START
STEP 2: INITILIZE NUM TO 1
STEP 3: WHILE NUM IS LESS THAN 10
STEP 4: MULTIPLAY THE NUM BY 2
STEP 5: DISPLAY TABLE HAS 2
STEP 6: END WHILE
STEP 6: STOP

 The For loop

School of Computer Science & IT, DAVV Indore


The For loop number of times it is repeated .the command to be repeated between
FOR and END FOR. Here is an example

Example: Write an Algorithm to print number from 10 to 20.

STEP 1: START
STEP 2: FOR NUMBER=10 TO 20
STEP 3: PRINT NUMBER
STEP 4: END FOR
STEP 5: STOP

Choosing
This method is used to take decision. This technique is called choosing, and uses
the commands IF, THEN and ELSE.
This type of command a condition is given in the IF command followed by an action to
be taken. If the condition if satisfied follow it by THEN command. Here is an example

Example: Write an Algorithm to decide weather or not go to school

STEP 1: START
STEP 2: IF IT IS WEEKDAY AND IT IS NOT A HOLYDAY
STEP 3: THEN GO TO SCHOOL
STEP 4: ELSE STAY AT HOME
STEP 5: STOP

School of Computer Science & IT, DAVV Indore


Lecture Note
WEEK 2

School of Computer Science & IT, DAVV Indore


1. Flowchart
Flowchart is a pictorial representation of an algorithm in which the steps are drawn in the
form of different shapes of boxes and the logical flow is indicated by interconnecting
arrow.
The boxes represent operations and the arrows represent the sequence in which the
operations are implemented .
The main purpose of the flowchart is to help to understanding the logic of the program.

2.1 Guidelines for Drawing a Flowchart

The following are some guidelines in flowcharting:

a. In drawing a proper flowchart, all necessary requirements should be listed out in


logical order.
b. The flowchart should be clear, neat and easy to follow. There should not be any
room for ambiguity in understanding the flowchart.
c. The usual direction of the flow of a procedure or system is from left to right or
top to bottom.
d. Only one flow line should come out from a process symbol.
e. Only one flow line should enter a decision symbol, but two or three flow lines,
one for each possible answer, should leave the decision symbol.
f. Only one flow line is used in conjunction with terminal symbol
g. If the flowchart becomes complex, it is better to use connector symbols to reduce
the number of flow lines. Avoid the intersection of flow lines if you want to make
it more effective and better way of communication.
h. Ensure that the flowchart has a logical start and finish.
i. It is useful to test the validity of the flowchart by passing through it with a simple
test data.

2.2 Importance of Flowchart

A flowchart helps to clarify how things are currently working and how they could be
improved.

1. Communication: Flowcharts are better way of communicating the logic of a


system to all concerned.
2. Effective analysis: With the help of flowchart, problem can be analyzed in more
effective way.
3. Proper documentation: Program flowcharts serve as a good program
documentation, which is needed for various purposes.
4. Efficient Coding: The flowcharts act as a guide or blueprint during the systems
analysis and program development phase.

School of Computer Science & IT, DAVV Indore


5. Proper Debugging: The flowchart helps in debugging process.
6. Efficient Program Maintenance: The maintenance of operating program becomes
easy with the help of flowchart. It helps the programmer to put efforts more
efficiently on that part

2.3 Symbols used in flowchart

Flowcharts use special symbol shapes to represent different types of actions or steps in
a process. Lines and arrows show the sequence of the steps, and the relationships among
them.

(Flow Line): Flow lines are used to connect symbols. These lines indicate
sequence of steps and the direction of flow.

(Terminal): This symbol is used to represent the beginning (start), the


termination (end) or halt (pause) in the program logic.

(Input/Output): It represents information entering or leaving the system,


such as customer order (Input) and serving (Output)

(Processing): Process symbol is used for representing arithmetic and data


movement instruction.

(Decision): Decision symbol denote a decision to be made .the program


should continue along one of the two routes (IF/ELSE).this symbol has one
entry and two exit paths. The path chosen depends on whether the answer to
a question is ‘yes’ or ‘no’.

(Connector): Connector symbol is used to join different parts of program.

2.4 Flowchart structure

1. Sequence: A sequence process is a series of processes carried out one after


the other. Where information can flow in a straight line.

School of Computer Science & IT, DAVV Indore


Example: Find average of five Example: convert Celsius to
numbers Fahrenheit
Start Start

Read value a,
b,c,d,e Input T (in C)

Avg=(a+b+c+d+e)/5 F=1.8*C+32

Display F
Display Avg

End
End

2. Selection (branches): Where the decisions are made according to some


predefined condition. The If_Else_If processes logically complete the binary
decision block by providing two separate processes. One of the processes will be
carried out in the each path of binary decision.

The flow chart of the if statement:

School of Computer Science & IT, DAVV Indore


The flow chart of the if…else statement:

The flow chart of the switch statement:

School of Computer Science & IT, DAVV Indore


Example: program to find the greatest number of three numbers.

NO

3. Repetition: Where the logic can repeat in a loop, that is, where a sequence of
steps is repeated until the desired output is obtained. The while process allow for
the representation of a conditional loop structure within a program.

Flow chart of the while loop:

Flow chart of the for loop:

School of Computer Science & IT, DAVV Indore


Example: Draw a flowchart to find the sum of first 50 natural numbers

Example: Draw a flowchart to find the sum 20 even numbers natural numbers

School of Computer Science & IT, DAVV Indore


2.5 Limitation of flowchart

• Complex: The major disadvantage in using flowchart is that when a program is


very large, the flowchart may continue foe many pages, marking them hard to
follow. Flowchart tends to get large very quickly and it is difficult to follow the
represented process.

• Costly: Drawing simple flowcharts may be a cost effective process. However, if


the flowchart is to be drawn for a huge program, the time and cost factor of
program development gets out of proportion, making it a costly affair.

• Difficult to modify: Modification to a flowchart usually requires redrawing


the entire logic again, and redrawing a complex flowchart is not a play. It is easy
to draw thousands of flow lines and symbols along with proper spacing,
especially for a large complex program.

School of Computer Science & IT, DAVV Indore


Lecture Note
WEEK 3

Computer Programming Languages

School of Computer Science & IT, DAVV Indore


Types of Computer Programming Language

1. Machine language
2. Assembly language
3. High-level languages

Machine language programs were made up of instructions written in binary


code.
This is the “native” language of the computer.
Each instruction had two parts: Operation code, Operand
• Operation code (Opcode): The command part of a
computer instruction.
• Operand: The address of a specific location in the
computer’s memory.
Hardware dependent: Could be performed by only one type of computer with a
particular CPU

Assembly language programs are made up of instructions written in mnemonics.


• Mnemonics: Uses convenient alphabetic abbreviations to
represent operation codes, and abstract symbols to represent operands.
• Each instruction had two parts: Operation code, Operand
• Hardware dependent.
• Because programs are not written in 1s and 0s, the
computer must first translate the program before it can be executed.

READ num1
READ num2
LOAD num1
ADD num2
STORE sum
PRINT sum
STOP

High-level languages: Use statements that resemble English phrases combined


with mathematical terms needed to express the problem or task being programmed.
– Transportable: NOT-Hardware dependent.
– Because programs are not written in 1s and 0s, the computer must
first translate the program before it can be executed.

School of Computer Science & IT, DAVV Indore


Assembled, Compiled, or Interpreted Languages
All programs must be translated before their instructions can be executed.

Computer languages can be grouped according to which translation process is used to


convert the instructions into binary code:
• Assemblers
• Interpreters
• Compilers

Assembled languages:
• Assembler: a program used to translate Assembly language programs.
• Produces one line of binary code per original program statement.
– The entire program is assembled before the program is sent to the
computer for execution.

Interpreted Languages:
• Interpreter: A program used to translate high-level programs.
• Translates one line of the program into binary code at a time:
– An instruction is fetched from the original source code.
– The Interpreter checks the single instruction for errors. (If an error
is found, translation and execution ceases. Otherwise…)
– The instruction is translated into binary code.
– The binary coded instruction is executed.
– The fetch and execute process repeats for the entire program.

Compiled languages:
• Compiler: a program used to translate high-level programs.
• Translates the entire program into binary code before anything is sent to
the CPU for execution.
– The translation process for a compiled program:
• First, the Compiler checks the entire program for syntax errors in the
original source code.
• Next, it translates all of the instructions into binary code.
» Two versions of the same program exist: the original source code version,
and the binary code version (object code).
• Last, the CPU attempts execution only after the programmer requests that
the program be executed.

School of Computer Science & IT, DAVV Indore

You might also like