Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Document preview thumbnail
Preview 4 out of 205 pages
Summary

Summary programming

Document preview thumbnail
Preview 4 out of 205 pages

A note on the field of programming, how to learn programming and training courses for programming, learning programming from scratch to professionalism, learning programming for beginners to professionalism, programming languages

Content preview

INTRODUCTION TO C++ UNIT 1



1
Algorithms, Flowcharts & Program
Design

Unit Structure:
1.1 Objectives
1.2 Introduction
1.3 Algorithms
1.3.1 Expressing Algorithms
1.3.2 Benefits of Using Algorithms
1.3.3 General Approaches in Algorithm Design
1.3.4 Analysis of Algorithms
1.4 Flowcharts
1.4.1 Advantages of Using Flowcharts
1.4.2 Limitations of Using Flowcharts
1.4.3 When to Use Flowcharts
1.4.4 Flowchart Symbols & Guidelines
1.4.5 Types of Flowcharts
1.5 Program Design
1.5.1 Activities involved in Program Design
1.5.2 Object-Oriented Formulations
1.6 Summary
1.7 Unit End Exercises
1.7.1 Questions
1.7.2 Programming Projects
1.8 Further Reading

1.1 OBJECTIVES

After completing this chapter, you will be able to:
 Understand the basics and usefulness of an algorithm,
 Analyse various algorithms,
 Understand a flowchart and its advantages and limitations,
 Steps involved in designing a program.

1.2 INTRODUCTION

A computer is a useful tool for solving a great variety of
problems. To make a computer do anything (i.e. solve a problem), you
have to write a computer program. In a computer program you tell a
computer, step by step, exactly what you want it to do. The computer
then executes the program, following each step mechanically, to
accomplish the end goal.
INSTITUTE OF DISTANCE & OPEN LEARNING 1

,INTRODUCTION TO C++ UNIT 1

The sequence of steps to be performed in order to solve a
problem by the computer is known as an algorithm.

Flowchart is a graphical or symbolic representation of an
algorithm. It is the diagrammatic representation of the step-by-step
solution to a given problem.

Program Design consists of the steps a programmer should do
before they start coding the program in a specific language. Proper
program design helps other programmers to maintain the program in
the future.

1.3 ALGORITHMS

Look around you. Computers and networks are everywhere,
enabling an intricate web of complex human activities: education,
commerce, entertainment, research, manufacturing, health
management, communication, even war. Of the two main
technological underpinnings of this amazing proliferation, one is the
breathtaking pace with which advances in microelectronics and chip
design have been bringing us faster and faster hardware. The other is
efficient algorithms that are fuelling the computer revolution.

In mathematics, computer science, and related subjects, an
algorithm is a finite sequence of steps expressed for solving a problem.
An algorithm can be defined as “a process that performs some
sequence of operations in order to solve a given problem”. Algorithms
are used for calculation, data processing, and many other fields.

In computing, algorithms are essential because they serve as the
systematic procedures that computers require. A good algorithm is like
using the right tool in the workshop. It does the job with the right
amount of effort. Using the wrong algorithm or one that is not clearly
defined is like trying to cut a piece of plywood with a pair of scissors:
although the job may get done, you have to wonder how effective you
were in completing it.

Let us follow an example to help us understand the concept of
algorithm in a better way. Let’s say that you have a friend arriving at
the railway station, and your friend needs to get from the railway
station to your house. Here are three different ways (algorithms) that
you might give your friend for getting to your home.


 The taxi/auto-rickshaw algorithm:
 Go to the taxi/auto-rickshaw stand.
 Get in a taxi/auto-rickshaw.
 Give the driver my address.
 The call-me algorithm:
 When your train arrives, call my mobile phone.
INSTITUTE OF DISTANCE & OPEN LEARNING 2

,INTRODUCTION TO C++ UNIT 1
 Meet me outside the railway station.
 The bus algorithm:
 Outside the railway station, catch bus number 321.
 Transfer to bus 308 near Kurla station.
 Get off near Kalina University.
 Walk two blocks west to my house.

All these three algorithms accomplish the same goal, but each
algorithm does it in a different way. Each algorithm also has a different
cost and a different travel time. Taking a taxi/auto-rickshaw, for
example, is the fastest way, but also the most expensive. Taking the
bus is definitely less expensive, but a whole lot slower. You choose the
algorithm based on the circumstances.

In computer programming, there are often many different
algorithms to accomplish any given task. Each algorithm has
advantages and disadvantages in different situations. Sorting is one
place where a lot of research has been done, because computers spend
a lot of time sorting lists.

Three reasons for using algorithms are efficiency, abstraction and
reusability.
 Efficiency: Certain types of problems, like sorting, occur often
in computing. Efficient algorithms must be used to solve such
problems considering the time and cost factor involved in each
algorithm.

 Abstraction: Algorithms provide a level of abstraction in
solving problems because many seemingly complicated
problems can be distilled into simpler ones for which well-
known algorithms exist. Once we see a more complicated
problem in a simpler light, we can think of the simpler problem
as just an abstraction of the more complicated one. For
example, imagine trying to find the shortest way to route a
packet between two gateways in an internet. Once we realize
that this problem is just a variation of the more general shortest
path problem, we can solve it using the generalised approach.

 Reusability: Algorithms are often reusable in many different
situations. Since many well-known algorithms are the
generalizations of more complicated ones, and since many
complicated problems can be distilled into simpler ones, an
efficient means of solving certain simpler problems potentially
lets us solve many complicated problems.

1.3.1 Expressing Algorithms:

Algorithms can be expressed in many different notations,
including natural languages, pseudocode, flowcharts and
programming languages. Natural language expressions of algorithms
tend to be verbose and ambiguous, and are rarely used for complex or
INSTITUTE OF DISTANCE & OPEN LEARNING 3

, INTRODUCTION TO C++ UNIT 1
technical algorithms. Pseudocode and flowcharts are structured ways
to express algorithms that avoid many ambiguities common in natural
language statements, while remaining independent of a particular
implementation language. Programming languages are primarily
intended for expressing algorithms in a form that can be executed by a
computer, but are often used to define or document algorithms.

Sometimes it is helpful in the description of an algorithm to
supplement small flowcharts with natural language and/or arithmetic
expressions written inside block diagrams to summarize what the
flowcharts are accomplishing.

Consider an example for finding the largest number in an
unsorted list of numbers.

The solution for this problem requires looking at every number in the
list, but only once at each.
1) Algorithm using natural language statements:
a) Assume the first item is largest.
b) Look at each of the remaining items in the list and if it is larger
than the largest item so far, make a note of it.
c) The last noted item is the largest item in the list when the
process is complete.

2) Algorithm using pseudocode:
largest = L0
for each item in the list (Length(L) ≥ 1), do
if the item ≥ largest, then
largest = the item
return largest


1.3.2 Benefits of using Algorithms:

The use of algorithms provides a number of benefits. One of
these benefits is in the development of the procedure itself, which
involves identification of the processes, major decision points, and
variables necessary to solve the problem. Developing an algorithm
allows and even forces examination of the solution process in a
rational manner. Identification of the processes and decision points
reduces the task into a series of smaller steps of more manageable size.
Problems that would be difficult or impossible to solve in entirety can
be approached as a series of small, solvable sub-problems.

By using an algorithm, decision making becomes a more
rational process. In addition to making the process more rational, use
of algorithm will make the process more efficient and more consistent.
Efficiency is an inherent result of the analysis and specification
process. Consistency comes from both the use of the same specified
process and increased skill in applying the process. An algorithm
serves as a mnemonic device and helps ensure that variables or parts of
INSTITUTE OF DISTANCE & OPEN LEARNING 4

Document information

School year
1
Uploaded on
July 19, 2023
Number of pages
205
Written in
2022/2023
Type
Summary
$6.89

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Sold
0
Followers
0
Items
43
Last sold
-


Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions