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

UNIT-1 Building Blocks

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views15 pages

UNIT-1 Building Blocks

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

SNS COLLEGE OF ENGINEERING

Kurumbapalayam (Po), Coimbatore – 641 107


An Autonomous Institution
Accredited by NBA – AICTE and Accredited by NAAC – UGC with ‘A’ Grade
Approved by AICTE, New Delhi & Affiliated to Anna University, Chennai

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

COURSE NAME : 20CS101 PROGRAMMING FOR PROBLEM SOLVING

I YEAR /I SEMESTER

Unit 1- INTRODUCTION TO PROBLEM SOLVING TECHNIQUES


Topic 3: Building Blocks of Algorithms (Statements, State, Control Flow, Functions)
9

UNIT I INTRODUCTION TO PROBLEM SOLVING


TECHNIQUES
Fundamentals - Computer Hardware – Computer Software -
Algorithms - Building blocks of algorithms (statements, state, control
flow, functions) - Notation (pseudo code, flow chart, and
programming language) -Problem formulation - Algorithmic
problem solving - Simple strategies for developing algorithms
(iteration, recursion). Illustrative problems .

3 November 2024 COMPUTER SOFTWARE/ 20CS101 PROGRAMMING FOR PROBLEM SOLVING/PRIYANGA R/CSE/SNSCE 2/19
What is Algorithm?

Definition: An algorithm is procedure consisting of a finite set of


unambiguous rules (instructions) which specify a finite sequence of
operations that provides the solution to a problem. In other word, an
algorithm is a step-by-step procedure to solve a given problem
Definition: An algorithm is a finite number of clearly described,
unambiguous steps that can be systematically followed to produce a
desired result for given input in a finite amount of time.

3 November 2024 BUILDING BLOCKS OF ALGORITHM/ 20CS101 PROGRAMMING FOR PROBLEM SOLVING/PRIYANGA.R/CSE/SNSCE 3/17
Building blocks of algorithm

• It has been proven that any algorithm can be constructed from just
three basic building blocks. These three building blocks are
Sequence, Selection, and Iteration.
Building Block Common name
Sequence Action
Selection Decision
Iteration Repetition or Loop

3 November 2024 BUILDING BLOCKS OF ALGORITHM/ 20CS101 PROGRAMMING FOR PROBLEM SOLVING/PRIYANGA.R/CSE/SNSCE 4/17
Sequence

• A sequence is one of the basic logic structures in computer


programming.
• In a sequence structure, an action, or event, leads to the next
ordered action in a predetermined order.
• The sequence can contain any number of actions, but no actions can
be skipped in the sequence.
• Once running, the program must perform each action in order
without skipping any.

3 November 2024 BUILDING BLOCKS OF ALGORITHM/ 20CS101 PROGRAMMING FOR PROBLEM SOLVING/PRIYANGA.R/CSE/SNSCE 5/17
Selection and Iteration

• A selection (also called a decision) is also one of the basic logic


structures in computer programming. In a selection structure, a
question is asked, and depending on the answer, the program takes
one of two courses of action, after which the program moves on to
the next event .
• An iteration is a single pass through a group/set of instructions. Most
programs often contain loops of instructions that are executed over
and over again. The computer repeatedly executes the loop, iterating
through the loop

3 November 2024 BUILDING BLOCKS OF ALGORITHM/ 20CS101 PROGRAMMING FOR PROBLEM SOLVING/PRIYANGA.R/CSE/SNSCE 6/17
Conti…

3 November 2024 BUILDING BLOCKS OF ALGORITHM/ 20CS101 PROGRAMMING FOR PROBLEM SOLVING/PRIYANGA.R/CSE/SNSCE 7/17
Example

3 November 2024 BUILDING BLOCKS OF ALGORITHM/ 20CS101 PROGRAMMING FOR PROBLEM SOLVING/PRIYANGA.R/CSE/SNSCE 8/17
Example

3 November 2024 BUILDING BLOCKS OF ALGORITHM/ 20CS101 PROGRAMMING FOR PROBLEM SOLVING/PRIYANGA.R/CSE/SNSCE 9/17
Iteration

• Iteration is the act of repeating a process, either to generate an


unbounded sequence of outcomes, or with the aim of approaching
a desired goal, target or result.
• Each repetition of the process is also called an "iteration", and the
results of one iteration are used as the starting point for the next
iteration.

3 November 2024 BUILDING BLOCKS OF ALGORITHM/ 20CS101 PROGRAMMING FOR PROBLEM SOLVING/PRIYANGA.R/CSE/SNSCE 10/17
Example

3 November 2024 BUILDING BLOCKS OF ALGORITHM/ 20CS101 PROGRAMMING FOR PROBLEM SOLVING/PRIYANGA.R/CSE/SNSCE 11/17
Recursion

• The process in which a function calls itself directly or indirectly is


called recursion and the corresponding function is called as
recursive function.
• Using recursive algorithm, certain problems can be solved quite
easily. Examples of such problems are Towers of Hanoi (TOH), In
order/Preorder/Post order Tree Traversals, DFS of Graph, etc.

3 November 2024 BUILDING BLOCKS OF ALGORITHM/ 20CS101 PROGRAMMING FOR PROBLEM SOLVING/PRIYANGA.R/CSE/SNSCE 12/17
Example

int fact(int n)
{
if (n < = 1) // base case
return 1;
else
return n*fact(n-1);
}

3 November 2024 BUILDING BLOCKS OF ALGORITHM/ 20CS101 PROGRAMMING FOR PROBLEM SOLVING/PRIYANGA.R/CSE/SNSCE 13/17
Assessment 1

1. What is Algorithm?

Ans : _______________________________________________________________________

2. Write algorithm for finding greatest of 3 numbers.

Ans : _______________________________________________________________________

3 November 2024 BUILDING BLOCKS OF ALGORITHM/ 20CS101 PROGRAMMING FOR PROBLEM SOLVING/PRIYANGA.R/CSE/SNSCE 14/17
References

TEXT BOOKS
1.E.Balagurusamy, “Fundamentals of Computing and Computer Programming”, 2nd Edition Tata McGRaw-Hill Publishing
Company Limited, (2012). (UNIT – I, II, III, IV, V)
2.Ashok.N.Kamthane,“ Computer Programming”, Pearson Education (India) (2010). (UNIT –II, III IV, V)
3.Reema Thareja, “Programming in C”, 2nd Edition, Oxford University Press,(2015). (UNIT –I,II, III, IV, V)
REFERENCES
1.Byron Gottfried, “Programming with C”, 2nd Edition, (Indian Adapted Edition), TMH Publications, (2006). (Unit II, III, IV)
2.Stephan G kochan, “Programming in C” Pearson Education (2008), (UNIT II, III, IV, V)
3.P.Sudharson, “Computer Programming”, RBA Publications (2008), (UNIT I, II, III, IV)
4.Yashavant P. Kanetkar. “Let Us C”, BPB Publications, 2014.(Unit II, III, IV, V)
5.Anita Goel and Ajay Mittal, “Computer Fundamentals and Programming in C”, Dorling Kindersley (India) Pvt. Ltd.,
Pearson Education in South Asia, 2011. (UNIT – I, II, III, IV, V)
Thank You
3 November 2024 BUILDING BLOCKS OF ALGORITHM/ 20CS101 PROGRAMMING FOR PROBLEM SOLVING/PRIYANGA.R/CSE/SNSCE 15/17

You might also like