
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Question
Design and implement (meaning write code and execute the code turning in test cases and source code) for the following two algorithms to raise an integer to an integer power assume in both cases that n, the exponent, is a power of 2:
Again, in case you don’t have any
X**N = X* X**(N-1)
X**0 = 1
Algorithm 2
n = 2**m
X**n = ((X**2)**2)**2…, etc. [NOTE: the symbol of power (**) is used m times here, i.e., X**8 = ((X**2)**2)**2, because 8 = 2**3].
Which algorithm is more efficient with respect to the number of multiplications?

Transcribed Image Text:(5) Design and implement (meaning write code and execute the code turning in test cases and
source code) for the following two algorithms to raise an integer to an integer power assume
in both cases that n, the exponent, is a power of 2:
Again, in case you don't have any programming language at hand you can use pseudocode
to solve the problem.
1
![Algorithm 1
X**N=X* X**(N-1)
X**0=1
Algorithm 2
n = 2**m
X**n = ((X**2)**2)**2..., etc. [NOTE: the symbol of power (**) is used m times here,
i.e., X**8 = ((X**2)**2)**2, because 8 = 2**3].
Which algorithm is more efficient with respect to the number of multiplications?](https://content.bartleby.com/qna-images/question/db3467fc-1c1d-4346-ac62-4b05a3c2dbd0/966b2aab-c59d-44b1-a50b-db0e6f213de1/kchadnq_thumbnail.png)
Transcribed Image Text:Algorithm 1
X**N=X* X**(N-1)
X**0=1
Algorithm 2
n = 2**m
X**n = ((X**2)**2)**2..., etc. [NOTE: the symbol of power (**) is used m times here,
i.e., X**8 = ((X**2)**2)**2, because 8 = 2**3].
Which algorithm is more efficient with respect to the number of multiplications?
Expert Solution

arrow_forward
Step 1
the program is an given below :
Step by stepSolved in 3 steps with 1 images

Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- Using recursion, write a function sum that takes a single argument n and computes the sum of all integers between 0 and n inclusive. Do not write this function using a while or for loop. Assume n is non-negative. def sum(n): """Using recursion, computes the sum of all integers between 1 and n, inclusive. Assume n is positive. >>> sum(1) 1 >>> sum(5) # 1 + 2 + 3+ 4+ 5 15 "*** YOUR CODE HERE ***"arrow_forwardWrite pseudocode to solve the following problem. Must use iterative dynamic programming (tabulation) and run in O(n) time. Input: positive integer n Output: two non-negative integer x and y where n = x185 + y120 Example: if n=1230 then x=6 and y=1 (1314 = 6(185) + 1(120))arrow_forwardMore sophisticated computer-assisted instruction systems monitor the student’s perfor- mance over a period of time. The decision to begin a new topic is often based on the student’s success with previous topics. Write a program that will help an elementary-school student learn multiplication. Use Math.random to produce two positive one-digit integers. To count the number of correct and incorrect responses typed by the student. After the student answers 10 questions, your program should calculate the percentage of correct responses. If the percentage is lower than 75 percent, display Please ask your instructor for extra help, and reset the quiz so another student can try it.arrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education

Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON

Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education