0% found this document useful (0 votes)
12 views20 pages

Factors Influencing The Performance of Algorithms - Computational Complexity - Classification of Algorithms

Uploaded by

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

Factors Influencing The Performance of Algorithms - Computational Complexity - Classification of Algorithms

Uploaded by

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

- Factors Influencing the

Performance of Algorithms

- Computational Complexity

- Classification of Algorithms
What is an Algorithm?
 An algorithm is a step-by-step guide or a set of
instructions to solve a problem or do a task.
 Examples:
 A recipe for cooking a dish (a set of steps to
prepare food).
 Instructions to find a phone number in a contact
list.
Factors Influencing the Performance of
Algorithms
 These are the things that affect how fast or slow an
algorithm works.
 Key Factors:
 Size of the input (how much data you have).
 Time it takes to run (time complexity).
 Memory it uses (space complexity).
 The environment it runs in (hardware and software).
Input Size
 The number of elements (like numbers or characters) the
algorithm has to work with.
 Impact: The more data you have, the longer it may take for
the algorithm to finish.
 Example: A sorting algorithm takes longer to sort 1,000
numbers than 10 numbers because there is more data to
process.
Time Complexity
 A way to measure how the time needed for an algorithm to
run, changes with the size of the input.
 Common Notations:
 O(1): Takes the same amount of time, no matter how big
the input is.
 O(n): Time grows directly with the size of the input.
 O(n^2): Time grows with the square of the input size (if
the input size doubles, the time grows four times).
 Example: Finding a name in a sorted phone book using
binary search takes much less time (O(log n)) than checking
every name one by one (O(n)).
Space Complexity
 A way to measure how much extra memory an algorithm
needs to run.
 Types of Space:
 Input Space: Memory required to store the input data.
 Auxiliary Space: Extra memory the algorithm needs
apart from the input data.
 Example: A sorting algorithm that uses extra space to store
a new list while sorting has higher space complexity than
one that sorts in place without extra memory.
Hardware and Software Environment
 CPU Speed: Faster processors can execute more instructions in a
second.
 Memory Size: More memory can allow for larger data sets and better
performance.
 Compiler Optimizations: Some compilers translate code more
efficiently.
 Operating System: The OS can impact performance based on how it
manages resources.

 Impact: The same algorithm can perform differently on different


computers or software setups.
Computational Complexity Overview
 The study of how the time and space required by an
algorithm grow with the size of the input.

 Purpose: Helps us understand which algorithms are more


efficient and why some algorithms are better for certain
tasks.
Time Complexity Analysis
 Worst-Case Complexity: The maximum amount of time an
algorithm could take for any input. It helps us prepare for
the worst-case scenario.

 Average-Case Complexity: The average time taken if we


consider all possible inputs. Useful for understanding typical
performance.

 Best-Case Complexity: The minimum time an algorithm


will take. Not very useful for judging an algorithm, as it
rarely occurs.
Space Complexity Analysis
 Memory Requirements:
 Primary Memory (RAM): The amount of RAM needed
while the algorithm is running.
 Secondary Memory (Disk): The amount of disk space
needed if the algorithm uses files or stores large amounts
of data.
 Trade-offs: Some algorithms use less memory but may take
longer to run, while others use more memory to be faster.
Big O Notation
 To describe the worst-case time or space complexity of an
algorithm.
 Examples:
 O(1): Takes the same amount of time, no matter how big
the input is.
 O(n): Time grows directly with the size of the input.
 O(n log n): Grows slightly faster than linear but much
slower than quadratic (O(n^2)).
 O(n^2): Time grows with the square of the input size (if
the input size doubles, the time grows four times).
Classification of Algorithms
 Algorithms can be grouped based on how they work and
what they do.
 Categories:
 Sorting: Algorithms to arrange data.
 Searching: Algorithms to find data.
 Graph Algorithms: Algorithms to solve problems related
to graphs (like maps or networks).
 Dynamic Programming: Algorithms to solve problems by
breaking them into smaller, simpler subproblems.
 Divide and Conquer: Algorithms that split a problem into
smaller parts, solve them, and then combine the results.
Sorting Algorithms
 Examples:
 Bubble Sort: Compares each pair of adjacent elements
and swaps them if they are in the wrong order (O(n^2))
 Example: 8 2 4 1 3

 Quick Sort: Picks a 'pivot' and partitions the array into


elements less than and greater than the pivot (O(n log n)
average case).

 Use Cases: Sorting is used in organizing data for quick


access
Searching Algorithms
 Examples:

 Linear Search: Checks each element one by one (O(n)).

 Binary Search: Efficiently finds an element in a sorted


list by repeatedly dividing the search interval in half
(O(log n)).

 Use Cases: Searching is used to find specific elements in


data.
Graph Algorithms
 Shortest Path Algorithms:

 Dijkstra's Algorithm: Finds the shortest path from one


node to all other nodes in a weighted graph (where edges
have weights or costs).

 Bellman-Ford Algorithm: Also finds shortest paths but


can handle graphs with negative weights.

 Applications: Network routing, pathfinding in maps.


Dynamic Programming
 A technique for solving problems by breaking them
down into simpler subproblems, solving each
subproblem just once, and storing their solutions.
 Examples:
 Fibonacci Sequence
 Knapsack Problem
Divide and Conquer
 A method of solving problems by dividing them into smaller
subproblems, solving each subproblem, and combining their
results.
 Examples:
 Merge Sort: Splits the array in half, recursively sorts each
half, and then merges the sorted halves (O(n log n)).
 Quick Sort: Picks a pivot, partitions the array around the
pivot, and recursively sorts the partitions (average O(n log
n)).
 Use Cases: Useful in tasks like sorting large datasets and
solving mathematical problems that can be broken down into
simpler, independent tasks.
Real-World Applications of Algorithms

 Sorting Algorithms: Used in databases to organize and


quickly retrieve data.
 Search Algorithms: Essential in search engines, where fast
retrieval of information is needed.
 Dynamic Programming: Used in financial models to
optimize decisions over time, like in portfolio management.
 Graph Algorithms: Used in GPS systems for finding the
shortest path and in social networks for friend suggestions.
Summary
 The performance of algorithms is influenced by input
size, time, and space requirements, and the
computing environment.
 Understanding computational complexity helps us
choose the right algorithm for the right task.
 Algorithms are classified by their design and
application areas, and different types of algorithms
are suited for different kinds of problems.
Questions?

You might also like