Chapter5.pdf 2
Chapter5.pdf 2
and Algorithms
Chapter 05 CS1003
1.1
Algorithms
Big-O
If each of these steps is considered to be a basic unit of
Notation computation, then the execution time for an algorithm can be
expressed as the number of steps required to solve the
problem.
Deciding on an appropriate basic unit of computation can be a
complicated problem and will depend on how the algorithm is
implemented.
Big-O Notation
The exact number of operations is not as important as determining the most dominant part of
the comparison function.
In other words, as the problem gets larger, some portion of the comparison function tends to
overpower the rest.
The order of magnitude function describes the part of comparison that increases the fastest as
the value of comparison increases.
Sometimes the performance of an algorithm depends on the exact values of the data
rather than simply the size of the problem.
For these kinds of algorithms we need to characterize their performance in terms of:
The worst case performance refers to a particular data set where the algorithm
performs especially poorly.
Whereas a different data set for the exact same algorithm might have
extraordinarily good performance.
The first step in the process will be to convert the second string
to a list.
Each character from the first string can be checked against the
characters in the list and if found, checked off by replacement.
We need to note that each of the n characters in the first
word (e.g., string or list) will cause an iteration through up
to n characters in the list from the second word.
Analyzing
The number of visits then becomes the sum of the integers
Solution 1 from 1 to n.
Solution 3: occurs.
• However, there is a difficulty with this approach.
Analyzing First two iterations used to count the characters are both based
Solution 4 on n.
Third iteration, compare the two lists of counts, and will always
takes 26 steps since there are 26 possible characters in the
strings.
This condition checks whether the number of elements is even. It’s a constant-time
operation.