)
ED
HK
(J
at
Bh
al
An Introduction to
qb
.I
Algorithms .M
of
Pr
By
Prof. Muhammad Iqbal Bhat
Topics
)
ED
H
K
(J
at
Bh
al
qb
.I
.M
of
Pr
ALGORITHMS CHARACTERISTICS OF ALGORITHMS FOR BASIC
AN ALGORITHM PROBLEMS
Algorithms:
An algorithm is a set of step-by-step instructions for solving a problem or accomplishing a specific task.
They are used in many fields, such as computer science, mathematics, engineering, and more.
)
ED
K H
Algorithms are like a recipe, which tells you what to do and in what order to achieve a specific outcome.
(J
at
Bh
They are designed to be executed by machines, such as computers, and humans can also execute them if needed.
al
qb
The use of algorithms is not a new concept, and people have been using them for centuries to solve problems.
.I
.M
With the advent of computers and the growth of technology, the use of algorithms has become more prevalent in various applications
today. of
Pr
The importance of algorithms cannot be overstated as they are crucial in solving problems and accomplishing tasks in many fields.
As we move further into the digital age, understanding algorithms and being able to design and implement them is becoming a
fundamental skill.
Famous but oldest Algorithms:
1700-2000 BC: The Egyptian algorithm for multiplying two numbers
)
ED
1600 BC: The Babylonian algorithm for factorization and finding square roots
KH
(J
300 BC: Euclid’s algorithm for finding the greatest common divisor of two numbers
at
Bh
200 BC: The Sieve of Eratosthenes for finding prime numbers
al
qb
.I
263 AD: Gaussian elimination for solving linear equations
.M
of
Pr
628 AD: Chakravala method for finding integer solutions to indeterminate quadratic equations
820 AD: Al-Khawarizmi’s algorithms for solving linear and quadratic equations and using the Hindu-Arabic
numeral system
Recent Algorithms with Huge Impact:
Generative adversarial networks AlphaFold, a deep-learning
(GANs), a type of neural network system that can predict the 3D GPT-3, a large natural-language
)
ED
that can create realistic images, structure of proteins, which is computer model that can generate
videos, and sounds from scratch crucial for understanding many realistic and coherent text on
HK
or by manipulating existing data biological processes and diseases almost any topic
(J
at
Bh
al
2014 2016 2018 2020 2020
qb
.I
.M
of
TikTok’s recommendation The algorithm for mRNA vaccines,
Pr
algorithms, which power the “For which enabled the rapid
You” feed and create viral ) development and deployment of
sensations and new forms of D
HE effective vaccines against covid-
( JK
online expression hat l B
19
b a
. Iq
ro f. M
P
Characteristics of an Algorithm:
Input: An algorithm requires some input values to start with. For example, an algorithm that multiplies
two numbers needs two numbers as input.
)
ED
Output: An algorithm produces one or more output values as a result of its execution. For example, an
H
algorithm that multiplies two numbers returns one number as output.
K
(J
at
Bh
Unambiguity: An algorithm should be clear and precise, without any room for confusion or interpretation. Each
instruction in an algorithm should have only one meaning and effect.
al
qb
.I
Finiteness: An algorithm should have a limited number of instructions and steps that can be counted. It should also
.M
terminate after a finite amount of time or iterations.
of
Pr
Effectiveness: An algorithm should be efficient and feasible to execute. Each instruction in an algorithm should be simple
enough to be carried out by a computer or a human.
Language independence: An algorithm should be independent of any programming language or platform. It can be expressed
in any language or notation that is understandable by humans or computers.
)
ED
HK
(J
Algorithms for
at
Bh
Problem-Solving
al
qb
and Decision-
.I
Making .M
of
Pr
Algorithms for Problem-Solving and Decision-Making
Structured Approach
• Algorithms offer a step-by-step plan for problem-solving and decision-making
• They assist in creating a systematic and organized approach
Breaking Down Complex Problems
)
ED
H
• Complex problems can be overwhelming, but algorithms simplify them
K
(J
• By dividing problems into smaller tasks, algorithms increase efficiency
at
Reproducibility
Bh
al
• Algorithms ensure consistent and repeatable results
qb
•
.I
Repeatedly following the same algorithm produces the same outcome
.M
Error Reduction Pr
of
• Algorithms minimize the likelihood of errors and oversights
• They provide clear guidelines and predefined steps
Efficiency
• Algorithms are designed to solve problems in the shortest time possible
• They optimize the use of resources for effective decision-making
Examples of Algorithmic Problem-Solving
Mathematics Automated Tasks
• Long division • Routine tasks like data entry that are automated with algorithms
• Solving equations using the quadratic formula • Reduction in time and effort required for these tasks
Economics
)
Data Analysis
ED
• Financial modeling algorithms for predicting market trends • Processing and analyzing large datasets made easier with algorithms
K H
• Algorithms in risk assessment for investment decisions • Ability to extract valuable insights from the data
(J
To-Do Lists
at
Optimizing Resources
Bh
• Creating a to-do list as an algorithm for organizing daily tasks
• Businesses using algorithms to optimize resource allocation
•
al
Prioritizing tasks in order of importance within the algorithm
•
qb
Examples include workforce scheduling and supply chain management
Online Shopping
.I
• Recommendation systems suggesting products based on past purchases
.M
•
of
Pricing algorithms adjusting product prices based on demand
Pr
Gaming
• AI opponents in games following algorithms for decision-making
• Game pathfinding algorithms assisting characters in navigating the
game environment
Algorithms for Basic Problems:
)
ED
There are many basic problems that can be
HK
solved using algorithms, such as sorting,
(J
at
searching, and calculating.
Bh
al
qb
•Sorting
.I
.M
of
•Searching )
Pr
ED
(JKH
at
Bh
•Calculating . I q bal
f. M
Pro
Sorting Algorithms:
Sorting algorithms are used to arrange data in a specific order, such as alphabetical, numerical, or chronological
)
order.
ED
K H
(J
at
There are various sorting algorithms that differ in their complexity, stability, and performance.
Bh
al
qb
.I
Some common sorting algorithms are bubble sort, insertion sort, selection sort, merge sort, quick sort,
.M
and heap sort.
of
Pr
Live Demo of Sorting Algorithms:
• Sorting (Bubble, Selection, Insertion, Merge, Quick, Counting, Radix) - VisuAlgo
• Interactive animations (ide.sk)
Searching Algorithms:
Searching: Searching is the process of finding an item (such as a number,
)
ED
word, or record) in a collection of items (such as an array, list, or database).
H
K
(J
There are many search algorithms that differ in their complexity, efficiency,
at
Bh
and applicability.
al
qb
Some common searching algorithms are linear search, binary search,
.I
.M
interpolation search, and hashing.
of
Pr
Live Demo of Sorting Algorithms: ED )
(JKH
at
l Bh
• Sorting (Bubble, Selection, Insertion, Merge, Quick, Counting, Radix) - VisuAlgo I q ba
M.
ro f.
P
Calculating Algorithms:
Calculating algorithms are used to perform calculations, such as addition,
subtraction, multiplication, division, and more.
)
ED
H
K
(J
There are various calculating algorithms, including the simple, long, and multi-digit
at
Bh
arithmetic algorithms, among others.
al
qb
.I
.M
These algorithms are essential in computer science and mathematics and have
of
numerous applications in real-world scenarios.
Pr
The efficiency of these algorithms is critical, as the time and space complexity can
significantly affect their performance.
Examples of Calculating Algorithms:
• An algorithm to calculate the area of a circle given its radius:
)
ED
Start
H
K
(J
Declare a constant PI with value 3.14
at
Bh
Input radius
al
qb
Compute area = PI * radius * radius
.I
.M
Output area of )
Pr
End (JKH ED
at
l Bh
I q ba
M.
f.
Pro
Examples of Calculating Algorithms:
• An algorithm to calculate the sum of the first n natural numbers:
)
ED
Start
H
K
Input n
(J
at
Initialize sum = 0
Bh
al
For i = 1 to n:
qb
.I
Add i to sum
.M
End for of
Pr
Output sum
End
Examples of Calculating Algorithms:
• An algorithm to calculate the factorial of a positive integer n:
)
ED
Start
H
K
Input n
(J
at
Initialize result = 1
Bh
al
For i = 1 to n:
qb
.I
Multiply result by i
.M
End for of
Pr
Output result
End
Questions?
Pr
of
.M
.I
qb
al
Bh
at
(J
K H
ED
)