You are on page 1of 4

Experiment Title-02

Student Name:Syed Zaid Ali UID:19BET1035


Branch: IT Section/Group-01
Semester: 5th Date of Performance:03/08/2021
Subject Name-Design and Analysis of Algorithm Lab
Subject Code:-ITP-309

1. Aim/Overview of the practical: Code to implement power function in O(log n) time complexity.

2. Task to be done/ Which logistics used: Code Block

3. Algorithm/Flowchart (For programming based labs):

The algorithm is simple implementation of following recurrence relation used to calculate 'a' to
the power 'b' where 'a' and 'b' are integers.
4. Steps for experiment/practical/Code:

#include<iostream>
using namespace std;
class pow
{

public:
int power(int x, unsigned int y)
{
if (y == 0)
return 1;
else if (y % 2 == 0)
return power(x, y / 2) * power(x, y / 2);
else
return x * power(x, y / 2) * power(x, y / 2);
}
};

int main()
{
pow g;
int x = 4;
unsigned int y = 5;

cout << g.power(x, y);


return 0;
}
5. Result/Output/Writing Summary:

Learning outcomes (What I have learnt):


1.Learnt about power function.

2.Best Algorithm to find power

3.Time Complexity: O(n)

Space Complexity: O(1)

Algorithmic Paradigm: Divide and conquer.


Evaluation Grid (To be created as per the SOP and Assessment guidelines by the faculty):

Sr. No. Parameters Marks Obtained Maximum Marks


1.
2.
3.

You might also like