Midterm review problems with solutions

Midterm review problems with solutions - 2. O(n 2 ) 3. No,...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Big-O Analysis - Finding two numbers in an array of size N that sum to a specific value Given a list of numbers in an array, find two numbers in the array that sum to a particular value. For example, let’s say I have an array of numbers as so, array = {1, 2, 5, 3, 10, 7, 3, 6, 11, 8, 9, 6, 6, 7, 9, 12}, and the number I am interested in is number = 14 1. How would you find two such numbers? Please describe your algorithm in pseudo code. 2. Given the size of the problem, N, representing number of numbers in the array of numbers. What is the Big-O of the algorithm you described in part 1? 3. Is the algorithm you described in part 1 the fastest? If not, what is the Big-O of the fastest algorithm? Solution: 1. Add two numbers from array and compare with n, e.g., 14; Do it for all two numbers pairs in the array.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 2. O(n 2 ) 3. No, O(n) using dictionary Modular Exponentiation Prove Solution: See lecture note on mod Modular Inverse Find the modulo inverse of 103 in base 4 (Hint: 103 is in base 4) Solution: 1: 3+3 = 6, 6 mod 4 = 2 2: 2+3 = 5, 5 mod 4 = 1 Modulo inverse is 3 Key Generation Given two prime numbers, 61 and 53 1. Find public key 2. Let e = 17, encrypt a message m, m = 3 Solution: 1. N = 61 x 53 = 3233, e is a small prime < (p-1)(q-1) = 3120, choose e = 17 2. 3^17 mod 3233 = 1211 Test for Prime Number Use Fermats little theorem to test if 23 is a prime number (Hint: avoid rounding) Solution: Test with a=2: 2^(23-1) mod 23 = 1 (pass) Test with a=3: 3^(23-1) mod 23 = 1 (pass) Test with a=5: 5^(23-1) mod 23 = 1 (pass) Thus, 23 is a prime number...
View Full Document

Page1 / 2

Midterm review problems with solutions - 2. O(n 2 ) 3. No,...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online