Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions Icon

Related questions

bartleby

Concept explainers

Question
**Exercise 3.**

Consider the following algorithms A and B for the problem of computing \(2^n \mod 317\). (This is the modular exponentiation problem that we have discussed in class. Algorithm A is the one that we have seen in class, and algorithm B is a variant of it.)

**Algorithm A.**

```plaintext
mod_exp_A(n) {
  if (n == 0) return 1;
  else {
    t = mod_exp_A(n/2);
    if (n is even) return t * t (mod 317);
    if (n is odd) return t * t * 2 (mod 317);
  }
}
```

**Algorithm B.**

```plaintext
mod_exp_B(n) {
  if (n == 0) return 1;
  else {
    if (n is even) return mod_exp_B(n/2) * mod_exp_B(n/2) (mod 317);
    if (n is odd) return mod_exp_B(n/2) * mod_exp_B(n/2) * 2 (mod 317);
  }
}
```

1. Write the recurrence for the runtime \( T_A(n) \) of algorithm A, and solve the recurrence to find a \(\Theta(\cdot)\) estimation of \( T_A(n) \).

2. Write the recurrence for the runtime \( T_B(n) \) of algorithm B, and solve the recurrence to find a \(\Theta(\cdot)\) estimation of \( T_B(n) \).

3. Which algorithm is faster? (Note: There is a huge difference between \( T_A \) and \( T_B \).)
expand button
Transcribed Image Text:**Exercise 3.** Consider the following algorithms A and B for the problem of computing \(2^n \mod 317\). (This is the modular exponentiation problem that we have discussed in class. Algorithm A is the one that we have seen in class, and algorithm B is a variant of it.) **Algorithm A.** ```plaintext mod_exp_A(n) { if (n == 0) return 1; else { t = mod_exp_A(n/2); if (n is even) return t * t (mod 317); if (n is odd) return t * t * 2 (mod 317); } } ``` **Algorithm B.** ```plaintext mod_exp_B(n) { if (n == 0) return 1; else { if (n is even) return mod_exp_B(n/2) * mod_exp_B(n/2) (mod 317); if (n is odd) return mod_exp_B(n/2) * mod_exp_B(n/2) * 2 (mod 317); } } ``` 1. Write the recurrence for the runtime \( T_A(n) \) of algorithm A, and solve the recurrence to find a \(\Theta(\cdot)\) estimation of \( T_A(n) \). 2. Write the recurrence for the runtime \( T_B(n) \) of algorithm B, and solve the recurrence to find a \(\Theta(\cdot)\) estimation of \( T_B(n) \). 3. Which algorithm is faster? (Note: There is a huge difference between \( T_A \) and \( T_B \).)
Expert Solution
Check Mark
Knowledge Booster
Background pattern image
Computer Science
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
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education