Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
47 views
3 pages
DAA 1.2 Adi
daa worksheet
Uploaded by
Aditya khanna
AI-enhanced title
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Download
Save
Save DAA 1.2 adi For Later
Share
0%
0% found this document useful, undefined
0%
, undefined
Print
Embed
Report
0 ratings
0% found this document useful (0 votes)
47 views
3 pages
DAA 1.2 Adi
daa worksheet
Uploaded by
Aditya khanna
AI-enhanced title
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Carousel Previous
Carousel Next
Download
Save
Save DAA 1.2 adi For Later
Share
0%
0% found this document useful, undefined
0%
, undefined
Print
Embed
Report
Download
Save DAA 1.2 adi For Later
You are on page 1
/ 3
Search
Fullscreen
DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING GRADE Discover Learn. Empower Course Name: DAA Lab Course Code: 211TH-311/21CSH-311 Experiment 1.2 Aim: Develop a program for implementation of power function and determine that complexity should be O(log n). Objectives: © Develop a program to efficiently compute the power ofa given base raised to a given exponent using O(log n) complexity. + Implement exponentiation by squaring technique to minimize multiplication operations and achieve faster computation for large exponents. Input/Apparatus Used: Laptop, VS code, C++ Procedure/Algorithm: Input: n (base), power (exponent) Output: result (result of n raised to the power) * The program starts by reading the base a and the exponent b from the user. * It defines a function power(a, b) that calculates the result of raised to the power of b using a recursive divide and conquer approach. * In the power function: © Ifpower is 0, the base case is reached, and the function returns 1. © Itrecursively calculates temp by calling itself with n and power/2 as arguments. Then, it squares temp by multiplying it with itself (emp * temp). If power is even, it directly returns temp If power is odd, it returns temp * n, effectively multiplying an extran term to account for the odd power. ° oo © The power functions called with the provided basen and powerpower, and the result is stored in the variable result. © Finally, the result is printed using the format "n Power power is result", * The program ends. Name: Aditya Khanna vid:2 1 BCS11424DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING GRAD) Dinowes toon Eopoees SER Ua Course Name: DAA Lab Course Code: 21ITH-311/21CSH-311 * The algorithm follows the same logic as the provided C++ code and achieves logarithmic complexity (O(logn)) by halving the power at each recursion step. Sample Code: #tinclude
using namespace std; float power(int a,int b){ if(b>==0){ return 1; 3 float temp=p ower(a,b/2); iffb%2==0){ return temp*temp; } else { if(b>0){ return a*temp*temp; 3 else return (temp *temp)/a; } } int main0){ float a,b; cout<<"Enter Base="; cin>>a Name: Aditya Khanna vid:2 1 BCS11424DEPARTMENT OF NAAC COMPUTER SCIENCE & ENGINEERING GRADE Diecoes lnom Expres Course Name: DAA Lab Course Code: 211TH-311/21CSH-311 cout<< cin>>b; "Enter exponent="; cout<<"Power is = "<< power(a,b); return 0; Observations/Outcome: PROBLEMS OUTPUT DEBUG CONSOLE aval 9 Time Complexity: The time complexity of given code is O(log n) Learning Outcome: * Learned the concept of dividing a problem into smaller sub-problems and solving them independently. * Learned to analyze the complexity of algorithms and saw that the power function implemented using a divide-and-conquer strategy has a complexity of O(log n). * Gained insights into how mathematical properties can be leveraged to optimize computations. Name: Aditya Khanna vid:2 1 BCS11424
You might also like
Algorithms Solutions Dasgupta PDF
PDF
No ratings yet
Algorithms Solutions Dasgupta PDF
66 pages
Cs170 Solutions Manual
PDF
No ratings yet
Cs170 Solutions Manual
66 pages
Data Structure - Chap 1
PDF
No ratings yet
Data Structure - Chap 1
42 pages
Algorithm and Architecture For Logarithm, Exponential, and Powering Computation
PDF
No ratings yet
Algorithm and Architecture For Logarithm, Exponential, and Powering Computation
12 pages
Lab 4 Sol
PDF
No ratings yet
Lab 4 Sol
9 pages
Algorithm Analysis (Big O)
PDF
No ratings yet
Algorithm Analysis (Big O)
26 pages
L4 DC en
PDF
No ratings yet
L4 DC en
43 pages
Assignment 5: Recursive Functions
PDF
No ratings yet
Assignment 5: Recursive Functions
5 pages
Intro Homework
PDF
No ratings yet
Intro Homework
4 pages
Subject Name: DAA LAB: Experiment Title
PDF
No ratings yet
Subject Name: DAA LAB: Experiment Title
4 pages
Math/CS 466/666: Shifted Inverse Power Method Lab: 8 Complex Eigenvalues For A Real 5x5 Matrix Im
PDF
No ratings yet
Math/CS 466/666: Shifted Inverse Power Method Lab: 8 Complex Eigenvalues For A Real 5x5 Matrix Im
4 pages
Basic Algorithms in Number Theory
PDF
No ratings yet
Basic Algorithms in Number Theory
44 pages
Modular Exponentiation - Article
PDF
No ratings yet
Modular Exponentiation - Article
4 pages
C++ - Effectively Calculate The Result of Geometric Series - Co
PDF
No ratings yet
C++ - Effectively Calculate The Result of Geometric Series - Co
4 pages
Daa Experiment 2
PDF
No ratings yet
Daa Experiment 2
5 pages
Index: Course Name: DAA Lab
PDF
No ratings yet
Index: Course Name: DAA Lab
4 pages
Lab 2
PDF
No ratings yet
Lab 2
7 pages
Oop 4
PDF
No ratings yet
Oop 4
8 pages
Problem Solving and Python Programming Laboratory
PDF
No ratings yet
Problem Solving and Python Programming Laboratory
59 pages
CS-E3190 Lect03 PDF
PDF
No ratings yet
CS-E3190 Lect03 PDF
27 pages
Number Theory: Modular Arithmetic
PDF
No ratings yet
Number Theory: Modular Arithmetic
4 pages
Alg Ch1 Part3
PDF
No ratings yet
Alg Ch1 Part3
22 pages
Test 1 Review and Practice Questions
PDF
No ratings yet
Test 1 Review and Practice Questions
7 pages
Model Qp-Bloom Sample
PDF
No ratings yet
Model Qp-Bloom Sample
3 pages
Loops and Recursion
PDF
No ratings yet
Loops and Recursion
2 pages
CS29003 Algorithms Laboratory Assignment 1: Logarithmic Vs Linear Vs Exponential Growth of Functions
PDF
No ratings yet
CS29003 Algorithms Laboratory Assignment 1: Logarithmic Vs Linear Vs Exponential Growth of Functions
4 pages
Bincoef
PDF
No ratings yet
Bincoef
17 pages
CP Algorithms Com Algebra Binary Exp HTML
PDF
100% (1)
CP Algorithms Com Algebra Binary Exp HTML
5 pages
Basic Number Theory-1: Tutorial Problems
PDF
No ratings yet
Basic Number Theory-1: Tutorial Problems
10 pages
DAA 1.2 Chandan Kumar-1
PDF
No ratings yet
DAA 1.2 Chandan Kumar-1
3 pages
Lab 1-1410
PDF
No ratings yet
Lab 1-1410
6 pages
Daa 2
PDF
No ratings yet
Daa 2
3 pages
Lab 2
PDF
No ratings yet
Lab 2
5 pages
Power: Def If Return Else Return
PDF
No ratings yet
Power: Def If Return Else Return
2 pages
Daa Nik 2
PDF
No ratings yet
Daa Nik 2
3 pages
Daa 2 Zoro
PDF
No ratings yet
Daa 2 Zoro
3 pages
EQTVuAhSFY (Dragged) 2
PDF
No ratings yet
EQTVuAhSFY (Dragged) 2
1 page
DAA Ex-2
PDF
No ratings yet
DAA Ex-2
2 pages
20BCS5977 - Daa Worksheet-2
PDF
No ratings yet
20BCS5977 - Daa Worksheet-2
3 pages
7 IntroToRecursion
PDF
No ratings yet
7 IntroToRecursion
73 pages
Daa 2
PDF
No ratings yet
Daa 2
3 pages
ADA Lab Manual Final
PDF
No ratings yet
ADA Lab Manual Final
29 pages
Materi Fast Exponentiation
PDF
No ratings yet
Materi Fast Exponentiation
2 pages
MCS-211 Design and Analysis of Algorithms
PDF
No ratings yet
MCS-211 Design and Analysis of Algorithms
38 pages
Bitmagic CPP
PDF
No ratings yet
Bitmagic CPP
5 pages
Oops Practical File 2322813
PDF
No ratings yet
Oops Practical File 2322813
10 pages
2 - 2 RecurrenciasDasgupta-Papadimitriou-Vazirani
PDF
No ratings yet
2 - 2 RecurrenciasDasgupta-Papadimitriou-Vazirani
4 pages
C Language 12
PDF
No ratings yet
C Language 12
4 pages
0.1 Big-O Notation: N N N N
PDF
No ratings yet
0.1 Big-O Notation: N N N N
16 pages
Headstart Week 2
PDF
No ratings yet
Headstart Week 2
12 pages
Modular Exponentiation
PDF
No ratings yet
Modular Exponentiation
8 pages
Practical 4
PDF
No ratings yet
Practical 4
3 pages
02 Intro Arrays
PDF
No ratings yet
02 Intro Arrays
14 pages
Task 1 To 4
PDF
No ratings yet
Task 1 To 4
20 pages
Exercise1 Sol
PDF
No ratings yet
Exercise1 Sol
5 pages
Lecture 3
PDF
No ratings yet
Lecture 3
36 pages
DAA Worksheet 2 - Alasso
PDF
No ratings yet
DAA Worksheet 2 - Alasso
3 pages
Bit Manipulations Leetcode
PDF
No ratings yet
Bit Manipulations Leetcode
12 pages