CHAPTER
Overview of Algorithm,
Flowcharts and DFD
INSIDE THIS CHAPTER
3.1. Problem 3.5. Data Flow Diagram (DFD)
3.2. Design Flow to Solve a Problem 3.6. Text Editor
3.3. Algorithms 3.7. VI Editor
3.4. Flow Chart
3.
3.11 . PR OBLEM
PROBLEM
IMPORTANT NOTES
32
OVERVIEW OF ALGORITHM, FLOW CHARTS AND DFD 33
In the present context, we are interested in problems & solutions of Mathematical &
Logical categories.
3.2. DESIGN FL
FLOO W TTO
O SOL VE A PR
SOLVE OBLEM
PROBLEM
DO YOU KNO
KNOWW
D E SIG N ID E A This explains that, you should know
what you do. Implementation of a problem
using any programming lan-
guage is just weighted 20%
SP EC IFIC ATIO N What are the things that you require to do
of the complete project & the
the design? remaining 80% weightage
uses the documentation part
A LG ORITH M S
Step-by-step solution of problem in English i.e. Algorithms, Flow-Charts,
Language or in Engish- Program-Style. Data Flow Diagram.
+0)26-4 !
FLOW C H A R T Flow Chart is a modeling tool to describe our algorithm pictorially or graphically,
this is easy to understand
D ATA FLO W
DFD is a modeling tool, which contains some functional/process through which
D IA G RA M data flow from one location to another location
IM P LEM E N TATIO N Whatever you write in algorithm, we have to just design it using any program
U S IN G A N Y
LA N G UA GE language like C, C++, Java, and Dotnet etc.
All the phases mentioned above are very important to understand to implement or
develop software. Now in the next session we are trying to explain all these above Phases,
mainly Algorithms, Flow charts & Data flow Diagram, which are very important part of the
problem designing & analysis.
3.3. AL GORITHMS
ALGORITHMS
A simple way of solving any problem is to make its Algorithm and flowchart.
IMPORTANT NOTES
To assign the values to the variables A & B using an algorithm in English Programming
style just write the following lines:
set A <- {Enter first input} or set A := {Enter first input}
set B <- {Enter second input} or set B := {Enter second input}
3.3.
3.3.11 . Char act
Charact eris
acteris tics of Algorithms
eristics
1. Input : Zero or more values externally supplied to Algorithm.
2. Output : Zero or more values produced by Algorithm.
3. Definiteness : Each instruction must be clear and unambiguous, i.e. having one
and only one meaning.
4. Finiteness : For all cases, algorithm must terminate after finite number of
steps or it should be complete.
5. Effectiveness : Every instruction must be efficient and also feasible as far as
execution is concerned (in terms of space and time).
FORMA
FORMATT OF AL GORITHM
ALGORITHM
Algorithm-name (input, output)
Input: Small description of the input
Output: Small description of the output
1.
2. Algorithm-body which contains finite number of steps and
. every step is properly defined and algorithm should be complete.
.
n.
SAMPLE AL GORITHM
ALGORITHM
Sum (A,B, Out)
A: first input
B: second input
Out: Sum of A + B (output)
1. Get the two inputs from the user
2. Assign the inputs to A & B
3. Set out : = A + B or Set out <- A + B
4. Exit
In the above Sample Algorithm Sum is the name of the algorithm with two inputs namely
A & B and one output out. The above algorithm just gets the two inputs from the user and
assigned the inputs to the two inputs A & B and stores the result in the output out.
3.3.3. An Ex am
Exam ple
ample
Print all the numbers starting from 1 to 10
OVERVIEW OF ALGORITHM, FLOW CHARTS AND DFD 35
+0)26-4 !
3. Print A
4. A ← A + 1
5. Exit
IMPLEMENT
IMPLEMENTAA TION OR C PR OGRAM F
PROGRAM OR THE AB
FOR ABOO VE PR OBLEM
PROBLEM
# include <stdio.h>
main ()
{
int A;
A = 1;
while (A < 11)
{
printf (“%d”,A);
A ++;
}
}
3.3.4. Algorithm Analy sis
Analysis
An algorithm is analyze in terms of their efficiency i.e. how much computer memory
space and execution time an algorithm uses, to store and to execute, in terms of complexity.
IMPORTANT NOTES
Complexity is defined as the total space and time required to store and to
execute an algorithm or problem.
IMPORTANT NOTES
IMPORTANT NOTES
1 . R ecur siv
ecursiv
sivee Algorithm
Recursive technique is used if the problem is solved by calling the same problem multiple
times as shown below :
A (I)
(1) set I = I + 1
(2) if I > 10, exit; Call itself i.e. recursion
(3) else Print “I”;
(4) Go to A (I);
2. Divide and Conq uer
Conquer
Divide and Conquer technique is the most important among all. We have three steps
involved in it viz.
(i) Divide a given problem into the various sub-problems
(ii) Perform the above step recursively until the problem is solved.
(iii) Then combine all the sub-problems at last level of tree to get the result.
3. It er
Iter ativ
erativ
ativee Me thod
Method
Iterative technique is used to solve a problem using expansion i.e. expand the given
Problem until it is not actually solved or we can say if there is any loop in the algorithm
called Iterative algorithm.
OVERVIEW OF ALGORITHM, FLOW CHARTS AND DFD 37
4. Dynamic Pr ogr
Progr amming
ogramming
The Algorithm designed using Dynamic Programming approach uses or remembers older
results and attempt to use these previous results to speed up the process of finding new
results.
5. Gr eedy Algorithms
Greedy
The Algorithm designed using Greedy approach attempts not only to find the solution,
but also to find the optimal solution for any given problem.
6. Br ut
Brut
utee F or
For ce Algorithm
orce
The Brute Force approach starts at some random point and iterates through every
possibility until it finds a solution.
7. Br anch and Bound
Branch
The Algorithm designed using Branch & Bound approach forms a tree like structure of
+0)26-4 !
sub-problems to the primary problem, following each branch of the tree until it is either
solved or lumped in with another branch.
8. Backtracking Algorithm
Backtracking Algorithm test for a solution, if the solution is found the problem given is
solved, if not it recurs again and tests again, continuously until a solution is found.
3.3.6. Some Ex am
Exam ples tto
amples o W rit
Writ
ritee Algorithms
Example 1. Write an algorithm to find whether a ∆ is right angled or not ?
Triangle (A, B, C)
A: first side of the triangle
B: second side of the triangle
C: third side of the triangle
Evenodd (A)
A: A is the number to be checked weather it is even or odd
38 INTRODUCTION TO PROGRAMMING
Smallest (A,B,C)
A: first number
B: second number
C: third number
Swap (A,B)
A: first number
B: second number
1. Set A ← {Enter first number}
2. Set B ← {Enter second number}
3. Set C ← A
6. Set A ← B
7. Set B ← C
8. Exit.
Swap (A,B)
A: first number
B: second number
OVERVIEW OF ALGORITHM, FLOW CHARTS AND DFD 39
IMPORTANT NOTES
+0)26-4 !
which is easy to understand.
3.4.
3.4.11 . Adv ant
Advant ages of Flo
antages Floww Char ts DO YOU KNO
KNOWW
n Being graphical in nature, they are easier to Flow-Char t is used to
understand. generate the sequence or
flow of events in which problem
n It can be reviewed & corrected easily, if found faulty.
is solved and represent the
n They provide effective algorithm documentation. flow of events graphically.
n Promotes understanding of a process.
n Identifies problem areas and opportunities for process improvement.
n Provides a way of training employees.
n Depicts customer-supplier relationships.
3.4.2. Symbols Used in Flo
Floww Char
Chartt
3.4.3. Ex am
Exam ples of Flo
amples Floww Char ts
Example 1. Draw a flow chart to ADD two numbers.
Solution.
STAR T
Input Tw o Numbers
A AND B
C: = A + B
PRINT C
STOP
Fig. 3.1.
Example 2. Draw the flow chart to find whether a ∆ is right angled or not?
Solution. S TA R T
NO
If A = B 2 + C 2
YES
YES
Print "fo rm s a right
angled tria ngle"
If B = A 2 + C 2
NO
YES
If C = A 2 + B 2
NO
STOP
Fig. 3.2.
OVERVIEW OF ALGORITHM, FLOW CHARTS AND DFD 41
Example 3. Draw the flow chart to Find smallest number of 3 numbers.
Solution.
STA R T
IN P U T 3 num be r
a, b, c
If No If
a>b a>c
No
Yes
+0)26-4 !
If Yes print a is sm alle st
b>c
Yes
No
STOP
Fig. 3.3.
Example 4. Draw the flow chart to find average of 3 numbers ?
Solution. STA RT
INP U T a, b, c
AVE R AGE
= (a + b + c)/3
PRIN T AV ERA G E
STOP
Fig. 3.4.
42 INTRODUCTION TO PROGRAMMING
Example 5. STAR T
SU M = 0
N=0
N=N+1
SU M = S U M + N
Is N = 5 0 ?
Yes
PR IN T SUM
EN D
Fig. 3.4.
Example 6. Softw are Development
Start
D esig n
C oding
Testing
Yes
E rrors?
No
No D esig n
E rror?
Yes
End
Fig. 3.5.
Example 7. Sta rt
In put
N
M = 1
F=1
F = F *M
No D oes
M = M +1
M = N?
Yes
O utput
F
F = 1*2*3 ... *N
En d
Fig. 3.6.
OVERVIEW OF ALGORITHM, FLOW CHARTS AND DFD 43
3.5. DA
DATT A FL
FLOO W DIA GRAM (DFD)
DIAGRAM
IMPORTANT NOTES
Synon ym
ymss ffor
Synonym or DFDs DO YOU KNO
KNOWW
1. Bubble Chart Data Flow Diagram is used to
check the flow of data i.e. how
2. Process Model data is stored in database or
3. Bubble Diagram how data is retrieved from the
database or how it is updated.
+0)26-4 !
4. Work Flow Diagram
5. Function Model
It is one of the most commonly used system modeling tool for operational system in
which the functions of the system are of permanent importance & more complex than the
data that system manipulates.
It is first used is software engineering.
3.5.
3.5.11 . S t eps in Dat
Dataa Flo
Floww Analy sis
Analysis
3.5.2. Dat
Dataa Flo
Floww Diagr ams
Diagrams
Data flow diagrams can be used to provide a clear representation of any business
function. The technique starts with an overall picture of the business and continues by
analyzing each of the functional areas of interest. This analysis can be carried out to precisely
the level of detail required. The technique exploits a method called top-down expansion to
conduct the analysis in a targeted way.
Dat
Dataa Flo
Floww Diagr am N
Diagram Noo t ations
There are only five symbols that are used in the drawing of business process diagrams
(data flow diagrams). These are now explained, together with the rules that apply to
them.
44 INTRODUCTION TO PROGRAMMING
2 C ounter
Fig. 3.7.
This diagram represents a banking process, which maintains customer accounts. In this
example, customers can withdraw or deposit cash, request information about their account
or update their account details. The five different symbols used in this example represent
the full set of symbols required to draw any business process diagram.
Ext er
Exter nal Entit y
ernal
An external entity is a source or destination of a data flow which is
outside the area of study. Only those entities which originate or receive C ustom er
data are represented on a business process diagram. The symbol used
is an oval containing a meaningful and unique identifier.
Pr ocess
Process
A process shows a transformation or manipulation of data flows
2
within the system. The symbol used is a rectangular box which contains C ounter
system:
It is represented by an open ended narrow rectangle.
Data stores may be long-term files such as sales ledgers, or may be short-term
accumulations: for example batches of documents that are waiting to be processed. Each
data store should be given a reference followed by an arbitrary number.
OVERVIEW OF ALGORITHM, FLOW CHARTS AND DFD 45
R esour ce Flo
esource Floww
A resource flow shows the flow of any physical material from its source C as h
to its destination. For this reason they are sometimes referred to as
physical flows.
The physical material in question should be given a meaningful name. Resource flows
are usually restricted to early, high-level diagrams and are used when a description of the
physical flow of materials is considered to be important to help the analysis.
Dat
Dataa Flo
Floww Diagr am–R
Diagram–R elationship Grid
am–Relationship
+0)26-4 !
External Entity
Process
Data Store
Fig. 3.8.
There are rules governing various aspects of the diagram components and how they can
relate to one another.
Dat
Dataa Flo
Flowws
For data flows the rules are as follows :
Data flows and resource flows are allowed between external entities and processes.
Data flows are also allowed between different external entities. However, data flows and
resource flows are not allowed between external entities and data stores.
Pr ocesses
Processes
For processes the data flow rules are as follows:
Data flows and resource flows are allowed between processes and external entities
and between processes and data stores. They are also allowed between different
processes. In other words processes can communicate with all other areas of the business
process diagram.
Dat
DataaS
Stt or es
ores
For data stores the data flow rules are as follows:
Data flows and resource flows are allowed between data stores and processes. However,
these flows are not allowed between data stores and external entities or between one data
store and another. In practice this means that data stores cannot initiate a communication
of information, they require a process to do this.
46 INTRODUCTION TO PROGRAMMING
Dat
Dataa Flo
Floww Diagr am – Cont
Diagram Contee xt Dia gr
Diagr am
gram
Return Request
Availability
and Advice
0 Context
Book Details
Book
Supplier Book Library Book Borrow er
O rder
Reservation
Enquiry
Borrow er
Num ber
Fig. 3.9.
The context diagram represents the entire system under investigation. This diagram
should be drawn first, and used to clarify and agree the scope of the investigation.
The components of a context diagram are clearly shown on this screen. The system
under investigation is represented as a single process, connected to external entities by
data flows and resource flows.
The context diagram clearly shows the interfaces between the system under investigation
and the external entities with which it communicates. Therefore, whilst it is often
conceptually trivial, a context diagram serves to focus attention on the system boundary
and can help in clarifying the precise scope of the analysis.
The context diagram shown on this screen represents a book lending library. The library
receives details of books, and orders books from one or more book suppliers.
Books may be reserved and borrowed by members of the public, who are required to
give a borrower number. The library will notify borrowers when a reserved book becomes
available or when a borrowed book becomes overdue.
In addition to supplying books, a book supplier will furnish details of specific books in
response to library enquiries.
Note, that communications involving external entities are only included where they
involve the system process. Whilst a book supplier would communicate with various
agencies, for example, publishers and other suppliers - these data flow are remote from the
system process and so this is not included on the context diagram.
Guidelines tto
o Dr
Draa w Cont
Contee xt Diagr am
Diagram
Firstly, draw and name a single process box that represents the entire system.
Next, identify and add the external entities that communicate directly with the process
box. Do this by considering origin and destination of the resource flows and data flows.
Finally, add the resource flows and data flows to the diagram.
OVERVIEW OF ALGORITHM, FLOW CHARTS AND DFD 47
In drawing the context diagram you should only be concerned with the most important
information flows. These will be concerned with issues such as: how orders are received
and checked, with providing good customer service and with the paying of invoices.
Remember that no business process diagram is the definitive solution - there is no absolute
right or wrong.
Le
Levv el 1 Diagr am
Diagram
D ata Store
Process
External
+0)26-4 !
Entity
D ata Store
Process
External
Process Entity
D ata Store
Fig. 3.10.
The level 1 diagram shows the main functional areas of the system under investigation.
As with the context diagram, any system under investigation should be represented by
only one level 1 diagram.
There is no formula that can be applied in deciding what is, and what is not, a level 1
process. Level 1 processes should describe only the main functional areas of the system,
and you should avoid the temptation of including lower level processes on this diagram. As
a general rule no business process diagram should contain more than 12 process boxes.
The level 1 diagram is surrounded by the outline of a process box that represents the
boundaries of the system. Because the level 1 diagram depicts the whole of the system
under investigation, it can be difficult to know where to start.
Dat
Dataa Flo
Floww Diagr am—T
Diagram—T op-Do
am—Top-Do wn Expansion
op-Down
The section explains the process of top down expansion, or leveling. Furthermore, it
illustrates that whilst there can only be one context and one level 1 diagram for a given
system, these normally give rise to numerous lower level diagrams.
Each process within a given business process diagram may be the subject of further
analysis. This involves identifying the lower level processes that together constitute the
process as it was originally identified. This procedure is known as top-down expansion or
leveling.
As a business process diagram is decomposed, each process box becomes a boundary for
the next, lower level, diagram.
In order to illustrate the process of top-down expansion, consider the three processes
shown within this business process diagram. No detail is shown, only the outline of the
process boxes, which have been identified during the drawing of a level 1 diagram.
48 INTRODUCTION TO PROGRAMMING
Level X
Level X+1
Fig. 3.11.
Any area of a level 1 diagram is likely to require further analysis, as the level 1 diagram
itself only provides a functional overview of the business system.
Therefore, below the level 1 diagram there will be a series of lower level diagrams.
These are referred to as level 2, level 3, etcetera. In practice, level 2 is usually sufficient
and it is unusual to carry out an analysis beyond level 3.
In this example the process numbered 3, at level 1, will be investigated further thereby
giving rise to a level 2 diagram.
In the level 2 diagram four processes of interest have been identified and the numbering
of these processes must reflect the parent process. Therefore the level 2 processes are
numbered 3.1, 3.2, 3.3 and 3.4
Suppose that of these four level 2 processes, one was of sufficient interest and complexity
to justify further analysis. This process, lets say 3.3, could then be further analyzed resulting
in a corresponding level 3 diagram. Once again the numbering of these processes must
reflect the parent process. Therefore these three level 3 processes are numbered 3.3.1, 3.3.2
and 3.3.3.
Dat
Dataa Flo
Floww Diagr am—N
Diagram—N umbering R
am—Numbering ule
Rule
The process boxes on the level 1 diagram should be numbered arbitrarily, so that no
priority is implied. Even where data from one process flows directly into another process,
this does not necessarily mean that the first one has to finish before the second one can
begin.
Therefore the processes on a level 1 diagram could be re-numbered without affecting
the meaning of the diagram. This is true within any business process diagram - as these
diagrams do not imply time, sequence or repetition.
However, as the analysis continues beyond level 1 it is important that a strict numbering
convention is followed. The processes on level 2 diagrams must indicate their parent process
within the level 1 diagram. This convention should continue through level 3 diagrams, and
beyond, should that level of analysis ever be required.
OVERVIEW OF ALGORITHM, FLOW CHARTS AND DFD 49
Process
+0)26-4 !
Process Process Process Process
Fig. 3.12.
The diagram on this screen clearly illustrates how processes on lower level diagrams
identify their ancestral path.
3.5.4. De
Devv eloping a DFD
Top-Do wn Appr
op-Down oach
Approach
1. The system designer makes a context level DFD, which shows the interaction
(data flows) between the system (represented by one process) and the system
environment (represented by terminators).
2. The system is decomposed in lower level DFD (Zero) into a set of processes, data
stores, and the data flows between these processes and data stores.
3. Each process is then decomposed into an even lower level diagram containing its
subprocesses.
4. This approach then continues on the subsequent subprocesses, until a necessary
and sufficient level of detail is reached which is called the primitive process (aka
chewable in one bite).
3.5.5. DFD Le
Levv els
Cont
Contee xt Le
Levv el
This level shows the overall context of the system and its operating environment and
shows the whole system as just one process. It does not usually show data stores, unless
50 INTRODUCTION TO PROGRAMMING
they are owned by external systems, e.g. are accessed by but not maintained by this
system, however, these are often shown as external entities.
Le
Levv el 0
This level shows all processes at the first level of numbering, data stores, external
entities and the data flows between them. The purpose of this level is to show the major
high level processes of the system and their interrelation. A process model will have one,
and only one, level 0 diagram. A level 0 diagram must be balanced with its parent context
level diagram, i.e. there must be the same external entities and the same data flows, these
can be broken down to more detail in the level 0, e.g. the 1enquiry data flow could be spilt
into enquiry request and enquiry results and still be valid.
3.5.6. Ex am
Exam ple of DFD
ample
1 . Aut omat
Automat ed Cour
omated se R
Course egis
Regis tr
egistr ation
tration
EX TERNA L
E N TIT Y A P P L IC AT IO N
1
E N Q U IR Y
CHECK COURSE
AVA IL A B IL IT Y
R E P LY CO UR SE S
A C C E P T/D E C L IN E
E N R O L LM E N T
A P P L IC AT IO N S
E N Q U IR Y R E P LY
C H E C K A P P L IC A N T
Q U A L IFIC AT IO N
Fig. 3.13.
The DFD is based on automatic course registration shown in Fig. 3.13 and it checks
automatically weather the course for which applicant is applied is available, as shown above
as (1), by checking the database where all the records are stored and if it is available then
it again checks weather the applicant fulfill the requirement qualification, as shown above
as (2), and if it fulfills then the application is accepted otherwise rejected.
2. Online Or der Sy
Order Syss t em
The DFD is based on online order system shown in Fig. 3.14 and it processes the customer
order that he had made online, shown as (1) in the above figure. Entry is done in database
D1. It also verify that the payment is approved or not by users credit card or its rejected
OVERVIEW OF ALGORITHM, FLOW CHARTS AND DFD 51
in (2) i.e. cyber check. If the payment is approved then it made an entry in inventory Database
D2 after adding shipping charges and confirms the order & tells the customer the delivery
date of the product with product type & total amount.
O RDER
C U S TO M E R
1 E -C O M M E R C E C U S TO M E R A N D O R D E R IN F O R M AT IO N
PR OCE SS OR DER
AC KNO W LEDG EM ENT
D1 C U S TO M E R
D ATA B A S E
2 CY BER CHECK C R E D IT C A R D N U M B E R
AN D OTHE R AM OUN T
+0)26-4 !
C O N F IR M AT IO N V E R IF Y C R E D IT
A N D D E LIV E RY CARD O R D E R IN FO R M AT IO N
D AT E A P P R O VA L O R
R E JE C TIO N
C R E D IT C A R D
C O M PA N Y
3 S H IP P IN G
S H IP O R D E R
D2 IN V E N TO R Y
Fig. 3.14.
3. Ex am
Exam ple
ample
A p plies to
Stud ent U nive rs ity
Prog re ss R epo rt
A p plica tio n
Ap prova l
D en ial Letter
Ac c eptanc e Le tter
R eg is tra tio n Stud ent
Stud ent D ataba se
Info rm ation
Fig. 3.15.
52 INTRODUCTION TO PROGRAMMING
4. A Le
Levv el Dat
Dataa Flo
Floww Diagr am ffor
Diagram or the Same Sy
Syss t em
1
C u stom er E n qu iry P ro cess
E n qu iry
Item
In fo rm a tion
Item s
2
C u stom er O rd er P ro cess C u stom er
E n qu iry
Inv oice
O rd er D etails
O rd er
D3
Store
Fig. 3.16.
IMPORTANT NOTES
Text editor is a program that enables you to create and edit text files.
There are many different types of editors, but they all fall into two general categories:
1 . Line Edit or
orss
Editor
A primitive form of editor that requires you to specify a specific line of text before you
can make changes to it.
2. Scr een-Orient
Screen-Orient
een-Orienteded Edit or
orss
Editor
It is also called as full-screen editors, these editors enable you to modify any text that
appears on the display screen by moving the cursor to the desired location.
3.6.
3.6.11 . Types of Te xt Edit
Te or
orss
Editor
(1) N o t epad++ (used only in W indo
Windo
indoww s oper ating sy
operating syss t em)
Notepad++ is the text editor which is used in many Windows Operating System and
which is able to provide better features compared to Notepad. It handles most of the advanced
features, like syntax highlighting, code folding, and macros.
Notepad++ is completely free and open source and it is fully customizable.
OVERVIEW OF ALGORITHM, FLOW CHARTS AND DFD 53
The Screen shot of Notepad++ is shown below
+0)26-4 !
Fig. 3.17.
Fig. 3.18.
54 INTRODUCTION TO PROGRAMMING
Fig. 3.19.
(4) Te xtMat
xtMatee (used only in Mac OSX oper ating sy
operating syss t em)
TextMate is a powerful and attractive text editor launched just a few years back and
quickly gained a rapid popularity with its attractive interface, powerful macros, and
downloadable.
The Screen shot of TextMate is shown below :
Fig. 3.20.
OVERVIEW OF ALGORITHM, FLOW CHARTS AND DFD 55
(5) Vim (used in all platf or
platfor ms)
orms)
Vim is very similar to Emacs, earlier version of the Vi text editor. Like Emacs, Vim is
available in several forms. Apart from the original version, there are gVim or gVim Portable
for Windows and MacVim for the Mac.
The Screen shot of Vim is shown below
+0)26-4 !
Fig. 3.21.
Fig. 3.22.
56 INTRODUCTION TO PROGRAMMING
3.7
3.7.. VI EDIT OR
EDITOR
VI is another text editor, which is used to create & edit
text files & Pronounced as Vee eye editor and which is DO YOU KNO
KNOWW
available on all UNIX system. VIM is the earlier version of
The VI editor has the powerful features to aid VI text editor.
programmers.
3.7
3.7.. 1 . Vi Te xt Edit
Te or Oper
Editor ating Modes
Operating
VI text editor is generally operates in either insert mode or command mode.
IMPORTANT NOTES
When the editor is in insert mode then whatever typed becomes the part of
the document and put these typed keystrokes into the current file.
IMPORTANT NOTES
When the editor is in command mode then the keystrokes entered by keyboard
are interpreted as commands that control the edit session.
Typing i while in command mode switches the editor into insert mode.
Typing i again at this point places an i character in the document.
3.7.2. Ho
3.7.2. Howw tto
o S
Stt ar t the VI Te xt Edit
Te or
Editor
The VI editor enables a user to create new files or edit existing files. The command to
start the VI editor is vi, followed by the filename. For example to edit a file called temporary,
you would type vi temporary. You can start VI without a filename, but when you want to
save your work, you will have to tell VI which filename to save it into later.
When you start VI for the first time, you will see a screen filled with tildes (A tilde looks
like this: ~) on the left side of the screen as shown below:
~
~
~
~
~
~
~
~
filename N lines, M characters
Any blank lines beyond the end of the file are shown this way. At the bottom of your
screen, the filename should be shown, if you specified an existing file, and the size of the
file will be shown as well, like this:
“filename” 21 lines, 385 characters
OVERVIEW OF ALGORITHM, FLOW CHARTS AND DFD 57
If the file you specified does not exist, then it will tell you that it is a new file, like this:
“newfile” [New file]
If you started VI without a filename, the bottom line of the screen will just be blank.
3.7.3. Ho
3.7.3. Howw tto
o Exit fr om VI T
from e xt Edit
Te or
Editor
Now that you know how to get into VI, now this session tells you how to exit from the Vi
text editor. The VI editor has two modes and in order to get out of VI, you have to be in
command mode.
Hit the key labeled Escape or Esc to get into command mode. If you were already
in the command mode when you again hit Escape key, dont worry, it might beep, but
you will still be in the command mode.
3.7.4. Te xt Buf f er
3.7.4. erss used in VI Te xt Edit
Te or
Editor
The VI editor has 36 buffers for storing pieces of text, out of which one buffer is a
+0)26-4 !
general purpose buffer. Any time a block of text is deleted from the file, it gets placed into
the general purpose buffer. The block of text is also stored in another buffer other than
general purpose buffer as well, if it is specified by user. The buffer is specified using the
command. For example, the command: mdd uses the buffer m, and the last two
characters stand for delete current line.
3.7.5. Some Sim
3.7.5. ple VI T
Simple e xt Edit
Te or Commands
Editor
Following are some simple set of commands used in VI Text editor.
Command Description
:w filename Writes (saves) the current document. If the optional filename is provided, the
text is saved in the specified file.
:q Quits the editor without saving the current file.
:vi filename Loads the specified file into the editor.
:n Loads the next file into the editor. Useful when vi was invoked from the command
line with multiple file names.
:r filename Reads (inserts) the content of the specified file into the current document.
:wq Quits the editor and save the current file.
:a enter insert mode, the characters typed in will be inserted after the current
cursor position. If you specify a count, all the text that had been inserted will
be repeated that many times.
:h move the cursor to the left one character position.
:i enter insert mode, the characters typed in will be inserted before the current
cursor position. If you specify a count, all the text that had been inserted will
be repeated that many times.
:j move the cursor down one line.
:k move the cursor up one line.
:l move the cursor to the right one character position.
:r replace one character under the cursor. Specify count to replace a number of characters
:u undo the last change to the file. Typing u again will re-do the change.
:x delete character under the cursor. Count specifies how many characters to delete.
The characters will be deleted after the cursor.
58 INTRODUCTION TO PROGRAMMING
3.7.6. Com
3.7.6. pilation and R
Compilation unning a Vi tte
Running e xt edit or pr
editor ogr
progr am
ogram
To Compile a file with filename filename.c
CC filename.c
OR
GCC filename.c
To Run a file with filename filename.c
a.Out
OR
/a.out
a.out or /a.out will run a file which is currently closed or saved using Vi text editor.
SUMMAR
SUMMARYY
1. Problems are obstacles or undesirable situations that prevent us from getting an objective.
So there is thirst to solve the problem in order to get objective.
2. An Algorithm is the step-by-step procedure to solve a particular problem in our own
Language.
3. Complexity is defined as the total space and time required to store and to execute an
algorithm or problem.
4. Space complexity of an algorithm is the total space used or required to store an algorithm
or program in memory.
5. Time Complexity of an algorithm is total time required to execute an algorithm.
6. This is a modeling tool to describe out algorithm pictorially or graphically, which is easy
to understand
7. DFD is modeling tool that allow us to make system as a network of functional processes,
connected one another by Pipelines & Holding Tanks of data.
8. Different techniques used to design an algorithms are recursion, divide & conquer,
backtracking, branch & bound, iterative, Dynamic programming, greedy approach, brute
force method.
9. Various symbol used in the flow chart are oval, rectangle, parallelogram, diamond box,
connector, line.
10. The Process entity identifies a process taking place, it must have at least one input and
output.
11. The Data Flow entity identifies the flow of data between processes, data stores & external
entities.
12. The Data Store entity identifies stores of data, both manual and electronic.
13. The External Entity identifies external entities which interacts with the system, usually
clients but can be within the same organization.
14. Text editor is a program that enables you to create and edit text files
15. Line editor is A primitive form of editor that requires you to specify a specific line of text
before you can make changes to it.
16. Screen-oriented editors are the editors enable you to modify any text that appears on
the display screen by moving the cursor to the desired location.
17. VI is another text editor, which is used to create & edit text files & Pronounced as Vee
eye editor and which is available on all UNIX system.
OVERVIEW OF ALGORITHM, FLOW CHARTS AND DFD 59
18. When the editor is in insert mode then whatever typed becomes the part of the document
and put these typed keystrokes into the current file.
19. When the editor is in command mode then the keystrokes entered by keyboard are
interpreted as commands that control the edit session.
EXER CISES
EXERCISES
1. What are the characteristics of an algorithm?
2. Write an algorithm to swap two numbers without using third variable.
3. What is the difference between a flowchart & Data flow Diagram ?
4. Draw a flowchart that reads two numbers x & y and prints the bigger of them. It gives an
appropriate message if both the numbers are same
5. What is Vi editor ?
+0)26-4 !
6. Write an algorithm to generate Fibonacci series and also draw the flowchart.
7. Explain in brief different modes of Vi editor and list the commands ?
8. Why does data flow diagram is required in modeling software system. Give some data flow
diagram at different levels for any example software system ?
9. Draw a flowchart to find whether the given number is prime or not.
10. What do you mean by algorithm ? Give an example.
11. What is the difference between a flowchart and data flow diagram ?
12. Draw flowchart for the following :
(i) to sort a list of N numbers
(ii) to find the sum of digits of a number.
13. Draw flow chart for the following :
(i) to find the smallest number from a list of N numbers
(ii) to print the digits of a number in reverse order.
14. Briefly discuss the features of VI editor.
15. Explain DFD with an example.
16. What is the difference between Screen editor and line editor ?
17. Three points are given (x1,y1), (x2,y2) and (x3,y3). Obtain a flowchart to check if they are
collinear.
18. Write short note on editing tools ?
GGG