INDIAN INSTITUTE OF TECHNOLOGY ROORKEE

Data Structures CSN- 102 Dr. R. Balasubramanian Associate Professor Department of Computer Science and Engineering Indian Institute of Technology Roorkee Roorkee 247 667 [email protected] https://sites.google.com/site/balaiitr/

More Big-Oh Examples 7n-2 7n-2 is O(n) need c > 0 and n0  1 such that 7n-2  c•n for n  n0 this is true for c = 7 and n0 = 1



3n3 + 20n2 + 5

3n3 + 20n2 + 5 is O(n3) need c > 0 and n0  1 such that 3n3 + 20n2 + 5  c•n3 for n  n0 this is true for c = 4 and n0 = 21



3 log n + 5 3 log n + 5 is O(log n) need c > 0 and n0  1 such that 3 log n + 5  c•log n for n  n0 this is true for c = 8 and n0 = 2 2

Big-Oh and Growth Rate • The big-Oh notation gives an upper bound on the growth rate of a function • The statement “f(n) is O(g(n))” means that the growth rate of f(n) is no more than the growth rate of g(n) • Useful to find the worst case of an algorithm

3

• Prove that

2

f ( n )  5n  2 n  1

is

2

O (n )

4

• Write an efficient program to find whether given number is prime or not.

5

AKS algorithm • Agrawal, Kayal and Saxena from IIT Kanpur have come up with O(log k n) algorithm for a prime number program – PRIMES is in P, Annals of Mathematics, 160(2): 781-793, 2004 • Infosys Mathematics Prize, 2008. • Fulkerson Prize for the paper “PRIMES is in P”, 2006. • Gödel Prize for the paper “PRIMES is in P", 2006. • Several awards and prizes

6

Programming Contest Sites • • • • •

http://icpc.baylor.edu(ACM ICPC) http://www.codechef.com (Online Contest) http://www.topcoder.com http://www.spoj.com http://www.interviewstreet.com

7

Find the output of the following code

int n=32; steps=0; for (int i=1; i<=n;i*=2) steps++; cout<
8

• A log10 (n) , B  log 2 (n) both are of O(log n), base doesn’t matter, • Suppose xm  log m n  f (n) and xk  log k n  g (n)

m

xm

m

xm

 n and

k

k

xk

n

xk

 x m  x k log m k  f ( n )  g ( n ) log m k  cg ( n ) where c  log m k  f ( n )  cg ( n )  f ( n ) and g ( n ) are of O( log n)

 -notation For function g(n), we define (g(n)), big-Omega of n, as the set: (g(n)) = {f(n) :  positive constants c and n0, such that n  n0, we have 0  cg(n)  f(n)} Intuitively: Set of all functions whose rate of growth is the same as or higher than that of g(n). g(n) is an asymptotic lower bound for f(n). 10

• Prove that

2

f ( n )  5n  2 n  1

is

2

(n )

11

Example (g(n)) = {f(n) :  positive constants c and n0, such that n  n0, we have 0  cg(n)  f(n)} • n = (log n). Choose c and n0. for c=1 and n0 =16,

c * log n  n

, n  16

12

13

Omega • Omega gives us a LOWER BOUND on a function.  Big-Oh says, "Your algorithm is at least this good."  Omega says, "Your algorithm is at least this bad."

14

-notation For function g(n), we define (g(n)), big-Theta of n, as the set: (g(n)) = {f(n) :  positive constants c1, c2, and n0, such that n  n0, we have 0  c1g(n)  f(n)  c2g(n)

} Intuitively: Set of all functions that have the same rate of growth as g(n).

g(n) is an asymptotically tight bound for f(n). 15

-notation For function g(n), we define (g(n)), big-Theta of n, as the set: (g(n)) = {f(n) :  positive constants c1, c2, and n0, such that n  n0, we have 0  c1g(n)  f(n)  c2g(n)

} Technically, f(n)  (g(n)). Older usage, f(n) = (g(n)). I’ll accept either…

f(n) and g(n) are nonnegative, for large n. 16

Example (g(n)) = {f(n) :  positive constants c1, c2, and n0, such that n  n0, 0  c1g(n)  f(n)  c2g(n)} • 10n2 - 3n = (n2) • What constants for n0, c1, and c2 will work? • Make c1 a little smaller than the leading coefficient, and c2 a little bigger. • To compare orders of growth, look at the leading term. • Exercise: Prove that n2/2-3n= (n2)

17

Example (g(n)) = {f(n) :  positive constants c1, c2, and n0, such that n  n0, 0  c1g(n)  f(n)  c2g(n)}

• Is 3n3  (n4) ?? • How about 22n (2n)??

18

Examples 3n2 + 17 • (1), (n), (n2)  lower bounds • O(n2), O(n3), ...  upper bounds • (n2)  exact bound

19

Relations Between O, 

20

o-notation For a given function g(n), the set little-o: o(g(n)) = {f(n):  c > 0,  n0 > 0 such that  n  n0, we have 0  f(n) < cg(n)}. f(n) becomes insignificant relative to g(n) as n approaches infinity:

lim [f(n) / g(n)] = 0 n

g(n) is an upper bound for f(n) that is not asymptotically tight. Observe the difference in this definition from previous ones. Why? 21

o-notation •

f(n)=3n+2 is o(n2)



f(n)=17n3 + n2 logn

is o(n4)

22

 -notation For a given function g(n), the set little-omega:

(g(n)) = {f(n):  c > 0,  n0 > 0 such that

 n  n0, we have 0  cg(n) < f(n)}.

f(n) becomes arbitrarily large relative to g(n) as n approaches infinity:

lim [f(n) / g(n)] = .

n

g(n) is a lower bound for f(n) that is not asymptotically tight. 23

 -notation •

f(n)=3n+2 is



f(n)=17n3 +

n2

 (1) is

2

 (n )

24

Comparison of Functions fg  ab f (n) = O(g(n)) f (n) = (g(n)) f (n) = (g(n)) f (n) = o(g(n)) f (n) =  (g(n))

    

a a a a a

  = < >

b b b b b

25

Data Structures

Find the output of the following code int n=32; steps=0; for (int i=1; i<=n;i*=2) steps++; cout<x m m. = = )( log ngn x k k. = = n k n m k m x x. = = ⇒ and k m x x k m = ⇒ k x x m.

2MB Sizes 22 Downloads 263 Views

Recommend Documents

Data Structures
Under certain circumstances: when your program receives a grade of 10 or. 25, you will be ... social media, classroom papers and homework exercises. Missouri ...

Data Structures
Dr. R. Balasubramanian. Associate Professor. Department of Computer Science and Engineering. Indian Institute of Technology Roorkee. Roorkee 247 667.

Data structures
A data structure where elements can be added or removed at either end but not in the middle: (a) Stack. (b) Queue. (c) Linked list, (d) Deque. 5. Which of the following is a two-way list: (a) Singly linked list. (b) Circular list. (c) Linked list wit

kinetic data structures - Basch.org
Alas, this analysis completely breaks down in the case of line segments, as Lemma 3.1 no longer holds. Instead, we use another potential argument reminiscent of the one used independently by several authors 47, 51, 61] for proving upper bounds on the

kinetic data structures - Basch.org
of robustness), and the software system issue of combining existing kinetic data structures as black boxes .... here is only to give a good prototyping environment.

Verifiable Data Structures - Continusec
Certificate Authorities to issue certificates, mail clients may trust a key server to .... practices we expect a small number of dedicated auditors to perform, rather ...

Data Structures & Algorithms.pdf
Page 2 of 2. Page 2 of 2. Data Structures & Algorithms.pdf. Data Structures & Algorithms.pdf. Open. Extract. Open with. Sign In. Main menu. Displaying Data Structures & Algorithms.pdf. Page 1 of 2.

From Control Structures through Data Structures (3rd ...
Structures (3rd Edition) By Tony Gaddis, Godfrey Muganda PDF Free · Click here ... texts, clear and easy-to-read code listings, concise and practical real-world examples, and an abundance ... NET programming, web application development, web services

Data structures in C++.pdf
count( ) return 0 or 1. reserve( ) set the number of buckets. size(). empty(). Nota: hash_table is a very efficient data structure but elements can not be ordered. - -.

Data and File Structures
Read the data in the new node. 3. Assign Flink and Blink as ..... data is directly accessed on a hard disk drive or some other secondary storage device where the.

ReadDownload Data Structures, Algorithms, and ...
ReadDownload Data Structures, Algorithms, and. Software Principles in C EBOOK Full book. Book Synopsis ... data structures and algorithm analysis. Important ...

DATA STRUCTURES NOTES 2.pdf
a tuple, the parentheses are optional, and you may just write the values with. commas in between. The commas create the tuple, not the parentheses — and.

ESTIMATION OF CAUSAL STRUCTURES IN LONGITUDINAL DATA ...
in research to study causal structures in data [1]. Struc- tural equation models [2] and Bayesian networks [3, 4] have been used to analyze causal structures and ...

CS 124 Algorithms and Data Structures Overview
People from all concentrations. (mathematics, biology, physics, economics…) welcome. • Assignments are theoretical/mathematical, but also have programming ...