Uploaded by MAHE Senthan

Activity 1

advertisement
Activity 1
What is algorithm?

In mathematics and computer science, an algorithm is a finite sequence of welldefined instructions commonly used to solve a specific problem class or to
perform a calculation. A computer program can be considered as an extensive
algorithm. In mathematics and computer science, an algorithm usually refers to a
small algorithm that solves a recurring problem. Algorithms are used as
specifications for calculations and data processing.
What are the characteristics of a good algorithm?

Unambiguous - Algorithm should be clear and unambiguous. Each of its steps (or
phases), and their inputs/outputs should be clear and must lead to only one
meaning.

Input - An algorithm should have 0 or more well-defined inputs.

Output - An algorithm should have 1 or more well-defined outputs, and should
match the desired output.

Finiteness - Algorithms must terminate after a finite number of steps.

Feasibility - Should be feasible with the available resources.

Independent - An algorithm should have step-by-step directions, which should be
independent of any programming code.
Page | 1
Pseudo Code for Fibonacci Series:
Step 1: Start
Step 2: Read number from User
Step 3: Initialize Variable a=0, b=1, i=1
Step 4: Display a, b
Step 5: While i<=n-2
C=a +b
Display C
a=C
i=i+1
END While
Step 7: Stop
Pseudo Code for Factorial:
Read number
Fact = 1, i= 1
WHILE i<=number
Fact=Fact*i
i=i+1
ENDWHILE
WRITE Fact
Stop
Page | 2
Steps in Writing and Executing a Program:

Problem Definition:
Clearly define the problem to be solved.

Algorithm Design:
Develop a step-by-step plan (algorithm) to solve the problem.

Coding:
Translate the algorithm into a programming language.

Compilation/Interpretation:
Convert the code into machine-readable format.

Testing:
Verify the correctness of the program using test cases.

Debugging:
Identify and fix any errors in the code.

Execution:
Run the program on specific inputs.

Maintenance:
Update or modify the program as needed.
Page | 3
Challenges in Writing Code:

Logic Errors:
Mistakes in the algorithm or code lead to incorrect results.

Syntax Errors:
Typos or incorrect usage of programming language syntax.

Runtime Errors:
Issues occurring during program execution.

Testing Challenges:
Ensuring all possible scenarios are covered in testing.

Optimization:
Enhancing the code for better performance.
Taking a sample number to dry run of Fibonacci series:
Input(n)
4
a
b
0
1
c
i
I<=n-2
Output
1
0
1
TRUE
1
1
1
1
2
TRUE
2
2
1
2
3
FALSE
Page | 4
Taking a sample number to dry run of Factorial of Number:
Input(n)
4
f
i
1
1
I<=n
output
TRUE
1
2
TRUE
2
3
TRUE
6
4
TRUE
24
5
FALSE
24
Big-O Notation:

Big-O notation is used to describe the upper bound on the growth rate of an
algorithm's time complexity. It represents the worst-case scenario for the
algorithm's performance.
Page | 5
Python Code for Fibonacci series:
Result is :
Page | 6
Python Code for Factorial Number:
Result is :
Page | 7
Activity 2
Programming Paradigm Defined:

A programming paradigm is the classification, style or way of programming. It is
an approach to solving problems by using programming languages. Depending on
the language, the difficulty of using a paradigm differs.

A programming format is the classification, style, or methodology of a program. It
is an approach to problem solving using programming languages. Depending on
the language, the difficulty of using a paradigm varies.

There are several programming languages that use paradigms, but in order to do
this they must follow a strategy or methodology. The following is an overview of
programming languages and their paradigms.
Page | 8
Procedural Paradigm:
Main Characteristics:




Based on procedures or routines.
Emphasizes procedures (functions) and the sequence of steps to be
followed.
Data is often global and can be accessed by any part of the
program.
Example languages: C, Pascal.
Code Sample :
Result is :
Page | 9
Object -oriented Paradigm:
Main Characteristics:




Programs respond to user actions or events (e.g., button click, mouse
movement).
Utilizes event handlers/callbacks to manage events.
Commonly used in graphical user interface (GUI) applications.
Example languages: JavaScript, Visual Basic.
Page | 10
Download