Introduction to Algorithms
3rd Edition
ISBN: 9780262033848
Author: Thomas H. Cormen, Ronald L. Rivest, Charles E. Leiserson, Clifford Stein
Publisher: MIT Press
expand_more
expand_more
format_list_bulleted
Question
Chapter 31.6, Problem 2E
Program Plan Intro
To show: Modular exponential
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Write an iterative algorithm to find base r representation of a decimal number n. Analyse its timecomplexity using O, Ω, Θ.
Give regular expressions for the i
(a) {w : w contains at most two 1s}
(b) {w : w contains at least two 1s}
(c) {w: every odd position in w is 1}
(d) {w : w contains an even number of 0s, or
Implement the modular exponentiation (a.k.a. fast exponentiation)function mod_exp (b, n, m) to compute bn (mod m) more efficiently. (Hint: toread n bit-by-bit, use / and % operations repeatedly)a) Test your function for b = 3, n = 231 – 2, m = 231 – 1.b) Report the result and the time (in seconds) it takes to find the result.
in pahton
Chapter 31 Solutions
Introduction to Algorithms
Ch. 31.1 - Prob. 1ECh. 31.1 - Prob. 2ECh. 31.1 - Prob. 3ECh. 31.1 - Prob. 4ECh. 31.1 - Prob. 5ECh. 31.1 - Prob. 6ECh. 31.1 - Prob. 7ECh. 31.1 - Prob. 8ECh. 31.1 - Prob. 9ECh. 31.1 - Prob. 10E
Ch. 31.1 - Prob. 11ECh. 31.1 - Prob. 12ECh. 31.1 - Prob. 13ECh. 31.2 - Prob. 1ECh. 31.2 - Prob. 2ECh. 31.2 - Prob. 3ECh. 31.2 - Prob. 4ECh. 31.2 - Prob. 5ECh. 31.2 - Prob. 6ECh. 31.2 - Prob. 7ECh. 31.2 - Prob. 8ECh. 31.2 - Prob. 9ECh. 31.3 - Prob. 1ECh. 31.3 - Prob. 2ECh. 31.3 - Prob. 3ECh. 31.3 - Prob. 4ECh. 31.3 - Prob. 5ECh. 31.4 - Prob. 1ECh. 31.4 - Prob. 2ECh. 31.4 - Prob. 3ECh. 31.4 - Prob. 4ECh. 31.5 - Prob. 1ECh. 31.5 - Prob. 2ECh. 31.5 - Prob. 3ECh. 31.5 - Prob. 4ECh. 31.6 - Prob. 1ECh. 31.6 - Prob. 2ECh. 31.6 - Prob. 3ECh. 31.7 - Prob. 1ECh. 31.7 - Prob. 2ECh. 31.7 - Prob. 3ECh. 31.8 - Prob. 1ECh. 31.8 - Prob. 2ECh. 31.8 - Prob. 3ECh. 31.9 - Prob. 1ECh. 31.9 - Prob. 2ECh. 31.9 - Prob. 3ECh. 31.9 - Prob. 4ECh. 31 - Prob. 1PCh. 31 - Prob. 2PCh. 31 - Prob. 3PCh. 31 - Prob. 4P
Knowledge Booster
Similar questions
- Implement the modular exponentiation (a.k.a. fast exponentiation) function mod_exp (b, n, m) to compute bn (mod m) more efficiently. (Hint: to read n bit-by-bit, use / and % operations repeatedly) a) Test your function for b = 3, n = 231 – 2, m = 231 – 1. b) Report the result and the time (in seconds) it takes to find the result. Q3. [30 pts] Modify your is_prime function to use the mod_exp (b, n, m) instead of the standard power operation (b**n % m). Rename it as is_prime2. Modify the mersenne (p) function to use is_prime2, and call it mersenne2. a) Use the modified function mersenne2 to print all the Mersenne primes Mp for p between 2 and 31 if possible, (with k = 3 in the is_prime function). Compare the results with the ones found in Q1. b) Gradually increase the range of p to find more Mersenne primes (say up to p = 101 if possible). What is the largest Mersenne prime you can achieve here? c) Extend the work in part (b) and find the maximum Mersenne prime you can get from this…arrow_forwardGiven an integer say 45, to find the sum of 45 with 8 in binary form (see the figure below), we can use the TM designed in slides 79-90 of the notes "Turing Machines and Equivalent Models I" twice to find the result. A more effective way is to design a TM to do the addition with 8 directly. 1000 101101 A + = ? Such a TM can be designed by extending the TM designed in slides 79-90 of the notes "Turing Machines and Equivalent Models I". The TM has 14 instructions and 6 states: 0, 1, 2, 3, 4, and halt. Six instructions of such a TM have been given in the first and the second tables below. Fill out the remaining blanks in the first and the second tables and also blanks in the third table to show the remaining instructions of the TM (you have to use your own text boxes here)arrow_forwardImplement SHANKS' ALGORITHM for finding discrete logarithms in Zp, where p is prime and & is a primitive element modulo p. Use your program to find log106 12375 in Z24691 and log 248388 in Z¼58009arrow_forward
- Let n be an even integer where n>0. How many bitstrings have more ones than zeros with a length n? The answer does not have to be in a closed formarrow_forwardWrite a python code that calculates the integral of the cos^2(x) function in the interval [0,π/4 ] using the monte carlo method.arrow_forwardWhen multiplying an elliptic curve point P by a positive integer n, it can be done in O(log n) time by doubling an accumulator and adding P according to the bit pattern of n. For example, 6P can be expressed as ((0*2+P)*2+P)*2. In the format shown above, show the sequence of doubles and adds, from left to right, needed to compute 11P. 11 in binary is 1011. Autograder format: Begin with 0*2. After each +P close a parentheses (don't forget the opening parentheses) and after each *2 do not insert a close parentheses. Because of the order of operations these are the only parentheses needed. Do not insert any other parentheses or any spaces. Hint: there should be exactly three close parentheses.arrow_forward
- An irreducible polynomial of degree 8 over GF(2) is given as f(x) =x+x+x'+x +1. This can be used to define GF(2)=GF(256) which is frequently used to design a code over the ASCII symbols consisting of 8 bits. We will use the following notation, for a, e GF(2), e ar + a,r+ ar ++ aa +a, (A) Write a computer program of addition and multiplication for all the binary 8-tuples as above and answer to the following questions: (B) Find any member a in GF(256) with the property that a, a², a²̟., a5 are all distinct, Calculate as al28, and a4. ANSWER: ) :a binary 8-tuple ):a binary 8-tuple ):a binary 8-tuple ):a binary 8-tuple a = ( a4 = ( a12 =( ass = ( (C) Calculate the multiplications a a, att . atza, and a al0 using your program in (A). Verify, for example, that a at = al+64 = ats, a*. a1zi - att12- al92 etc. (D) Define a linear function g from GF(256) to itself such that g(x) = x for any x in GF(256). Here, the linearity implies that g preserves two operations of the field. That is, for any…arrow_forwardBased on the binary division algorithm, find the value of C: C=0.3/ (A-B), where A= 0.25 (ten), B= -0.20 (ten). Finally, show the binary representation of C in: - Single precision. - Double precision.arrow_forwardExpress the following function as a sum of minterms and as a product of maxterms:F(A, B, C, D) = BD + AD + BDarrow_forward
- A c++ program that implements full subtractor using full adder for n bits.(Eg if n=4,the program should subtract two 4 bit numbers and show the output after subtraction as well as borrow)arrow_forwardLet say A*B. The input of A is 10101010, and input of B is 10101010. Can you help me do this in multiplication , create a truth table truth table of the result and simplify it using k map? Pleasearrow_forwardIf F(x, y, z) = (xy + z') (x'z + y), what is the complement of F (you don't have to simplify it) ?arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
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