Adsa-1 Unit
Adsa-1 Unit
Continues………
MC4101
Algorithms as a Technology
MC4101
CONSTANT VALUE=3
VARIABLE VALUE=5
MC4101
AB-VARIABLE
10-CONSTANT
MC4101
MC4101
MC4101
Asymptotic analysis
EXAMPLE
MC4101
Asymptotic notation
MC4101
MC4101
EXAMPLE SUM:
MC4101
MC4101
MC4101
When you’re getting started with programming, it’s also important that
algorithms are clear and simple to understand. While it’s important to consider
efficiency, it’s not necessary to try and find the most efficient algorithm. This
is a very hard task and a very efficient algorithm may be harder to understand.
MC4101
Remember, you often need to return to your code and understand it in order to
make changes, and other people may also need to work with your code.
Recall that you can also have alternative algorithms that give different
results for the same problem.
For example, different search engines return different results for the
same query.
The search algorithms used by the major search engines are regularly
changed and improved. Efficiency is very important for getting results
back to searchers quickly, but the results need to be high quality. It’s no
use returning poor results quickly.
When designing an algorithm, you often need to balance time efficiency
with the quality of the results.
MC4101
Space Efficiency
Actual Data: The actual data, such as whether the name is first or
last in a sequential search.
Approaches to Time Efficiency
Asymptotic Categorization
This employs basic categories to offer a basic notion of performance,
which is also called an order of magnitude. If the algorithms are similar, the
data amount is little, or performance is essential, then the next method can
be explored further.
Space Complexity
When we create a problem-solving algorithm, it demands the use of computer
memory to complete its execution. Memory is necessary for the following
purposes in any algorithm:
int square(int a)
return a*a;
}
MC4101
In the preceding piece of code, variable ‘a’ takes up 2 bytes of memory, and
the return value takes up another 2 bytes, i.e., it takes a total of 4 bytes of
memory to finish its execution, and for any input value of ‘a’, this 4 byte
memory is fixed. Constant Space Complexity is the name given to this type of
space complexity.
Time Complexity
Every algorithm needs a certain amount of computer time to carry out its
instructions and complete the operation. The amount of computer time
required is referred to as time complexity. In general, an algorithm’s execution
time is determined by the following:
return a+b;
}
MC4101
In the following example code, calculating a+b takes 1 unit of time, and
returning the value takes 1 unit of time, i.e., it takes two units of time to
perform the task, and it is unaffected by the input values for a and b. This
indicates it takes the same amount of time for all input values, i.e., 2 units.
Recurrences:
MC4101
Recursion
Types of recursion
There are two types of recursion:
Direct recursion
Indirect recursion
MC4101
Direct Recursion :
A function fun is called direct recursive if it calls the same function fun.
void directFun()
{
// Some code....
directFun();
// Some code...
}
C
Copy
Indirect Recursion
A function fun is called indirect recursive if it calls another function say fun
_new and fun _new calls fun directly or indirectly.
void indirectFun1()
{
// Some code...
indirectFun2();
// Some code...
}
void indirectFun2()
{
// Some code...
indirectFun1();
// Some code...
}
MC4101
5. We sum the costs within each of the levels of the tree to obtain a set of pre-
level costs and then sum all pre-level costs to determine the total cost of all
levels of the recursion.
Example 1
Consider T (n) = 2T + n2
T (n) = 4T +n
When we add the values across the levels of the recursion trees, we get a
value of n for every level. The longest path from the root to leaf is
MC4101