98
SEERLOGICA INFOTECH SeerLogica Infotech Private Limited, #3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam, Ameer Pet, Hyderabad-38. Http://www.seerlogica.com 1 BY

C & DS At a Glance

Embed Size (px)

DESCRIPTION

C & DS At a Glance

Citation preview

SEERLOGICA INFOTECH SeerLogica Infotech Private Limited, #3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam, Ameer Pet, Hyderabad-38. Http://www.seerlogica.com 1

BY SEERLOGICA INFOTECH SeerLogica Infotech Private Limited, #3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam, Ameer Pet, Hyderabad-38. Http://www.seerlogica.com 2Algorithm:- Step by step representation to performing any task is called algorithm. Algorithm & flowchart for making a tea: Begin 1.Boil water. 2.Put tea power in the kettle. 3.Pour boiled water in the kettle. 4.Wait for three minutes. 5.Boil milk. Put boiled milk in a cup. 6.Add sugar to the cup. 7.Empty the kettle in the cup. 8.Stir the cup with a spoon. End Put tea power in the kettle Pour boiled water in the kettle Wait for 3 minutes Boil milk Put boiled milk in a cup Add sugar to the cup Empty the kettle Stir the cup with a spoon End Boil Water Begin SEERLOGICA INFOTECH SeerLogica Infotech Private Limited, #3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam, Ameer Pet, Hyderabad-38. Http://www.seerlogica.com 3Steps to write an algorithm:It is thestep by step method of performing any task. Whenwe breakup a big task into smaller steps what we actually do is to create an algorithm. The steps in an algorithm can be divided in three basic categories. They are 1.Sequence 2.Selection 3.Iteration Sequence:A Sequence is a series of steps that we can follow in any algorithm without any break i.e., Unconditionally. Selection:Selection involves makes a choice from multiple, available options. A selection statement generally takes the form of 1.If 2.Then 3.End-if Eg: 1.If the guest wants tea. 2.Then give him tea. 3. Offer biscuits. 4.End-if

BeginBegin 1.If the guest wants tea1. If the guest wants tea 2. Then make tea.2.Then make tea; 3.End-if3.offer biscuits 4.Offer biscuits4. End-if End. End Offer biscuits to all guests Offer biscuits only to guests who want tea Begin 2.Take a utensil. 3.Take the utensil to the water tap. 4.Open the tap. 5.Fill the utensil with water. 6.Close the tap. 7.Put the utensil on the gas or in the oven. 8.Start the gas or the oven. 9.Wait until the water boils. 10. Switch off the gas or the oven. End SEERLOGICA INFOTECH SeerLogica Infotech Private Limited, #3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam, Ameer Pet, Hyderabad-38. Http://www.seerlogica.com 4I.Compound conditions:We combine two or more conditions in to a single compound condition (using the words like and and/or or to join sentences. 1. Compound conditions with and: 1.If it is a weekday 2.and it is 7 am or more 3. and you are feeling ok 4.Then 5.Take breakfast 6. Go to work 7.End-if 2. Compound conditions with or: 1.If it is a weekday 2.or work is pending 3.or boss is angry 4.Then 5. Take breakfast 6. Go to work 7.End-if II. Nested condition:-Putting a if with in another if forms a nested condition. Eg 1. 1.If you are feeling ok 2.Then go to work 3.Else 4.If you have fever 5.Then go to the doctor 6. Else 7.Just relax 8. End-if 9.End-if Eg 2. 1.If a>b 2.Then If a>c 3.Then choose a 4. Else choose c 5. End-if6.Else if b>c 7.Then choose b 8.Elsechoose a 9. End-if 10.End-if Selecting the largest of three numbers using nested conditions SEERLOGICA INFOTECH SeerLogica Infotech Private Limited, #3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam, Ameer Pet, Hyderabad-38. Http://www.seerlogica.com 5 III Testing and debugging:We are checking to see if our algorithm gives the desired result, Hence we testing the algorithm. A set of values of a, b and c that we use for testing (e.g. a=18, b=24,c=49) is called as a test case as we test our algorithm for a possibility (or case) at a given time. A group of test cases makes up the test data. If for any one of such conditions, our algorithm gives an incorrect result, we say that isa bug in the algorithm-itis anothername for anerror. The process of removinga bug from an algorithm is called as debugging. IV Indentation and Algorithm maintenance:For every if statement there is a end-if statement, for every Begin statement there is anendstatement,writingend-ifisexactlybelowif,endisexactlybelowbegin&start somesentencesatbeginningandsomeafterleavingsomespacesiscalledindentation. Writing algorithms in indentation is very easy to understand & make changes very easily. Writing the algorithms in indented form is called good maintenance of algorithms. Iteration: A sequence of steps which are used repeatedly is called iteration. (a)1.Repeat(b)1.Do(c) 1.While I do not arrive 2. Wait for two minutes.2. Wait for two minutes.2. Wait for two minutes. 3.Until I arrive3.While I do not arrive3.End-while 4. Go to Movie4.Go to Movie4.Go to Movie Repeat-Until&Do-While(casesa&b)areessentially,firstitdothestepsthen check for the condition, While- End while(case) is differ from above, Because first checks the condition then do the steps. Type casting: Type conversion int i,j; float k; k = (float) i / j

(float)i is called type casting(we are converting integer to float) (float) i / j i is float, j is automatically converts into float (from int) This is called type conversion. SEERLOGICA INFOTECH SeerLogica Infotech Private Limited, #3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam, Ameer Pet, Hyderabad-38. Http://www.seerlogica.com 6 Flowchart:- Representation of algorithm in graphical form is called Flowchart. Flowchart Symbols & its uses S. NO SymbolsNamePurposeUsage of symbol in flowchart 1.Rounded Rectangle TerminalIt is used to start and stop

2. ParallelogramData It is used for input oroutput data 3.RectangleProcess It is used to process thedata 4.Rhombus Decision It is used to give condition

5.Arrows Flow of controlIt is used to give flow ofgiven data 6.Hexagon Preparation It is used for loops likeFor, While, Do While 7.CircleConnector It is used for connectinglines 8. Crossed Circle Summing JunctionIt is used for junctions 9.- - - - - - Dotted LinesFlow of data It is used to give Flow of data in loops 10.Double Sided RectanglePredefined ProcessIt is used for Predefinedprocess like Macros

SEERLOGICA INFOTECH SeerLogica Infotech Private Limited, #3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam, Ameer Pet, Hyderabad-38. Http://www.seerlogica.com 7System Ready Enter ProgramProgram Code Edit Source Program CompileSource Program CCompiler Syntax Errors ? Link withSystem Library System Library Execute Object Code Input Data Logic and Data Errors? CORRECT OUTPUT Stop Flowchart for Process of Compiling & Running a C Program

Source Program (.C)

Yes No Object Code (.OBJ) Executable Object Code (.EXE) Data ErrorLogic Error No Errors SEERLOGICA INFOTECH SeerLogica Infotech Private Limited, #3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam, Ameer Pet, Hyderabad-38. Http://www.seerlogica.com 8 C Tokens Tokens Keywords Identifiers Constants StringsOperators Special Symbols (Reserved words) int, iffact, avgabc, A +,^ {, # Numeric Character IntegerReal SingleMulti CharacterCharacter 1.05, 2.4e2A, 1ABC,$123 Decimal Binary Octal Hexa Decimal (0-9) (0,1) (0-7)(0-9, A-F) 89, 18701, 110 05, 0171A, FF Data Types Data Types User definedDerivedPrimary (fundamental)Empty typedef, enum Structure, unionnull

IntegersReal NumbersCharacters

int long short float double long doublechar Data TypeSize(bytes)Size(bits)RangeRange (in 2 power) int216-32,768 to 32,767-215to215-1 signed int 216-32,768 to 32,767-215to215-1 unsigned int2160 to 65,5350to 216-1 long432-2,147,483,648 to 2,147,483,647-231 to231-1 signed long 432-2,147,483,648 to 2,147,483,647-231 to231-1 unsigned long432 0 to 4,294,967,2950to 232-1 short18-128 to 127-27to27-1 signed long 18-128 to 127-27to27-1 unsigned long180to 2550to 28-1 float4323.4E-38 to3.4E+38 double8641.7E-308 to1.7E+308 long double10803.4E-4932to1.1E+4932 char18-128 to 127-27to27-1 signed char 18-128 to 127-27to27-1 unsigned char180to 2550to 28-1 SEERLOGICA INFOTECH SeerLogica Infotech Private Limited, #3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam, Ameer Pet, Hyderabad-38. Http://www.seerlogica.com 9Operators 1.Arithmetic operators (+, -, *, /, %) 2.Relational Operators (=, ==, !=) 3.Logical Operators (&&, ||, !) 4.Assignment Operator (=) (a=a+b =>a+=b Shorthand notation) 5.Increment/Decrement Operators (++, --) (a++, a-- => Post & ++a, a++ Pre) 6.Bitwise Operators (&, |, ^, >>, b ? a+b : a-b) 8.Special Operators (,(comma),sizeof()) Truth Tables Logical Operators Logical AND Logical OR ABA&&B 000 0non zero0 non zero00 non zeronon zero1 Logical NOT Bitwise Operators Bitwise AND Bitwise OR Bitwise Ex-OR Bitwise NOT A^B=AB+ABOnes Complement ABA||B 000 0non zero1 non zero01 non zeronon zero1 A!A 01 non zero0 ABA&B 000 010 100 111 ABA|B 000 011 101 111 ABA^B 000 011 101 110 A~A 01 10 SEERLOGICA INFOTECH SeerLogica Infotech Private Limited, #3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam, Ameer Pet, Hyderabad-38. Http://www.seerlogica.com 10Operator Precedence & Associativity OperatorDescriptionAssociativityRank () [] Function Call Array element reference Left to right1 + - ++ -- ! ~ * & Sizeof (type) Unary Plus Unary minus Increment Decrement Logical negation (Logical not) Ones compliment (Bitwise not) Pointer reference (indirection) Address Size of an object Type cast (conversion) Right to left2 * / % Multiplication Division Modulus Left to right3 + - Addition Subtraction Left to right4 > Left shift Right shift Left to right5 < >= Less than Less than or equal to Greater than Greater than or equal to Left to right6 == != Equality (Relational equal to) Inequality (Relational not equal to) Left to right7 &Bitwise ANDLeft to right8 ^Bitwise EX-ORLeft to right9 |Bitwise ORLeft to right10 &&Logical ANDLeft to right11 ||Logical ORLeft to right12 ? :Conditional Operator (Conditional expression)Right to left13 = *=/= %=+=-= &= ^=|= = Assignment operatorsRight to left14 ,Comma operatorLeft to right15 SEERLOGICA INFOTECH SeerLogica Infotech Private Limited, #3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam, Ameer Pet, Hyderabad-38. Http://www.seerlogica.com 11Input Formats Integer Numbers: int a,b,c,x,y,p,q,r; printf(Enter three integer numbers); scanf(%d %*d %d,&a,&b,&c);123 printf(%d %d %d,a,b,c);13-3577 printf(Enter 2 4-digit numbers); scanf(%2d %4d,&x,&y);67894321 printf(%d %d,x,y);6789 printf(Enter 2 2-digit numbers); scanf(%d %d,&a,&x);4466 printf(%d %d,a,x);432144 printf(Enter 9-digit number); scanf(%3d %4d %3d&p,&q,&r);123456789 printf(%d %d %d,p,q,r);661234567 printf(Enter 2 3-digit numbers); scanf(%d %d,&x,&y);123456 printf(%d %d,x,y);89123 Real Numbers: float x,y; double p,q; printf(Enter two values); scanf(%f %e,&x,&y);12.345617.5e-2 printf(%f %f,x,y);12.3456000.175000 scanf(%lf %lf,&p,&q);4.14285714285718.5678901234567890 printf(%lf %e,&p,&q);4.1428571428571.856789012346e+001 Strings: char name1[15],name2[15],name3[15],char address[80]; printf(Enter a name); scanf(%15c,name1);123456789012345 printf(%15s,name1);123456789012345r printf(Enter a name); scanf(%s,name2);New Yorkprintf(%15s,name2);New printf(Enter a name); scanf(%15s,name1);London printf(%s,name1);York printf(Enter a name); scanf(%15c,name1);123456789012 printf(%15s,name1);123456789012r printf(Enter a name); scanf(%s,name2);New-Yorkprintf(%15s,name2);New-York printf(Enter a name); scanf(%15s,name1);London printf(%s,name1);London printf(Enter address); scanf(%[a-z],address);new delhi 110002 (It accepts a to z values) printf(%s,address);new delhi scanf(%[^\n],address);new delhi 110002 (It accepts up to new line) printf(%s,address);new delhi 110002 SEERLOGICA INFOTECH SeerLogica Infotech Private Limited, #3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam, Ameer Pet, Hyderabad-38. Http://www.seerlogica.com 12Output Formats Integer Numbers: int m=12345; long n=987654 printf(%d,m); printf(%10d,m); printf(%010d,m); printf(%-10d,m); printf(%3d,m); printf(%-3d,m); printf(%d,-m); - printf(%10d,-m); printf(%3d,-m);-printf(%10d,n); Real Numbers: float y=98.7654 printf(%f,y); printf(%7.4f,y); printf(%7.2f,y); printf(%-7.2f,y); printf(%*.*f,7,2,y); rintf(%07.2f,y); printf(%10.2e,y); printf(%12.4e,y);printf(%-10.2e,y); printf(%e,y); printf(%f,-y); -- Strings: char x=A; char name[20]=ANIL KUMAR GUPTA; printf(%s, name); printf(%20s,name); printf(%20.10s,name); printf(%-20.10s,name); printf(%.5,name); printf(%5s,name); 12345 12345 1234500000 12345 12345 12345 12345 12345- 12345 876549 540498.76 5498.76 98.77 7798. 7798. 770098. e+0019.88 +0019.88e 65e+09.8701 540498.76 KUMARANILAGUPT NILKAGUPTAUMAR KUMARANIL KUMARANIL ANIL KUMARANILAGUPT 54e+0 9.87601 SEERLOGICA INFOTECH SeerLogica Infotech Private Limited, #3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam, Ameer Pet, Hyderabad-38. Http://www.seerlogica.com 13Statement 1 Statement 2 is condition 2 Decision Making & branching Decision Making & branching ifswitch gotoConditional Operator (Combination of? :=>c= a>b ? a+b : a-b) simple ifif- else nested ifif-else ladder Syntax of if statement: if (Condition)TrueTrue { Statement 1; Statement 2; } if (Condition)True Statement 1; Syntax of if-else statement: if (Condition) {True Statement 1; Statement 2; false }else { Statement 3; Statement 4; } Syntax of nested if statement: if (Condition 1)True { if (Condition 1) {Statement 1;True Statement 2; } else { False Statement 3; Statement 4; } } is condition Statement 1 Statement 2 is condition Statement 1 is condition Statement 1 Statement 2 Statement 3 Statement 4 is condition 1 Statement 3 Statement 4 SEERLOGICA INFOTECH SeerLogica Infotech Private Limited, #3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam, Ameer Pet, Hyderabad-38. Http://www.seerlogica.com 14is condition 1 Statement 1 is condition 2 Statement 2 is condition 3 Statement 3 Statement 4 Syntax of if-else ladder statement:Syntax of switch statement: if (Condition 1) switch(expression) {{ Statement 1;case 1:statement 1; }break; else if (Condition 2) case 2:statement 2; {break; Statement 2;case 3:statement 3; } break; else if (Condition 3) case 4:statement 4; {break; Statement 3; default:statement 5; } else} { Statement 4; } False TrueFalse True False True Syntax of goto statement: main() { double x, y; read: scanf(%lf,&x); if(XHASHFUNCTION------------>ADDRESS There are many different hashing functions which can be devised. The following some methods are used for hashing functions. DIVISION-REMINDER METHOD: - Mainly this method is used for the founding the key value of or the location of the hash function. For this we remember the some formula i.e.==> HASH (KEY)=KEY mod P WHERE; Hash(key)isthehashfunction.KEY'isthetargetelementto besearchedand'P'is some integer preferably a PRIME NUMBER. The Operator mod gives the remainder value after division. This gives the address of theelementsinthelook-up-tableintherange0top-1.Andthatsizeofhashtableisatleast'P'. For Example: If P=11 and key =4536 SEERLOGICA INFOTECH SeerLogica Infotech Private Limited, #3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam, Ameer Pet, Hyderabad-38. Http://www.seerlogica.com 60 then HAS(4536)=4536 mod 11 =4 Thus; The element with the key 4536 is mapped to the table, location address(index) is '4'. In this division -Reminder method, we find the index value (or) key of Hash table by using the range of Prime factors. That gives the index or key value of hash function. MIDDLE SQUARE METHOD:- In this middle square method, the address is computerized by squaring the key element and selecting an appropriate number of bits from the middle of squared number. Thenumberofbitsselectedtoobtaintheaddressdependsonthetablesize.Forall elements the same bit positions must be used. Example:- Suppose the key is 352, And squaring it we get 123904. The meaning of Hash is independent of the size of the space being searched. Frequently, an application will need to search a key item for a Collection of items or records. Hashing techniques transform the search key item into address of that item in the table. Ifthehashtablerequiresfourdigitsaddressthen selectbitsfrom2nd digitsto5thdigits resulting 2390. Inthismethod,wefindthekeyelement'x'thensquaringitandlefttheplacesonedigit from left end and other digit from right end. This gives the resulting of the kth element of hashing. This method takes the lot of computations and time taking process. This is the disadvantage of Middle square method. So, we will go for another method. FOLDING METHOD:- This, method divides the given key into parts based on the number of bits required for the address. Summing all the parts, omitting the carry, if any will result the address. Suppose, the key element is 5647832 and the number of address digits required is '3'.The '3' digit parts of the key namely 564,783, and 2 are added. Then, give the result is; Which results the address is 344. One,ofthemainproblems,inHashingisthatformanykeysthehashfunctionmay produce same address. Finding a PERFECT HASH FUNCTION is always is not correct. For Example:- Suppose, we can find a hash function H(K),which maps most of the Keys onto unique integers, but maps a small number of keys as same integer. This situation is said to be COLLISION. SEERLOGICA INFOTECH SeerLogica Infotech Private Limited, #3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam, Ameer Pet, Hyderabad-38. Http://www.seerlogica.com 61Analysis of Algorithms Definition: - The method of solving a problem is known as an algorithm. It is a sequence of instructions that act on some input data to produce some output in a finite number of steps. Properties:- a) Input: An algorithm must receive some input data supplied externally. b) Output: An algorithm must produce atleast one output as the result. c) Finiteness: The algorithm must terminate after a finite number of steps. d) Definiteness: The steps to be performed in the algorithm must be clear and unambiguous. e)Effectiveness:Onemustbeabletoperformthestepsinthealgorithmwithoutapplyingany intelligence. All algorithms basically fall under two broad categories-Iterative and Recursive algorithms. Iterative Algorithms typically use loops and conditional statements. RecursiveAlgorithmsuseadivideandConquerstrategy.Asperthis,therecursivealgorithm breaksdownalargeproblemintosmallpiecesandthenappliesthealgorithmtoeachofthese smallpieces.Determiningwhichalgorithmisefficientthantheotherinvolvesanalysisof algorithms. While analyzing, time required to execute it determined .time represents the number of operations that are carried out while executing the algorithm. Whileanalyzingiterativealgorithmsweneedtodeterminehowmanytimestheloopis executed. To analyze a recursive algorithm one needs to determine amount of work done for three things: i. breaking down the large problem to smaller pieces. ii. Getting solution for each piece and combining the individual solutions to get the solution to the whole problem. iii. Combining this information and the number of the smaller pieces and their sizes, we then need to create a recurrence relation for the algorithm. Analysis:-The analysis of an algorithm provides information that gives us a general idea of how long an algorithm will take for solving a problem. For comparing the performance of two algorithms we have to estimate the time taken to solve a problem using each algorithm for a set of N input values. Analysis of algorithms gives us the scientific reason to determine which algorithm should be chosen to solve the problem. The purpose of determining the number of comparisons is to then use themtofigureoutwhichofthealgorithmsunderconsiderationcansolvetheproblemmore efficiently. What Analysis Does nt Do:- Theanalysisofalgorithmsdoesnotgiveaformulathathelpsusdeterminehowmany secondsorcomputercyclesaparticularalgorithmwilltaketosolveaproblem.Theanalysisof algorithmshouldbedoneregardlessofthecomputeronwhichtheprogramthatimplementsthe algorithm is going to get executed. Things to Count and Consider:- i. The significant operation or operations in the algorithm must be identified first. ii. Operationsintegral to the algorithm and which merely contribute to the overheads should be determined next. Comparisonorarithmeticaretwoclassesofoperationsthattypicallychosenforthe significant operation. Cases To Consider During Analysis:- Multiple input sets must be considered while analyzing an algorithm. a) Best Case Input:- This represents the input set that allows an algorithm to perform most quickly with this input the algorithm takes shortest time to execute, as itcauses the algorithms to do the least amount of work. No matter how large is the input, searching in a best case will result in a constant time of 1. Since the best case for an algorithm would usually be very small and frequently constant value, a best case analysis is often not done. SEERLOGICA INFOTECH SeerLogica Infotech Private Limited, #3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam, Ameer Pet, Hyderabad-38. Http://www.seerlogica.com 62 b) Worst Case Input: This represents the input set that allows an algorithm to perform more slowly.Worst case is animportantanalysisbecauseitgivesusanideaofthemosttimeanalgorithmwillevertake. Worstcaseanalysisrequiresthatweidentifytheinputvaluesthatcauseanalgorithmtodethe most work. c) Average Case Input: Thisrepresentstheinputserthatallowsanalgorithmtodeliveranaverageperformance. Doing average case analysis is a four step process. These steps are as follows: i. Determine the number of different groups into which all possible input sets can be divided. ii.Determinetheprobabilitythattheinputwillcomefromeachofthesegroups. iii. Determinehow long the algorithm will run for each of thesegroups. All of theinputin eachgroup should take the same amount of time, and if they do not, thegroup must be splitinto separate groups. Calculate average case time using the formula: m A(n)=pi*ti where i=1 n=size of input m=number of groups pi=probability that the input will be from group i ti= time that the algorithm takes for input from group i. Rates Of Growth:- Whiledoinganalysisofalgorithmwemustconsiderwhathappenswhenthesizeofthe input is large, because small input sets can hide rather dramatic differences. Algorithmscanbegroupedintothreecategoriesbasedontheorderofthefunctionor related algorithm. a) Algorithm that grow atleast as fast as same function. b) Algorithms that grow at the same rate. c) Algorithms that grow no faster. ThecategoriesmentionedabovearecommonlyknownasBigOmega(f),BigohO(f) and Big Theta (f) respectively. Ofthese,theBigOmegacategoryoffunctionsisnotofmuchinterestoussinceforall values of n greater than same threshold value no all the functions in (f) have values that are at least as large as f(i.e.) all functions in this category grow as fast as f or even faster. Big Oh O(f)categoryrepresentstheclassoffunctionsthatgrownofasterthanf.Thismeansthatforal valuesofngreaterthansamethresholdnumberallthefunctionsinO(f)havevalues thatareno greater than f. Worst Case Analysis: These are two worst case for the sequential search algorithm: -The value being searched matches the last element in the list -The value being searched is not present in the list. Average Case Analysis: Therearetwoaveragecaseanalyzesthatcanbedoneforasearchalgorithm.Thefirst assumes that the searchisalwayssuccessful andthe otherassumes that thevalue beingsearched will sometimes not be found Performance Analysis: Criteria upon which can judge an algorithm includes. 1. Does it do what we want it to do 2. Does it work correctly according to the original specifications of the task? SEERLOGICA INFOTECH SeerLogica Infotech Private Limited, #3A, Shanthi Nilaya Bhavan, Behind Huda Maithrivanam, Ameer Pet, Hyderabad-38. Http://www.seerlogica.com 633. Is there documentation that describes how to use it and how it works? 4. Are procedures created in such a way that they perform logical sub functions? 5. Is the code readable? These are other criteria for judging algorithms that have a more direct relationship to performance. These have to do with their computing times and storage requirements. Space Complexity: The space complexity of an algorithm is the amount of memory it needs to run to completion. 1)Example: Algorithm abc(a,b,c) { return a+b+b*c+(a+b-c)/(a+b)+4.0; } Algorithm abc computes a+b+b*c+(a+b-c)/(a+b)+4.0; 2)Example: Algorithm sum(a,n) [ s:=0.0; for i:=1 to n do s:=s+a[i]; return s; } n Algorithm sum computes a[i] iteratively where the a[i] s are real numbers. I=1 3)Example: Algorithm Rsum(a,n) { if(n=100n for n>=1 3) Definition:-[Theta]The function f(n)= (g(n)) iff there exists positive constants c1, c2 and n0 such that c1g(n)=3n for all n>=2 and 3n+2=2,so c1=3,c2=4 and n0 =2. The theta notation is more precise than both big oh and omega notations. 4) Definition:-[little oh] The function f(n)= o(g(n)) iff lim f(n)/g(n) =0 n-> Ex:3n+2=o(n) since lim 3n+2/n2 =0 n-> 5) Definition:-[little omega]The function f(n)= w(g(n)) iff lim g(n)/f(n) =0 n-> The Big OH Notation: Iff(n)andg(n)arefunctionsdefinedforpositiveintegers,thentowritef(n)isO(g(n)) whichmeansthatthereexistsaconstantCsuchthat|f(n)|f(n)-O(g(n))ifthereexiststwoconstantsCandnosuchthat |f(n)|= no. Utility: f(n) will normally represent the computing time of some algorithm. When we say that the computingtimeofanalgorithmisO(g(n))wemeanthatitsexecutiontakesnomorethana constant times g(n).n is a parameter which characterizes the input and/or output. i) Big O is transitive:- It is easy to show that if f(n) is O(g(n)) is O(h(n)),f(n) s O(h(n)). e.g:n+100nisO(n),nisandO(n)consequentlyn+100nisO(n).Thisiscalled transitive property. ii) Big O is multiplicative: A constantcomputing timeis referred to as O(1),O(1) is better than O(n),whichin tern is better than O(n).O(n)is worse and O(2^n) is awful. One other frequently seen computing time is O(log n base 2)which is better than O(n). Its complexity increases in multiple as n increases, hence it is multiplicative. Total number of key comparisonsby Quick Sort algorithm for an unordered arrayis O(nlogn) and for ordered array is O(n). For an unsorted array if we are lucky then each time a record is correctly positioned the sub file to itsleft will be of the same size as that to its right. This would leave us with the sorting of two sub files each of size roughly n/2. The time required to position a record in the file of size n is O(n). If T(n) is the time taken to sort a file of n records then when the file splits roughly into two equal parts each time a record is positioned correctly we have T(n)