Padma Reddy

You might also like

Download as pdf
Download as pdf
You are on page 1of 113
Contents PART-A Chapter 1 Introduction 1.1 Notion of algorithm... 1.2 Computing GCD.... 1.2.1 Euclid’s algorithm (Using modulus) 1.2.2 Consecutive integer checking .. 1.2.3 Comparison of Euclid’s algorithm and consecutive integer chee] 1.2.4 Using repetitive subtraction . 1.2.5 Middle school method... 6 Generation of prime numbers pSaoalyss of algorithms. 1.3.1. Orders of growth wk 13.2 Worst case, best case and averag PAsympiotic notations : 1.4.1 Informal definitions of asymptotic notations 1.4.1.1 O (Big-Oh). 1.4.1.2 O (Big-Omega) . 1.4.1.3 6 (Big-Theta: 1.42. Formal definitions of asymptotic notations 1.4.2.1 0 (Big-Oh 1.4.2.2 Q (Big-Omega). 1.4.2.3 6 (Big-Theta) 1.4.2.4 Property of asymptotic notation +143. Order of growth using limit: 1.4.4 Problems on asymptotic notations ... A.5 Important mathematical formulas and simplifications JS Mathematical analysis of Non-recursive algorithms 1.5.1 Maximum of n elements 1.5.2. Element uniqueness problem 1.5.3. Matrix multiplication 1.5.4 Linear search . +1.6 Mathematical analysis of recursive algorithms .. case efficiencies AmeImyé @ Scanned with OKEN Scanner 1.80 1.6.1 Factorial of a number . i i i! mber) 1.6.4 Fibonacci number — 1.6.5 Explicit formula to find n Fibonacei numb 1.6.6 Other problems and solutions. Chapter 2 Brute force 2.1 Introduction 2.2 Sorting ... 2.2.1 Selection so 2.2.2 Bubble sort. 2.3 Sequential search 2.4 Pattern matching UNIT-2 Chapter 3 eee Divide and conquer _3.1 General method. = 3.2 Sum of n elements of array a... AS Sorting using divide and conquer. 33.1 Merge sort 38 a 3.3.2 Quick sort 3.19 WBA Binary search., 3 3.5 Defective chess board . ‘al 3.6 Multiplication of large integer 7 Strassen’s matrix multiplicatio, Chapter 4 © Gey Teta 4.1 The general method, 2, -42Knapsack problen (AS _435F0b sequencing with deaatines . ~ SA Dijkstra’s algorithm (Single source short 4.5 Minimum spanning trees: estat "45.1 Prim’s algorithm 452. Kruskal’s algorithig wien) za @ Scanned with OKEN Scanner UNIT-4 Chapter 5 Dynamic programming 5.1 Introductioy 5.2 Fibonacci numbers 5.3 Computing binomial coefficient 4Warshal’s algorithm... $5 Floyd’s algorithm (all pairs shortest path problem) V1 Knapsack .... pel _D7 The knapsack problem using memory functions . 58 Single source shortest paths: General weigh | 59-Fravelling salesman problem(TSP) —~ GID TSP using brute force .2 TSP using dynamic programming, UNIT-5 Chapter 6 Decrease and Conquer Ue ea a 6.1.1 Decrease by a constant 6.1.2 Decrease by a constant factor. 6.1.3 Variable size decrease 6.2 Insertion sort, 6.2.1 Analysis (Bost case time efficiency), 6.2.2 Analysis (Worst case time efficiency), 62.3 Analysis (Average case time efficiency 6.3 Graph traversals. 63.1 Breadth First Search Depth First Searc 639-Tepological sorting. a 6.3.3.1 Topological sort using DES method 6.3.3.2 Topological sort usi ing source removal method @ Scanned with OKEN Scanner Space and Time Tradeoffs WW 72 7.1 Introduction. 3 7.2 Sorting by counting...... 2 7.2.1 Comparison counting. . 7.2.2 Sorting by Distribution Counting. r 13 7.3 Pattern Matching. Tas 7.3.1 Horspool’s Algorith os 73.2 Boyer More algorithm, Chapter 8 Limitations of algorithm power 8.1 Introduction ........... 8.2 Lower bound arguments cision trees.. . NP and NP — Complete problems 5 Challenges of numerical algorithms Chapter 9 Copying with limitations of algorithm Power 9.1 Backtracking, 9.1.1 Implementatior ir ) 9:12 N-Oucene prublon Perkin robles, “9.1.3 Sum of subset problem >. . 9.1.4 Hamilton ~ 9.2 Branch and bound .... “1-Knapsack problem... 2.2.2 Assignment problem. 9:23 Traveling salesperson Problem,. —/NeRINAL ANREETAN| scanned with OKEN Scanner 9.3 Approximation algorithms for NP-Hard problems. 9.3.1 Traveling salesman problem. 9.3.1.1 Nearest neighbor algorithm. 9.3.1.2 Twice-around-the-tree algorithm. /9.3.2 Knapsack problem UNIT-8 Chapter 10 SS PRAM Algorithms 10.1 Introduction. 10.2 Computational model, 10.3 Fundamental techniques and alg 10.3.1 Prefix computation. 10.3.2 List Ranking... A anval : @ Scanned with OKEN Scanner ea am conoswltgioud Arguinee of stp fo Aol te proess Chapter 1; Introduetion Whit are we studying in this chapter?. ¢ Notion of Algorithm i ¢ Review of Asymptotic Notations ¢ Mathematical Analysis of Non-Recursive ¢ Mathematical Analysis of Recursive Algorithms 1.1 Notion of Algorithm If we want to be a good computer professional, we should know how to design the algorithms. So, let us understand standard algorithms and then learn how to design new algorithms to solve various types of problems. First, we shall see “What is an algorithm?” Definition: An algorithm is defined as finite sequence of unambiguous instructions followed to accomplish a given task. Itis also defined as unambiguous, step by step procedure Gnstructions) to solve & given problem in finite number of steps by accepting a set of inputs and producing the desired output, After producing the result, the algorithm should terminate. The notion of an algorithm is pictorially represented as shown below: Input Problem —> Algorithm —> Program—! Output Observe the following activities to see how an algorithm is used to produce the desired result: * The solution to a given problem is expressed in the form of an algorithm, ¢ The algorithm is converted into a program. * The program when it is executed, accept the input and produces the desired output. Now, let us see “What are the criteria that all algorithms must satisfy?” or ‘What are the propesties oF aii algorithm?” An algorithnt must satisty the Following criteria: Lee apoE +h algorithm should have zero or more inputs. The range of inputs for which algorithm works should be satisfied NAIA) @ Scanned with OKEN Scanner 1.2 B Introduction esl e correct re The algorithm should produc ¢ Output: Definit ach instruction shot id be clear instruction jiteness: Ea i be simpl iveness: The instructions should Effectiveness : a input to the desired output. Finiteness: The algorithm m instructions. unambiguous. ol should transform the oe ite sequence t terminate after a finite seq' of ust : ammel jte the program in C or Note: By looking at the algorithm, the progr can write the pi : : ont Before riting any program, the solution ee Qf the rograrming language. writing any Prog} C++ or any of the prt has to be expressed in the form of algorithms. 1.2 Computing GCD The notion of an algorithm can be explained by computing the GCD of two numbers, Now, let us see “What is GCD of two numbers? Definition: The GCD (short form for Greatest Common Divisor) of two numbers m and n denoted by GCD(m, n) is defined as the largest integer that divides both m and "such that the remainder is zero. GCD of two numbers is defined only for positive integers put, not defined for negative integers and floating point numbers. For os GCD(10, 30) can be obtained as shown below: : 81,2, 5 and 10 a divisors of both 10 and 30 and 10 is the greatest nui and hence it is called Greatest Common Div: ‘isor, So, a 2: GED (10, 30) = 10, re common mber which is common Now, | Ow, Tet us see “What are the dit 1 GCD of e different vw, ays of Con two numbers can be compute: nputing GCD. d using various methods a Fie aca Different ws Algorithm (Using modulus) _“ulferent ways of petitive Subtraction (Eygjiqe ; computing GCD Conse igs ines a S algorithm) Middle School proce Ig " gorithm, “re Using prime factors AMETNYA) @ Scanned with OKEN Scanner I Analysis and design of algorithms 1.3 1.2.1 Euclid’s algorithm (Using modulus) nethod of finding d after mathematician method of finding the GCD of two numbers was name af a ena from Alexandria (300 B.C) and this is often called “Euclid’s algorithm to find GCD of two numbers”. ) Design iterative algorithm: The procedure to obtain GCD(6, 10) using Euclid’s algorithm is shown below: M, subtract M from N and store in N) M=4-2= i 2=2 (Since MSN, subtract N from M and Store in M Since M and N a i . nd N are same, the GCD will be either M or N which is Amemyél @ Scanned with OKEN Scanner & Analysis and design of algorithms 1.11 Now, the algorithm can be written as shown below: Example 1.8: Algorithm (represented in natural language) to compute GCD of two numbers using Buclid’s algorithm (repetitive subtraction) ALGORITHM GCD(m, n) J Description : Computes GCD(m, n) J Tnput : mand n should be +ve integers // Output : Greatest common divisor of m and n Step 1: Repeat as long as M and N are different Step 1: If M>N, subtract N from M, store result in M Step 2: If Mn) mem-n else nen-m and the above statement has to be executed as long as M and N are different, The algorithm using the pseudo code can be expressed as shown below: Example 1.9: Iterative algorithm to compute GCD of two numbers using Euclid’s algorithm ALGORITHM GCD(m, n) 1 Description : Computes GCD(m, n) / input : mand n should be +ve integers // Output : Greatest common divisor of m and n ATEMYe: @ Scanned with OKEN Scanner i id 4.2.5 To compute GCD using middle school metho e schoo! method?” Now, let us see “How to compute GCD of 60 and 120 using middl Procedure: The following steps are followed to compute GCD of 60 and 120 Step 1: Compute the prime. factors of 60. The prime factors of 60 are obtained as shown below: lo 2 [0 3s . So, the prime factors of 60 = 2.2.3.5 Step 2: Com : ipute the shown below: prime factors of 120. The prime factors f 121 : of 120 are obtain ed as 2[120 2 (60 5 So, the pri prime factors of 120-9 $2.2.23.5 ANTENA) @ Scanned with OKEN Scanner I Analysis and design of algorithms 1.13 step 3: Identify the common prime factors. The common prime factors of 60 and 120 ep 3: shown below: “ prime factors of 60 = prime factors of 120 =[2.2| 2.[3.5 Common prime factors = 2.2.3.5 = 60 0, GCD(60, 120) = 60 Using the above procedure, the algorithm can be written in natural language as shown. below: Example 1.10: Algorithm (Using natural language) to compute GCD of 2 numbers using middle school method ALGORITHM GCD(n, n) WPurpose — : To find the GCD of two numbers / Mescription : This algorithm computes the GCD of two non-negative and non-zero values accepted as parameters. /Mnput : Two non-negative and non-zero integer values m and n Output : GCD of m and n Step 1: Find the prime factors of m Step 2: Find the prime factors of n Step 3: Identify the common prime factors obtained in step 1 and step 2 Step 4: Find the product of all common factors and return the result as gcd of two given numbers End of algorithm GCD Now, let us see “What are the disadvantages of finding the gcd of two numbers using middle-school method?” The various disadvantages are shown below: ¢ The procedure is more complex and slower when compared to Euclid’s algorithm ¢ This algorithm does not specify how to generate the prime factors and hence it is not a legitimate algorithm This algorithm does not specify how to find the common factors and hence it is not possible to write the program . TAN) @ Scanned with OKEN Scanner rime factors We use sents Par 200 B.C, from erat rargsthenes- Now, let us given PY called | sieve of Br 1 ee pyatosthenes method?” pelow: = 49) and store these numbers in the assume B= ors from 2 to nj array as shown bel Hf [Generate the list of intege! sep ori= 210 dO afiJ=1 end for initiali: .s shown below: By executing the above statement, the array 4 1S initialized as 10) (1) (12) 013) a a 8) (6) el oe tPsT6T71 8191 nf 2 afl4] 15]_[16) (17) [18] a (20) (21) (22) _[23)_ (241 {25} uli 7s 20 1 21 [2 1 23 | 24 [ 25 J (26) (27) [28] (29) (30) (31) [32] (33) [34] [35] [36] [37] 26 | 27 | 28 | 29 | 30} 31 | 32 | 33 | 34 | 35 36 af38) (39) [40] [41] [42] (43) [44] [45] [46] [47] [481 [49] BsTs ToT. [a yas [46] a7 4 [49 ] Step 2.a: Now, eliminate multiples of 2 exc ae : following index positions: iples of 2 except 2. This is achieved by storing 0 in i= al4) (6) (8) [10] [12] 90000, [48]. Note: i starts from Nin steps o} [48]. Not ts from 2*2 to te f 2 The resulting array is shown below: a21_(3] [4] 3 a Uo) wu 12) [13] 0 0 3 @ Scanned with OKEN Scanner Analysis and design of algorithms.1.15 [23] (24) (25) 23 [ 0 | 25 ug] (20) (201 [22] 19 0 21 0 a(14) (15) 6) U7) [18] 0 pis [0 [17 | 0 B6)_ (37) a(26] (27) (28) [29] o [37 (0)_(31)__ [32] [331 (34]_(35) 0 [27] 0] 29 | 0 a1, o [33] 0 35 47] [48] [49] 40] (41) [42] [43] [44] [45] [46] f 8 oo 7 a 41 o_| 43 0 45 0 47 4 49 tiples of 3 except 3. This is achieved by storing 0 in Step 2.b: Now, eliminate mul following index positions: Note: Here, i starts from 3*3 ton in steps of 3 j= a{9] [12] [15] [18] [21].......a[48]. 000 0 0 0 The resulting array is shown below: af2]_ [3] [4] (5) {6) {7} (8) (9) (10) [11] (12) [13) 5 7 0 11 [2 T3 [0 0 0 0 0 | 13 af14] [15] [16] [17] [18] [19] [20] [21] [22] [23] [24] [25] ofToTot[m Tofu o fof o [23] o [2s a{26] [27] [28] [29] [30] [31] [32] {33} [34] [35] [36] [37] 0 0 0 | 29 O | 31 0 0 0 35 0 37 * af38) [39] [40] [41] [42] [43] [44} [45] [46] [47] [48] [49) o}o}otatofatotoyofa[o [a9 | Step 2.¢: After 3; the next nonzero item in the array is 5. So, eliminate multiples of 5: ire item 4 need not be considered, since its multiples are also multiples of 2 and are ready eliminated. Multiples of 5 except 5 can be eliminated by storing 0 in the following index positions: i= a{25] [30] [35] [40] [45] _ Note: Here, i s i 00 Oo ere, i starts from 5*5 to n in steps of 5 The resulting array is shown below: @ Scanned with OKEN Scanner yt) 12} 03) 11 | 0 3} (9) 0 BL I 13 BL 1, 7 To 213 os 0.7 22) (23) (241 [25] 16 1171. (18)_ 91 20) foi) (22 aa i i TLoletel o [Biel 426] 27)_(281_ 291 O_ BU p23) G4) 35] BS (371 ojo d] 2), 0] 31) Y oO 0 0 0 | 37 a(38}_ (39) (40) (41) (421 143) 44} (45]_1461_ (47) (48)_ (493 Co fe fo la} } BloloLlo lai’ 49 Step 2.d: After 5, the next nonzero item in the array is 7. So, eliminate multiples of 7. The item 6 need not be considered, since its multiples are also multiples of 2 and are already eliminated. Multiples of 7 except 7 can be eliminated by storing 0 in the following index positions: i=a[49] Note: Here, i starts from 7*7 to n in steps of 7 0 The resulting array is shown below: a2) 3) 4) 5) (6)_(7)_ 18) 19) 0) 1) 2) 3) 2 | 3 o | 5 of 7 of o oO | Wt o 13 a(l4) (15) [16] [17] (18) 19} (20) . (2 4) (25 0 0 0 17 oi i i ma rr i i Pal a(26) (27) (28) [29] [30] {31} (32) 3 0 0 ee) 0 Sh i a i a i 7 a(38) [39] [40] (41) [a2 boo Lae 86) (47) s8]_ 149 Note ini aa 7 the remaining non-zero values in the table » the prime numbers within 49 are shown below: are all prime numbers within 49- 2, 3,5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41 43, 47 Note: In the above fin: al pa: is though the multiples of Tare eee Seu 5 + <1, 28, 35, 42 oll ther numbers are already eliminated ‘hose multiples are eliminated. Eve and 49, observe that, except 49 all TEIN - @ Scanned with OKEN Scanner & Analysis and design of algo So, given the number 7, the first item to be eliminated is 49 which is ie. given the number 7, the first item to be eliminated is 77 which is In general, given the number p, the first item to be eliminated is p*p which is <= n. ie. p*p 2 Output: Prime numbers Speed of the computer Choice of the programming language Components that Compiler used affect time efficiency Choice of the algorithm Number (Size) of inputs/Outputs Since we do not have any control over speed of the computer, programmin, ig language and compiler, let us concentrate only on next two factors such as: * Choice of an algorithm ¢ Number (size) of inputs ANTETNZ! @ Scanned with OKEN Scanner tion 120 Binwoene™ e order of growth. The parame find the : algorithms use n as the parameter to it i oat of the time, thewveloe one's Note: Many ale qumber of inputs or size of inputs. aft tine te-vans ot ‘i ret al to the size of data to be processed. directly prop algorithms run longer on Tanger inputs. larger arrays and longer time to search For example it takes longer time Ot tgorithm depends on size of the input 1 i ici of an al the larger arrays. So, the time efficiency of an and ie time efficiency is always expressed in terms of n. Before proceeding further, let us see “What is basic operation?” Definition: The operation that contributes most towards the running time of the algorithm is called basic operation. A statement that executes maximum number of times in a function is also called basic operation. The number of times basic operation is executed depends on size of the input. The basic operation is the most time consuming operation in the algorithm. For example: * a statement present in the innermost loop in the algorithm * addition operation while adding two matrices, since it is present in innermost loop ¢ multiplication operation in matrix multiplication since it is present in innermost loop Now, let us see “How to compute the runing time of or How time efficiency is analyzed?" The time efficie umber of times the basic operation is executed. The an algorithm using basic operation ncy is analyzed by determining the running time T(n) is given by: T(n) = b* C(n) where . Tis the running time of the algorithm * mis the size of the input A petectton time for basic Operation, Tepres i i Present number of times the basic Operation is executed 13.1 Order of growth : Now, let us see “ , ee “WI oe ‘hat is order of growth? For wi We o: execute faster for to work Smaller valyeg Otk faster for al "AY Slow. So, the behavior ot an Ut, a8 the value I values Of n. Some algorithms algorithm ch, ” Increases, they tend to be anges wit ee Mcrease in value of n. This Ameri @ Scanned with OKEN Scanner i Analysis and design of algorithms 1.21 change in behavior of the algorithm and algorithm's efficiency can be analyzed by considering the highest order of n, The order of growth is normally determined for larger values of 7 for the following reasons: 4 The behavior of algorithm changes as the value of n increases + Inreal time applications we normally encounter large values of n For example, the order of growth with respect to two running times is shown below: 4 Suppose T(n) = c * C(n). Observe that T(n) varies linearly with increase or decrease in the value of n. In this case, the order of growth is linear. # Suppose T(n) = ¢ * C(n*). In this context, the order of growth is quadratic. Note: If the order of growth of one algorithm is linear and the order of growth of second algorithm to solve the same problem is quadratic, then it clearly indicates that running time of first algorithm is less and it is more efficient. So, while analyzing the time efficiency of an algorithm, the order of growth of n is important. Let us discuss orders of growth in the next section. The concept of order of growth can be clearly understood by considering the common computing time functions shown in table 1.1, z JogN [N [NiogN | ON? TN? [a LN : 1 0 4 0 T 1 2 it git} | s 2 1 2 2 4 8 4 2 3 & 4] 2 84 8 16 64 16 24 i OJ 3: 8 24 64 512 256 40320 & fi] a | 4 | 16 64 256 > 4096 65536 high 8 . é 32 5 32 160 1024-32768 4294967206 j very high Fig 1.1 Values of some of the functions piested comparing N (which is linear) and 2\(which is exponential) it is observed from ‘ ‘able that exponential function grows very fast even for small variation of N. ©, an algorithm with linear Tuning time is preferred over an algorithm with exponential Tunning time. The basic efficiency of asymptotic classes are shown below: ANSEIAN i @ Scanned with OKEN Scanner 1.22 B Introduction i ram is constant. Jor any constant: Indicates that running time of @ prog! pe : : is logarithmic. e i is logari : 's Indi ning time of a program. i anaes oe a larger problems by repens Lee Ya in: : ee each iteration of the loop (For example, binary ing ti is linear. So, when N is 1000, the running i inning time of a program is linear. , whe ioe we = 1000 we Wie Nis doubled, so does the running time. (For example, linear search) N log N: Indicates that running time of a program is N log N (For sek of beter. adjective, it is used as itis instead of linear, quadratic etc). The algorit ms to clements in ascending order such as quick sort, merge sort and heap sort will have this running time. (These sorting techniques are discussed in later chapters) ‘N's Indicates that runnin, will have two loops. Foi sort, addition and subtra : : : time of a program is quadratic. The algorithms normally example, sorting algorithms such as bubble sort, selection ction of two matrices have this running time. Ns Indicates that Tunning time of a program is cubic. The algorithms with running time will have three loops. For example, matrix multiplication, algorithm to solve Simultaneous equations using gauss-elimination method will have this running time, 2": Indicates that runnin ig time of an algorithm is ex Problem and algorithms that generate subsets of gi time, Ponential. The tower of Hanoi ven set will have this running NE: Indicates that running tim le of an algorithm is factorial. The al; Senerate all permutations of set t ; g gorithms that Will have this running time, Note: All the above functions can be e 7 ines lige oe e ordered According to their order of growth (from Tslogn> 2 log, n for very large value of 7 So, log, n*log, n has higher order of growth than 2 log, u Jog?n has higher order of growth than log,” So, logy’n has higher order of growth than log Solution: PART e: Given: 2! and a Q 2 ales znd 2 order J Q order 2 and 2" Since 2" is same as 2" we say that So, 2" has same order of growth as 2° vein @ Scanned with OKEN Scanner a 1.26 © Introduction Solution: PART f: Given: (oat )! and t (p-1D! and n*(n-1)! (n-1)! is less than n*(n-1)! 1 So, (n-1)! has lower order of growth than n! 1.13: For each of the following functions, indicate how much the function’s value will change if its argument is increased fourfold. a) log,n >) vn oan d) nw? e) ) 2 Solution: PART A: Given: log, n. Let f(n) = log, n Ifthe argument is increased fourfold, we get log, dn. Let g(n) = log, dn Let us express a(n) in terms of f(n). This can be done as shown below: a(n) = log, 4n = log,4+ log;n (Since log, ab= log, a+ log, b) (Substituting relation 1) Solution: PART B: Given; va. Let f(n) = Ja If the argument is increased fourfold, E 7 Latent ras , we get Jan. Let g(n)= Jan of f(n). This can be done v oe as shown below (Substituting relation 1) 'y 2 times @ Scanned with OKEN Scanner & Analysis and design of algorithms 1.27 iven: Let f(n) tion: PART C: Given: n, = frie angament is increased fourfold, we get 4n. Let g(n) = Let us express g(n) in terms of f(n). This can be done as shown belo g(a) =4n ie, kara f(n) (Substituting relation 1) So, the function’s value is increased by 4 times Solution: PART D: Given: n?. , bet fin) = mits If the argument is increased fourfold, we get (4n)?. Let g(n) = (4n) Let us express g(n) in terms of f(n). This can be done as shown below. g(n) = (4n)* =4n? = 4. fn) (Substituting relation 1) So, the function’s value is increased by 4? times Solution: PART E: Given: n?. Let {(n) If the argument is increased fourfold, we get (4n)’, Let g(n) = (4ny Letus express g(n) in terms of f(n). This ean be done as shown belo} a(n) = (4n)? =4)3 =4° fn) (Substituting relation 1) So, the function's value is increased by 4? times Solution: PART F: Given: 2", Le Ifthe argument is increased fourfold, we get 2", Let p(n) = 28 Letus express g(n) in terms of f(n). This ean be done as shown belo a(n) = 2" = 290 3 = (2") fm) (Substituting relation 1) So, the function’s value is increased by (2°) times AMET) @ Scanned with OKEN Scanner troduction “4 Asymptotic notations ing asymptotic notations. The The efficiency of the algorithm is normally sxoressca using asymp' Order of growth can be expressed using two methods: * Order of growth using asymptotic notations * Order of growth using limits Before proceeding further, let us see “What do you mean by asymptotic behavior of g function?” Definition: The value of the function may increase or decrease as the value of n increases. Based on the order of growth of n, the behavior of the function varies. Asymptotic notations are the notations using which two algorithms can be compared with Yespect to efficiency based on the order of growth of an algorithm's basic Operation, Now, let us see “What are the different types of asymptotic notations?” Th ‘yPes of asymptotic notations are shown below: he different > O(Big On) Asymptotic : notations Q(Big Omega) 8 (Big Theta) Now, let us see the informal definition and formal a 1) notations 1.4.1. Informal Definitions of YMplotic notations” 1.4.1.1 Informal Definitions of Big-On(o) Now, let us see “What is Big Oh (O) Notation?” ANREIA! ——_ @ Scanned with OKEN Scanner & Analysis and design of algorithms 1.29 n € O(n’) nw € O(n’) ne O(n’) Ex 2; Let g(n) =n’, Since n*, 0.001n‘, n*4n+3 do not have smaller order or same order as that of, they do not belong to O(g(n)) and can be represented as shown: nt € O(n’) 0.001n‘ ¢ O(n’) nen43. ¢ O(n’) 1.4.1.2 Informal Definitions of Big-Omega(Q) Now, let us see “What is big Omega (Q) notation?” Definition: Assuming n indicates the size of inj (g(a) is defined as set of functions with a larg goes to infinity. put and g(n) is a function, informally er or sume order of growth as g(n)) as n Ey 1: Let g(n) = n°. Note that n’, n*, 0.001n*, nSan+3 have larger order or same order as that of n*. Hence, they belong to Q(g(n)) and can be represented as shown: ” € Qn’) nt € Qn’) 0.001n* € Qa) w4nt3 € O(n’) Ex 2: Let g(n) = n°, Since n and n? do not hi wave larger order or same order of growth when compared to n’, we say n ¢ Qn’) we Qin) Example 1.14; Let g(n) = What is the relation between w°, ¥a(n)(n-1) and 100n + 5 using Q-notation? Solution: Itis given that g(n) = n? and we need to find the relation between: Anne VeNe @ Scanned with OKEN Scanner 1.30 B Introduction 2 ° and 2 » $a) and c) 100n45 andr ae b) ¥4(a)(a-1) and ii y : 2 m2 and Qorder oder is n same as 1 2 So, 4(n)(n-1) has same order of growth as n°. So, ) 100n45 and a? order order as wv Observe that n has lower order of growth than n°. [So, 100n+5 fore) 1.4.1.3 Informal Definitions of Big-Theta(@) Now, let us see “What is big Theta (8) notation?” Definition: Assuming n indicates the size of input a i ion, in o put and gin) is a f i) 'S defined asset of functions that have sa at pave infinity. me order of growth as g(n)) as ngs Ex: =n. eae fal a ied that antsbnte for a> 0, n2asin 1, n@4log n have same ord ©} elong to O(g(n)) and can be Tepresented as shown: anteonte © OG) ntsinn © Qin) Hone on AME @ Scanned with OKEN Scanner & Analysis and design of algorithms 1.31 Example 1.15: Use the informal definitions of O, ©, and Q to determine whether the following assertions are true or false. : a) n(n + 1)/2 € O(n) b) n(n + 1/2 € On’) o)n(n + 1/2 € OD’) @) n(n + D2 €Q(n) a) Given: n(n + 1/2 € O(n) m2 + n/2€ O(n") order J order 2 3 Since 2 has smaller order of growth than 3, we say that n(n+1)/2 € O(n’) So, the relation | n(n+1)/2 € O(n’) is true b) Given: n(n + 1/2 € Om’) 17/2 + n/2€ On?) order QV order 2 2 j ¥ Since n” has same order of growth than n’, we say that n(n+1)/2 € O(n’) So, the relation} n(n+1)/2 € O(n?) is true c) Given: n(n + 1)/2 € @(n°) 1/2 + n/2€ © (n°) order J order 2 3 ¢ evan Since n* has smaller order of growth than n°, we say that n(n+1)/2 € O(n’). But, it is given that: n(n + 1)/2 € O(n’) So, the relation | n(n+1)/2 € @(n°) is false| 4) Given: n(n + 1)/2 € Q(n) n°/2 + n/2€ Q(n) order order 2 1 ¥ Since 2 has larger order of growth than 1, we say that n(n+1)/2 € Q(n) So, the relation] n(n+1)/2 € O(n) is true AEM) @ Scanned with OKEN Scanner 132 B Introduction an 4.2. Formal Definitions of Asymptotic notation: 1.4.2.1 O (Big-Oh) eel Now, let us see “What is Big Oh (0) notation? ; Bete ben - - f(n) be the time efficiency of an algorithm. The function f(n) is said to be efinition: \ig-oh of g(n)], denoted by O(g(n)) [read as big-oh of g1 Tac ote or f(n) = O(g(n)) if and only if there exists a positive constant ¢ and positive integer ng satisfying the constraint f(n) < c*g(n) forall n2 no So, if we draw the graph f(n) and c*g(n) verses n, the graph of the function f(n) lies below the graph of c¥g(n) for sufficiently large value’of nas shown below: cg(n) Upper bound =~ fin) = f(n) $ c.g(n) for all n> ny >n i Ty Here, c.g(n) is the upper bound. The pper bound on f(a) indicates that function £(n) will pereonsume more than the specified tiie c*g(n) ie, running time of fare jon f() may. Fee Blah BUT IC WHITHEVET be work thai the upper Bowid- Soc we sey say that f(n) is generally faster than g(n) Note: Big-O is the formal method of ex Tunning time. It is a measure of the longest algorithm to complete, Pressing the upper bound of an algorithm's amount of time it could possibly take for the Note: The function g(n) is normally expressed using higher order terms of f(n). This is achieved using the following steps: Take the lower order term of fi {(n), replace the constant variable. Repeat this step, till we get the higher order 4 ¢ Once the constraint “f(n) ny" is obt with next higher order term and call it as ¢.(n). ‘dined we say {(n) € O(g(n)) @ Scanned with OKEN Scanner & Analysis and design of algorithms 1.33 syample 1.16: Let f(n) = 100n + 5. Express f(n) using big-oh solution: It is given that f(n) = 100n + 5. Replacing 5 with n (so that next higher order mis obtained), we get 100n + n and call it c.g(n) i.e. c-g(n) = 100n + n forn=5 =101n forn tert Now, the following constrain is satisfied: f() S$ c* g(n) forn2no vv v ie, 100n+5<101n forn25 no oe eee oe ie 10n?+8 <11*n? forn28 Itis clear from the above relations that ¢ = 11, g(n) = n° and no = 8. By definition, f(n) € O(g(n)) ie See ee) GE ge pa ea eee Example 1.18: Prove that every polynomial p(n) = an* + ay.in*! + ......ayn! + ag with ax > 0 belongs to O(n*). Solution: It is given that f(n) = an‘ + a,an*' + ......ain! + ao Each term in the summation is of the form ain’. Since, n is non-negative, a particular term will be negative only if a;< 0. So, etonye) @ Scanned with OKEN Scanner eA Ls aol Wf(n)1 = Vagal + ayn? + .....an! + 20 layl n+ laol 1 jue, f(n) ny where g(n) =n* and ny = 1. definition, we can write ao to) f(n) = O(n') or fin) € O(n) : f(n) = 6*2" + n°, Express f(n) using Big-Oh. Example 1.1 Solution: It is given that f(n) = 62" + n°, Replacing n° with 2" (so that next higher order term is obtained), we get 6*2" +2” and call it c.g(n) Since 2° > n°, Taking log ie., eg(n) = 6*2" +2"=72" forn>=0 isa Now, the following constraint is satisfied: which is tue for n20 fin) < ¢* g(n) forn2 no Vig aV LN. ie, 6*2"+n'<7*2" forn> 0 2and ny = 0. So, by definition, Tis clear from the above relations that = 7, gn f(a) € O(g(n)) icc., fn) € O(2' * Instead of replacing n* by 2", we could have replaced it by 2*2", 3*2",......Only thing is, the value of c and np will change, Note: Big-O notation is widely used. This is because, we normally take worst case Scenario and prepare for the worst and hope for the best. “Is there any disadvantage?” Yes, The only limitation of Big-O is that there is no lower bound for f(n) for large value of. The lower bound can be obtained using Big-Omega, @ Scanned with OKEN Scanner B Analysis and design of algorithms 1.35 —— 4.42.20 (Big-Omega) Let us see “What is Big-Q?” pefinition: Let f(n) be the time complexity of an algorithm. The function f(n) is said to be 2(g(n)) [read as big-omega of g(n)] which is denoted by fin) € Q(g(n)) or f(n) = Q(gn)) if and only if there exists a positive constant c and non-negative integer no satisfying the constraint fin) 2 c*g(n) for all n2 no. So, if we draw the graph f(n) and c*g(n) verses n, the graph of f(n) lies above the graph of gn) for sufficiently large value of n as shown below: fin) cg(n) Jower bound — 1 f(n) 2 c.g(n) for all n> no 7 n This notation gives the lower bound on a function {(n) within a constant factor. The lower__ bound on f(n) indicates that function f(n) will consume at least the specified time c*g(n) : ee Ge ag ie. the algorithm has a running time that is always gredter than c¥g(n). In general, the lower bound implies that below this time the algorithm cannot perform better Note: f(n) > c*g(n)_ indicates that g(n) is a lower bound and the running time of an algorithm is always greater than g(n). So, big-omega notation js used for finding best case time efficiency. Example 1. 00n + 5. Express f(n) using big-omega ANTETA: @ Scanned with OKEN Scanner 136 B Introduction Se Bimroduetion Solution: The constrain to be satisfied is f(n) > ¢* g(n) form vooVvy v ie, 100n+52>100n — forn>0 — Itis clear from the above relations that ¢ = 100, g(n) =n and np = 0. So, by definition fin) € Q(gin)) ie, fn) ¢ Q(n) Example 1.21: Let f(n) = 10n°45. Express fn) using Big-omega. Solution: The constrain to be satisfied is f(n) 2 ¢* g(n) forn> No voy v ie, 10n°+5 210%? forn>0 Itis clear from the above relations that = 10, g(n) =n’ and np = 0. By definition, Example 1.22: Let f(n) = 6*2" + n°, Express f(n) using Big-Omega. f(n) € Q (g{n)) ie. Solution: The constrain to be satisfied is f() 2 c* g(n) forn> Do vv v ie, 6*2"+n°2 6*2" forn> 0 tis clear from the above relations that ¢ a(n) = 2" and np = 0. By definition, fin) € Q(g(n)) ie.,| fn) € 202") 1.4.2.3 6 (Big-Theta) Let us see “What is Big-0?” Definition: Let f(n) be the ti ime complexity of be big-theta of g(n), denoted an algorithm, The function f(a) is said to {(n) € O(e(n)) or fin) = O(g(n)) @ Scanned with OKEN Scanner Analysis and design of algorithms 1.37 only if there exists some positive constants c;, cy and*non-negative. integer no ng the constraint cy*g(n) $ f(n) $c2*g(n) for alln > no. ifand satisfy! the graph f(n), c:*g(n) and c2*g(n) verses n, the graph of function f(n) lies ST aol of erat) and lies below the graph of e,?e(n) tne sufficiently large value shown below: of nas exg(n) upper bound fla) saneur uss0p cig(n) lower bound a ey*g(n) < fin) np 7 >in ‘Tis notation is used to denote both lower bound and upper bound on a function f(n) within @ constant factor. The upper bound on {(n) indicates that function f(n) will not consume more than the specified time cy*g(n).The lower bound on f(n) indicates that function {(n) in the best case will consume at least the specified time cy"g(n) Example 1.23: Let f(n) = 100n + 5. Express {(n) using big-theta Solution: The constraint to be satisfied is can) fin) $e * a(n) forn2 ny vy v vv v 100%n <100n+5 < 105*n forn> | Itis clear from the above relations that ¢; = 100, c= 105, no = 1, g(n) So, by definition fin) € O(g(n)) ie, [fn) € Om) Example 1.24: Let f(n) = 10n'+5. Express f(n) using Big-omega. S$ 10n°+n? forn? 25 lon'+5 < 11 "n° Solution: The constrain to be satisfied is ln? +5 ci*g(n)< ffm) < ©* em) forn> No vyooy vv v 10% <10n'+5 << 11*n forn>2 @ Scanned with OKEN Scanner 1.38 B Introduction =n, tt Itis clear from the above relations that ¢) = 10, c= 11, no= 2, g(n) =n". By definition, f(n) € O(g(n)) ie., f(n) € O(n°) Example 1.25: Let f(n) = 6*2" + n°, Express f(n) using Big-Omega. Solution: The constrain to be satisfied is Since 2 > n°, Taking log i.e, mlog;2 2 2logan a(n) < fn) << @*g(n) forn2m | ie. n 2 2logn gree) ” i ‘ y which is true for n20 vy v vv v 6*2 < 62 4n2<7* 2" forn20 Itis clear from the above relations that c: = 6, ¢2= 7, no = 0, a(n) = 2°, By definition, f(n) € 8(g(n)) i.e., | fm) € 0(2") 1.4.2.4 Property of asymptotic notation If an algorithm has two executable parts, the analysis of this algorithm can be obtained using the following theorem. Theorem: If fi(n)e O(g;(n)) and f2(n)€ O(g2(n)) then {)(n)+f2(n) € O(max{ gi(n), g2(n)}), Note: The same assertion is true if we replace O notation by Qor@ notations. Note: Let us consider four arbitrary numbers ay, a3, by and by. If'a; < by and ar < by, then the following simple relation holds good: a + a» 2 max{by, bs}. Let us use the above fact in proving this theorem, proot By definition, we know that the function {(n) is said to be big-oh of gin), denoted ny f(n) € O(g(n)) such that there exists a Positive constant c and positive integer no satisfying the constraint f(n) $c¥g(n) for all n> ny. Itis given that fy(n) € O( g:(n) ). So, by definition, there exists a relation fi) Ser* gi(n) forn> ny - It is given that fa(n) € O( go(n) ). So, by definition, there exists fx(n) $c * go(n) for n> ny, arelation @ Scanned with OKEN Scanner & Analysis and design of algorithms 1.39 3) Totus assume cs = max{cy, ca) andn = max{n), na} — ig equation (1) and equation (2) we have, f\(n) + fen) Ser * gi(n) + c2 * ga(n) Sc3* gi(n) +c; * ga(n) Ses [gi(n) + go(n)) Sy 2*max{gi(n),ga(n)} py addin, since, fi(n) + f2(n) $ cs 2*max{ gi(n),ga(n)}, by definition we can write f,(n) + f2(n) ¢ O(max{ gi(n), ga(n) } where ¢ = 2cs = 2max{c}, 2) and ng = max{n}, np). Hence, the proof. Note: It is clear from the above property that, the overall efficiency of the algorithm is determined by the executable part which has larger order of growth. Example 1.26: Find the time complexity of an algorithm which has two parts: ¢ sorting part requiring Yan(n-1) comp: 4 Tocheck consecutive elements requiring n comparisons Part 1: The sorting algorithm in the worst case uses ¥4n(n-1) comparisons. So, the time complexity of sorting part is O(n*). Part 2: The algorithm to check whether consecutive elements are present or not, requires no more than (n-1) comparisons. So, the time complexity of the second part is given by O(n). We know from the property of asymptotic notations that if fi(n) € O(gi(n)) and f2(n) € O(g2(n)} thea f,(n) + f(n} € O(max { gi(n), g2(n)}). According to this property, the time complexity of entire algorithm is given by O(max{n?, n} 1.4.3 Order of growth using limits Instead of using asymptotic notations, the order of growth can be obtained by computing the limit of the ratio of the two functions as shown below: si gases @ Scanned with OKEN Scanner 1.40 B Introduction 0 imply f(n) has smaller order of growth than g(n)ie., flr) € O(g(n)) = +c imply f(n) has same order of growth than g(n) i.e., Sin) € A(g(n)) co imply f(n) has a larger order of growth than gin)ie., flr) € 2g(n)) Note: To compute the order of growth, the limit-based approach = often convenient because, it is more advantage to use powerful calculus techniques such as: £0) im gin) gin) # L'Hospitals’s rule defined by Sterling’s’ formula which is given by a!=/2xn (2) for very large values of n. Example 1.27: Compare the orders of growth | ,,¢, 1) and n? using limits 2 Solution: Given fiy=5n (n-1)and g(n) = n?. We can find the limit of ratio of function f(n) and g(n)as shown below: Lin) 50-1 Tim Jim fk ee ie 1 2 2 2 Since the limit is a Positive const: ‘ant, both the functi 7 of growth (second condition hold Thin cons 1) and g(n) have the same order S good) and itis symbolically represented as: TEMA @ Scanned with OKEN Scanner & Analysis and design of algorithms 1.41 Example 1.28: Compare the orders of growth of log,n and Jy mf” . “ gn) =lim log, e(log, m) ae ey (n) im (108 (log, J =k gn) gy HE (log,n) = derivative of (log, n ‘ \ (vn) = derivative of J? can be obtained as shown below: Note: derivative of x” = n.x™! LP)G)_ 2 2 1 2a Substituting equations (2) and (3) in equation (1) we have, 1 f(r) fm) Pea Fim 2) jig LO) _ 7 gn) ne gi(ny ~!82e| lim—F Wn Tei) @ Scanned with OKEN Scanner 1.42 2 Introduction vim =log,e| Jim 7 w2hn{ iat 0 =log,” has Since the limit is equal to 0, the first condition holds good and f(n)=log, ” has a ically, iti das shown smaller order of growth than g(n) =n and symbolically, itis represented as show, below: v.ne on Example 1.29: Compare the orders of growth of nf and 2 Solution: Given that ffm) = n/ and g(n) = 2" we can find the limits as shown below: Vimn{ : Sins nl €} using Sterling's formula Jim = tim = = tim — gin) een Since the third condition is satisfied, ic, jin! gan» SYbolically it is represented as a im: Note: It is clear from above example that n! has lary £rOWs very fast, n! still grows f ‘ger order of growth than 2°. So, as 2 ‘aster. But, it is not evident from formal i definition of OQ, 1.4.4 Problems on asymptotic notations Now, let us solve various problems on asymptotic notations Nm @ Scanned with OKEN Scanner Analysis and design of algorithms 1.43 sample 1.30: Prove that 3n? + 2n? = O(a?) solution: Itis given that f(n) = 3n? + 2n°. Replacing 2 with n (so that next higher order term is obtained), we get 3n’ + n*n? and call it ¢.g(n) i.e., ¢.g(n) = 3n? + n*n? for n= 2 =4n forn=2 Now, the following constrain is satisfied: f(n) < c*g(n) forn2 no v_Y, v 4*n forn22 a2 grt ®) logy n Wanye @ Scanned with OKEN Scanner 4.44 G Introduction Solution: part A: Given + Dee iene @(n”). So, (n+ ne On) Informally, (r+) Assertion: Let fn) = (n° + 1)"° and g(n) = al)” | inl ain a - ("3") So, tint = el ie: nl = = c(constant). = gi By definition, f(n) € @(g{n)). So,} (a" + 1)"€ @(n*®) is proved. Solution: part B: Given yl0n? + 7n + 3 Informally, Ji0n? + 7n + 3 = Vl0n? = VJ0n € O(n). So, | fi0n? + 7n + 3 € O(n) Assertion: Let f(n)=V10n? + 7n +3 g(n) =n 7 Jim £0 = jim Yin? + Tn + 3 ee n + Slim [+ 7 + 3 — 7 0 slim tow2 43 iG iid non So, tin 9 ie, mL - By definition, ft) € (ea), Se Solution: part e: Given: 2nig(n + 2) 4 (n+ ayig® ye 5 @ Scanned with OKEN Scanner & Analysis and design of algorithms 1.45 Informally, 2nig(n + 2) + (n + 2)'Ig 7 = 2n2ig(n + 2)+ (n + 2) (lgen—lg2) = 4nig(n + 2)+ (n + 2) (Ign—1) ol) =n Ig(n)+ n° Ign (For aconstant multiple when n is very large =m Ign so, |2nig(n + 2) + (n +2) Ig : € O(n Ig n) : Let fin) = 2nig(n + 2) + (n + 2) BS and g(n) =n? gn fo) ine + 2+ (n+ aye S PS (acetyl nign Replacing numerator by eq(1) we have Ig(n +2 ee i tim LO) jn S18 + 2)4 (n + 2) (Isn—1) me g(n) Hae 4nig(n + 2 2 (len- a tim ABO * 2) 5p 2 + 2) (ent) = mignon) 1 a(n +2 ‘| = 4 tim 8 * 2) 4 ion tim tant me omgn ee = nigh Ie(n +2 2 1 = 4 tim OF 2) 4 ig +4n+4yiph 3M sand se onign ia aaa Ee P +4 a =i tt geen eee agree 2 4 = 0 4) tire 7 . fn a ow(nlgn ign alga = 0 i ; : = 1 (constant) Pony @ Scanned with OKEN Scanner 146 B Introduction £0). constant BY definition, fin) € O(g(n)) since Hii Pig a € O(n’ Ign) git gant 3" 7 informally, 2 #37 =2 42456 0(2 )#06")=06 So, | 243°! € 9G") = ae Assertion: Let f(n) = 2°" +3 " and g(n) = 3 3 eget oe £0 tg? 25 tin Fim gq) ee Fe 22" " elim lim ae Diy al sii + lim— i 3" 3 =o4t-! 33 fin) 1 fm) So, lim ~~ = = i.e, lim—— = a 0, aa ie. Lae ¢ (constant), By definition, fin) € @(g(n)). So, ]2! 43" € O(3") is prove Solution: part e: Given: logyn ‘e. | logon € O(log n) | By neglecting the constant Assertion: Let f(n) = logan and g(n) = lo; gn fim £20820 _ 08 8(n) = logn “log n We know that o eons 8" ie 2° By Substituting in above equation, we get @ Scanned with OKEN Scanner & Analysis and design of algorithms 1.47 Gy el | loon : mm gin) "log, 2 log n "log. time = constant, by definition, f(n) € O(a(n). So, [login € Ollozm) Example 1.33: a) The values of Several functions that often arise in analysis of algorithms such as log n,n, n log n, n°, n°. 2", n! ave listed in increasing order of their order of growth. Do these values prove this fact with mathematical certainty? b) Prove thatthe functions are indeed listed in increasing order of their order of growth, Solution: Part A: The order of growth and the related notations O, Q, and © deal with the asymptotic behavior of functions as » goes to infinity ice., practically for very large value of n. Therefore no specific values of functions within a finite range of n's values, can establish their orders of growth with mathematical certainty. So, the above facts cannot be proved with mathematical certainty for a finite range of n’s values, Solution: Part B: We can prove that the functions: 3 on > 2%, nt logn, n, nlogn, n°, are listed in increasing order of their order of growth for very large value of n as shown below: Case 1: log n and in Note: log n= logy n So, consider lim Am on Since log, b = log, a (log.n\ @ Scanned with OKEN Scanner a =log, elim Case 2: nand nog n . n So, consider lim—>—= m= n*logn se3: mlognandn” nélogn _ So, consider li om Case 4: n? and n° $0,261 secsseeeeall Case 5: . So, consider lim = im (According AmeRWz @ Scanned with OKEN Scanner Analysis and design of algorithms 1.49 2n =—Slim wees Ig2 lim" (According to LMosp “ar @ Case 6:2" and nt Consider Thus, using the relations from (1) to (6) we have proved that Te a aah logn< n< nlogn 0 belongs to O(n), Solution: It is given that p(n) = an’ + aan! 4, prove that f(n) belongs to @(n') we + a, With ay > 0. It is Tequired to So,letus compute: tim LO — jy PO) mm on) mea A an’ + = lim : a =lim| a, +t me if =4, (a constant) imply f(n) has same order of growth than g(n) ie, fn) © 6 (x(n) by asymptotic definition using limits ie. p(n) € 8(0') using relation (1) So] p(n) = ant + ay ny, oo tay € O(n") Example 1.36: Prove that exponean 36: Mt exponential functions a" have dirt tders of gr¢ Sifeean vanes of oe oe have different orders of growth for @ Scanned with OKEN Scanner & Analysis and design of algorithms 1.51 ion: Consider the two functions a and a3. To see that they have different orders Soluth fr different values of base a> 0, let us compute: of 3! f hen tim Case 1:lf a, a,, then lim={ =, Accor ding to asymptotic definition using limits, this mq (2) imply that fin) € Q(gin)) ie, ale O@)efee eet Sy Sad By observing relations in case 1, case 2 and it is proved that exponential functions have different orders of growth for different values of base a> 0. Example 1.37:Show that 5x? is On’) Solution: Itis given that f(x) = 5x2 yal @ Scanned with OKEN Scanner 1.52 B Introduction Ofg(w). By definition, if f(x) ere ® Siz! 1.2)42.2° 43.2 +1022" =(n=12!" 42 9) Yilog i= mlogn Faample 1.38: Find the sum of the series: 1434547 # cs 999 Given: 1+34+5+7+....... 999 214243 te.80. 1000-[24+4+4+648...... 1000} oo 0*1001 300*501 OOOO Tae ) =2,50,000 ae Sa) Example 1.39: Find the sum of the series: 244484 164.........1024 Given: 2+4+8+416+......... 1024 Example 1.41; Simplity: Y° Amennyé) @ Scanned with OKEN Scanner 1540 Introduction (n-1int 4) 2 nf (By taking the constant n(neiy 4 Example 1.43: Simply. yor Given: 33! = yy 2 y33) el aaEINVA @ Scanned with OKEN Scanner Analysis and design of algorithms 1.55 a(-1)_,3@"-1) 9 oy Example 1.44: Simplify: 3 ii+1) P +i) i e Given: Yii+D= ste form y nan? = Mn+ D241) a 6 ‘ ait) 2 So, 1.5 Mathematical analysis of Non-reeursive algorithms Now, let us see “What is the general plan of analyzing non-recursive algorithms?” The 8eneral plan of analyzing non-recursive algorithms is shown below: * Based on the size of input, determine the number of parameters to be considered, * Identify the basic operation in the algorithm, * Check whether the number of tim the size of the input. If the b: Conditions, then it is neces: Separately, nes the basic oper: asic oper ary ‘ation is executed depends only on ‘ition to be executed depends on some other to obtain the worst case, best ¢ asi und average case Naina) @ Scanned with OKEN Scanner

You might also like