0% found this document useful (0 votes)
6 views57 pages

Unit 1 Python

The document provides an overview of computational thinking and problem-solving techniques, including algorithms, flowcharts, and pseudocode. It discusses the properties and qualities of good algorithms, building blocks of algorithms, and the advantages and disadvantages of flowcharts. Additionally, it covers programming languages, algorithmic problem-solving strategies, and the concepts of iterations and recursions.

Uploaded by

gemstoreseven
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)
6 views57 pages

Unit 1 Python

The document provides an overview of computational thinking and problem-solving techniques, including algorithms, flowcharts, and pseudocode. It discusses the properties and qualities of good algorithms, building blocks of algorithms, and the advantages and disadvantages of flowcharts. Additionally, it covers programming languages, algorithmic problem-solving strategies, and the concepts of iterations and recursions.

Uploaded by

gemstoreseven
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

Unit 1

Computational Thinking
Problem Solving
Problem solving is the systematic approach to define the problem and
creating number of solutions.

PROBLEM SOLVING TECHNIQUES


1. Algorithms.
2. Flowcharts.
3. Pseudo codes.
4. programs
Algorithm
Step by step procedure for solving problem

Properties of Algorithms
• Should be written in simple English
• Each and every instruction should be precise and unambiguous.
• Instructions in an algorithm should not be repeated infinitely.
Keep adding numbers (no stopping condition)
Add numbers until the user enters 0

• Algorithm should conclude after a finite number of steps.


• Should have an end point

• Derived results should be obtained only after the algorithm terminates.


adding all subjects
Qualities of a good algorithm
Time
Memory
Accuracy

Example
Write an algorithm to print „Good Morning”
Step 1: Start
Step 2: Print “Good Morning”
Step 3: Stop
Building blocks of algorithms (statements, state,
control flow, function)
Statements:
single action in a computer
State:
Transition from one process to another process
Control flow:
Process of executing the individual statements in a given order.
The control can be executed in three ways
1. Sequence
2. Selection
3. Iteration
Sequence:
All the instructions are executed one after another is called sequence
execution.
Example:
Add two numbers:
Step 1: Start
Step 2: get a,b
Step 3: calculate c=a+b
Step 4: Display c
Step 5: Stop
Selection:
A selection statement causes the program control to be transferred to a
specific part of the program based upon the condition.
Example
Write an algorithm to check whether he is eligible to vote?
Step 1: Start
Step 2: Get age
Step 3: if age >= 18 print “Eligible to vote”
Step 4: else print “Not eligible to vote”
Step 6: Stop
Iteration:
Certain set of statements are executed again and again based upon
conditional test. i.e. executed more than one time. This type of
execution is called looping or iteration.
Write an algorithm to print all natural numbers up to n
Step 1: Start
Step 2: get n value.
Step 3: initialize i=1
Step 4: if (i<=n) go to step 5 else go to step 7
Step 5: Print i value and increment i value by 1
Step 6: go to step 4
Step 7: Stop
1. What is a statement in an algorithm?
A. A group of instructions
B. A single instruction
C. A decision structure
D. A loop structure
2. Which of the following is the smallest unit of an algorithm?
A. Sequence
B. Selection
C. Iteration
D. Statement
3. Sequence refers to:
A. Repetition of statements
B. Decision making
C. Execution of statements one after another
D. Skipping statements
4. Which building block is used for decision making?
A. Sequence
B. Selection
C. Iteration
D. Statement
5. Iteration is used when:
A. Statements are executed only once
B. A condition is checked
C. Statements need to be repeated
D. Output is displayed
6. Which of the following is NOT a building block of an algorithm?
A. Sequence
B. Selection
C. Iteration
D. Statement
7. If–else statement represents which building block?
A. Sequence
B. Selection
C. Iteration
D. Statement
8. Printing numbers from 1 to 10 uses:
A. Sequence
B. Selection
C. Iteration
D. Statement
Functions:
sub program which consists of block of code(set of instructions)that
performs a particular task.
For complex problems, the problem is been divided into smaller and
simpler tasks during algorithm design.

Benefits of Using Functions


• Reduction in line of code
• code reuse
• Better readability
• Easy to debug and test
• Improved maintainability
Example:
Algorithm for addition of two numbers using function

Main function()
Step 1: Start
Step 2: Call the function add()
Step 3: Stop

Sub function add()


Step 1: Function start
Step 2: Get a, b Values
Step 3: add c=a+b
Step 4: Print c
Step 5: Return
3. NOTATIONS
Flow chart is defined as graphical representation of the logic for
problem solving.
The purpose of flowchart is making the logic of the program clear in a
visual representation.
Rules for drawing a flowchart
1. should be clear, neat and easy to follow.
2. must have a logical start and finish.
3. Only one flow line should come out from a process symbol.
4. Only one flow line should enter a decision symbol. However, two or
three flow lines may leave the decision symbol.

5. Only one flow line is used with a terminal symbol.


6. Within standard symbols, write briefly and precisely.
7. Intersection of flow lines should be avoided
Advantages of flowchart:
1. Communication
2. Effective analysis
3. Proper documentation
4. Efficient Coding
5. Proper Debugging.
6. Efficient Program Maintenance
Disadvantages of flow chart:
1. Complex logic
2. Alterations and Modifications
3. Reproduction
4. Cost
PSEUDO CODE
Example: Making Tea
“How do you explain tea making to a robot?”
PSEUDO CODE
BEGIN
BOIL water
ADD tea powder
ADD sugar
POUR milk
BOIL for 5 minutes
FILTER tea
END
PSEUDO CODE
• Short, readable and formally styled English languages used for explain
an algorithm(logic of a pgm).
•Easy to understand
•Language independent
•Not machine readable
•Cannot be compiled
•No standard syntax
Guidelines:
• Write one statement per line
INPUT a
INPUT b
ADD a, b
• Capitalize initial keyword (Keywords are written in CAPITAL letters)
BEGIN
PRINT result
END
• Indent to hierarchy (Use space (indent) to show which steps belong together)
IF a > b
PRINT a
ENDIF
• End multiline structure (Any block that starts must end properly)
IF condition
statement
ENDIF
• Keep statements language independent.
Common keywords used in pseudocode
The following gives common keywords used in pseudocodes.
1. //
// This program adds two numbers

2. BEGIN,END
BEGIN
PRINT "Hello“
END
3. INPUT, GET, READ
INPUT a
INPUT b
4. COMPUTE, CALCULATE
COMPUTE c = a + b
5. ADD, SUBTRACT, INITIALIZE
INITIALIZE sum = 0
ADD a, b INTO sum
6. OUTPUT, PRINT, DISPLAY
PRINT c
7. IF, ELSE, ENDIF
IF marks >= 50
PRINT "Pass“
ELSE
PRINT "Fail“
ENDIF
8. WHILE, ENDWHILE
WHILE i <= 5
PRINT i
ENDWHILE
9. FOR, ENDFOR
FOR i = 1 TO 5
PRINT i
ENDFOR
Example:
Addition of two numbers:
BEGIN
GET a,b
ADD c=a+b
PRINT c
END
[Link] Language
Set of symbols and rules for instructing a computer to perform specific task.
Follow all the specified rules .
Types of programming language
1. Machine language
Adv
Translation free
high speed
Disadv
It is hard to find errors
time consuming process

2. Assembly language
Ex:

Assembler
3. High level language:
-Specified rules are followed
- interpreter or compilers
They are divided into following categories:
1. Interpreted programming languages
2. Functional programming languages
3. Compiled programming languages
4. Procedural programming languages
5. Scripting programming language
6. Markup programming language
7. Concurrent programming language
8. Object oriented programming language
1. Interpreted Programming Languages
Meaning: These languages do not need to be turned into machine code
first. Instead, an interpreter reads your code line by line and runs it
immediately.
Examples: Python

2. Compiled Programming Languages


Meaning: These languages are turned into machine code first by a
compiler before they run. After compiling, the program can run directly on
the computer.
Examples: C, C++, C#, Java
3. Functional Programming Languages
Meaning: These languages treat everything like a mathematical function.
There are no step-by-step instructions like in procedural programming.
• telling the computer:“Here’s a formula, give me the answer,”

Examples: Haskell, Clean

4. Procedural Programming Languages


Meaning: These languages tell the computer step by step what to do.
Programs are made of procedures or functions that can be reused.
Examples: MATLAB
5. Scripting Languages
Meaning: These languages are used to automate tasks or control other
applications. They don’t usually make full programs—they help with repeated
tasks.
A small robot that does a repetitive job for you automatically.
Examples: AppleScript, VBScript

6. Markup Languages
Meaning: These are not programming languages, but they tell the computer
how to display text or data.
Examples: HTML, XML
7. Concurrent Programming Languages
Meaning: These languages can do many tasks at the same time
(concurrently).
Examples: Joule, Limbo

8. Object-Oriented Programming Languages


Meaning: These languages use objects to store data and actions
(methods). Each object is like a mini-program itself.
Examples: Java, Moto, Lava
ALGORITHMIC PROBLEM SOLVING
Algorithmic problem solving is solving problem that require the
formulation of an algorithm for the solution
Algorithm Design Technique:
•Divide and Conquer
•Greedy method
•Dynamic Programming

write the steps to solve the problem- recipe that anyone can follow and get the same
result.
Must be clear and unambiguous.

always works correctly.

Memory usage
Efficiency (Time complexity)
SIMPLE STRATEGIES FOR DEVELOPING
ALGORITHMS:
1. Iterations
2. Recursions
Iterations:
A sequence of statements is executed until a specified condition is true
is called iterations.
1. for loop
2. While loop
Recursions:
A function that calls itself is known as recursion.
Recursion is a process by which a function calls itself repeatedly until
some specified condition has been satisfied.
Algorithm

stopping point of recursion.


Write an algorithm to find area of a rectangle

Algorithm , flowchart , pseudocode

Area = l*b
Write an algorithm for Calculating area and
circumference of circle
Write an algorithm for Calculating simple
interest

You might also like