Assignment#2-100426154 (dhavalkumar patel)

Assignment#2-100426154 (dhavalkumar patel) - Dhavalkumar...

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

View Full Document Right Arrow Icon
Dhavalkumar Patel 100426154 Assignment #2 Discrete Mathematics 3.3 Complexity of Algorithms (p. 199): Exercise 2. 3.4 The Integers and Division (p. 209): Exercise 16. 3.5 Primes and Greatest Common Divisors (p. 217): Exercise 10. 3.8 Matrices (p. 256): Exercise 20.
Background image of page 1

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

View Full DocumentRight Arrow Icon
2. Write the algorithm that puts the first four terms of a list of arbitrary length in increasing order. Show that this algorithm has time complexity O (1) in terms of the number of comparisons used. Answer: bubble sort (al, . .., an: real numbers with n :::: 2) For i: = 1 to n – 1 For j: = 1 to n – i If aj > aj+l then interchange aj and aj+l {aI, . .. , an is in increasing order} It has O(1) complexity
Background image of page 2
16. Evaluate these quantities. a)-17 mod 2 b) 144 mod 7 c) -101 mod 13 d)199 mod 19 a) -17 mod 2 Solution: Note: The remainder cannot be negative -9 2 -17 - (-18) +1 (-9)*2= -18, then the remainder would be +1 Therefore, -17 mod 2= +1 Proof: To verify the answer we can multiply 2 by -9, and add it with the remainder +1
Background image of page 3

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

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/11/2012 for the course LSDHFA 234 taught by Professor Sdaf during the Spring '12 term at UOIT.

Page1 / 7

Assignment#2-100426154 (dhavalkumar patel) - Dhavalkumar...

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

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