Growth of Functions: Asymptotic Notations Direct Address Tables Hashing
מושגים O (Asymptotic Notation) הגדרה : T(n)=O(g(n)) אם קיים n 0 וקבוע C>0 כך שלכל n n 0 מתקיים T(n) Cg(n) דוגמא : 4n100+=O(n) 4n+100 Cn C 4+100/n n 0 =100, C=5
מושגים O מהו הנכון ? 3n+1 = O(n 2 ) (n+1) 2 =O(n 2 ) (n+1) 2 =O(n) 8=O(1) log(n)=O(n) nlog(n)=O(n)
מושגים O (Asymptotic Notation) הגדרה : T(n)= (g(n)) אם קיים n 0 וקבוע C>0 כך שלכל n n 0 מתקיים T(n) Cg(n) דוגמא : 4n100+= (n) 4n+100 Cn C 4+100/n n 0 =1, C=4
מושגים O מהו הנכון ? 3n+1 = (n 2 ) (n+1) 2 = (n 2 ) (n+1) 2 = (n) 8= (1) log(n)= (n) nlog(n)= (n)
מושגים O (Asymptotic Notation) הגדרה : T(n)= (g(n)) אם קיים n 0 וקבועים C 1,C 2 >0 כך שלכל n n 0 מתקיים C 1 g(n) T(n) C 2 g(n) דוגמא : 4n100+= (n) C 1 n 4n+100 C 2 n C 2 4+100/n C 1 4+100/n n 0 =100, C 2 =5, C 1 =4
מושגים O מהו הנכון ? 3n+1 = (n 2 ) (n+1) 2 = (n 2 ) (n+1) 2 = (n) 8= (1) log(n)= (n) nlog(n)= (n)
תכונות של O A={O } 1) Transitivity: if f(n)=A(g(n)) and g(n)=A(h(n)) then f(n)=A(h(n)) 2) Reflexivity: f(n)=A(f(n)) 3) Symmetry: if f(n)= (g(n)) then g(n)= (f(n)) 3’) Transpose symmetry: if f(n)= O(g(n)) then g(n)= (h(n))
דוגמא :
דוגמא : פעולות על רשימה. זמני ריצה L={x 1,x 2,…, x n } ListSearch(value):Ptr Ptr x Head() While (not Outside(x)) and Key(x) <> value x Next(x)(worst case:) If Outside(x) (n) Return nil Else Return x