7. 7
Evaluation
•Grade Percentage
–FCD : 70% and above
–FC : 60% -69%
–SC : 35% -59%
–FL : less than 35%
•Syllabus Coverage Schedule
–1stIA Test : 30% [ Portion-first 2.5 Units ]
–2ndIA Test : 30% [ Portion-next 2.5 Units ]
–3rdIA Test : 40% [ Portion-Last 3 Units ]
8. 8
Evaluation
•Assignments
–Total : 3
–Each Assignment to be submitted before the IA test
begins
•Attendance
–Class Participation: 85%
•You may get detained if you miss (more than) ¼of the whole classes
•Academic dishonesty (e.g. cheating, copying, late coming and etc.) will be taken seriously
9. 9
Announcement
•Class Website
•The link for the CMS portal is:
–Intranet link: http:172.17.0.2moodle
–Internet link: http:61.8.153.222moodle
–http://gg.gg/hkbkis
•Class information such as lecture notes can be accessible through this website
•We will also use Moodle for online test
10. 10
Announcement
•Programming Assignments
–We encourage to study and discuss together for doing programming assignments.
–However, you must do programming YOURSELF.
–You must not share any of source code with other students.
–Any kind of academic dishonesty will be viewed very seriously.
11. Unit -1
11 Prof. A. Syed Mustafa (Ph.D)
Basic concepts
12. 12 Prof. A. Syed Mustafa (Ph.D)
Basic Concepts
Topics :
Pointers and Dynamic Memory Allocation
Algorithm Specification
Data Abstraction
Performance Analysis
Performance Measurement
13. 13 Prof. A. Syed Mustafa (Ph.D)
Basic Concepts
Objectives
Understanding core concepts of memory management, performance analysis.
Applying the pointer concepts to actual programming
managing memory efficiently
Improve the performance.
14. 14 Prof. A. Syed Mustafa (Ph.D)
Basic Concepts
Course Outcome:
Able to apply the pointer concepts to actual programming
Able to use memory efficiently
Able to increase the performance of the program.
15. 15 Prof. A. Syed Mustafa (Ph.D)
Basic ConceptsSystem Life Cycle
•Large-Scaleprogramcontainsmanycomplexinteractingparts.
•Programsundergoadevelopmentprocesscalledthesystemlifecycle.
•Solidfoundationin
1.dataabstraction
2.algorithmspecification
3.performanceanalysisandmeasurement
providesnecessarymethodology.
16. 16 Prof. A. Syed Mustafa (Ph.D)
Basic ConceptsSystem Life Cycle
5phasesofsystemlifecycle:
1.Requirements:Beginswithdefiningpurposeoftheproject. Whatinputs(needs),outputs(results)
2.Analysis:Breaktheproblemdownintomanageablepieces. bottom-upvs.top-down,divideandconquer
3.Design:dataobjectsandoperationscreationofabstractdatatypes,thespecificationofalgorithmsandalgorithmdesignstrategies,ignorecodingdetails.
4.Refinement&coding:chooserepresentationsforourdataobjectsandwritealgorithmsforeachoperationonthem.
weshouldwritethosealgorithmsthatareindependentofthedataobjectsfirst.
17. 17 Prof. A. Syed Mustafa (Ph.D)
Basic ConceptsSystem Life Cycle
5.Verification:consistsofdevelopingcorrectnessproofsfortheprogram,testingtheprogramwithavarietyofinputdataandremovingerrors.
Correctnessproofs:proofsareverytime-consuminganddifficulttodevelopforlargeprojects.Schedulingconstraintspreventthedevelopmentofacompletesetofproofsforalargesystem.
Testing:beforeandduringthecodingphase.testingisusedatkeycheckpointsintheoverallprocesstodeterminewhetherobjectivesarebeingmet.
ErrorRemoval:systemtestswillindicateerroneouscode. Errorscanberemoveddependingonthedesign&codingdecisionsmadeearlier.
19. 19
Basic ConceptsPointers
•i=10or*ip=10;
Inbothcasestheinteger10isstoredasthevalueofi.
Insecondcase,the*infrontofthepointeripcausesittobedereferenced,
bywhichwemeanthatinsteadofstoring10intothepointer,10isstoredintothelocationpointedatbythepointerip.
Prof. A. Syed Mustafa (Ph.D)
21. 21
Basic ConceptsPointers
Thenullpointerpointstonoobjectorfunction.
Thenullpointerisrepresentedbytheintegeras0anincharacteras‘0’.TheASCIIvalueforNULLis0.
Thenullpointerisinterpretedasfalseinrelationalexpressions.
Prof. A. Syed Mustafa (Ph.D)
22. 22
Basic ConceptsDynamic Memory Allocation
•Whenwewriteprogram,wemaynotknowhow
muchspacewemayneed,tostoredata.
•Cprovidesamechanismcalledaheap,for
allocatingstorageatrun-time.
•Thefunctionmalloc()isusedtoallocateanew
areaofmemory.
Prof. A. Syed Mustafa (Ph.D)
23. 23
Basic ConceptsDynamic Memory Allocation
malloc()
Syntax
void *malloc(size_tsize)
Parameters
•size--This is the size of the memory block, in bytes.
Return Value
•This function returns a pointer to the allocated memory, or NULLif the request fails
Prof. A. Syed Mustafa (Ph.D)
24. 24
Basic ConceptsDynamic Memory Allocation
malloc()
•The name mallocstands for "memory allocation".
•Thefunctionmalloc()reservesablockofmemoryofspecifiedsizeandreturnapointeroftypevoidwhichcanbecastedintopointerofanyform.
Prof. A. Syed Mustafa (Ph.D)
25. 25
Basic ConceptsDynamic Memory Allocation
•Whenmemoryisnolongerneeded,wemayfreeitbycallingfree()function.
•Thecalltomalloc()determinessizeofstoragerequiredtoholdintorthefloat.
•Thenotations(int*)and(float*)aretypecastexpressions.
Prof. A. Syed Mustafa (Ph.D)
26. 26
Basic ConceptsDynamic Memory Allocation
•Theresultisapointertothefirstbyteofastorageareaofthepropersize.
•Thereturnvalueofthemalloc()isvoid*.
•Acalltomalloc()mayfailforlackofsufficientmemory
Prof. A. Syed Mustafa (Ph.D)
27. 27
Basic ConceptsDynamic Memory Allocation
Example:
int*pi; float *pf;
pi = (int*) malloc(sizeof(int));
pf = (float *) malloc(sizeof(float));
*pi=1024; *pf=3.124;
printf(“an integer = %d, a float = %fn”,*pi,*pf);
free(pi); free(pf);
Prof. A. Syed Mustafa (Ph.D)
28. 28
Basic ConceptsDynamic Memory Allocation
•WhenprogramminginCitisawisepracticetosetallpointerstoNULLwhentheyarenotpointingtoanobject.
•Useexplicittypecastswhenconvertingbetweenpointertypes:
pi=malloc(sizeof(int));/*assigntopiapointertoint*/
pf=(float*)pi;/*castsanintpointertofloatpointer*/
•Inmanysystems,pointershavethesamesizeastypeint.intisthedefaulttypespecifier.
Prof. A. Syed Mustafa (Ph.D)
29. 29
Basic ConceptsDynamic Memory Allocation
calloc()
•The name callocstands for "contiguous memory allocation“ or ‘c’for cleared.
•Thefunctioncalloc()allocatesablockofmemoryforanarrayofnumelements,eachofthemsizebyteslong,andinitializesallitsbitstozero.
30. 30
Basic ConceptsDynamic Memory Allocation
calloc()
Syntax
void* calloc(size_tnum, size_tsize);
Parameters
•num--Number of elements to allocate.
•size--Size of each element
•size_tis an unsigned integral type.
Return Value
•On success, a pointerto the memory block allocated by the function.
•The type of this pointer is alwaysvoid*, which can be cast to the desired type of data pointer in order to be dereferenceable.
• If the function failed to allocate the requested block of memory, anull pointeris returned.
Prof. A. Syed Mustafa (Ph.D)
31. 31
Basic ConceptsDynamic Memory Allocation
calloc()
Example
int*ptr1,*ptr2;
ptr1 = (int*)calloc(10, sizeof(int));
ptr2=(int*)calloc(20,sizeof(float));
Prof. A. Syed Mustafa (Ph.D)
32. 32
Basic ConceptsDynamic Memory Allocation
malloc() & calloc()
Differrence
Theonlydifferencebetweenmalloc()andcalloc()isthat,malloc()allocatessingleblockofmemorywhereascalloc()allocatesmultipleblocksofmemoryeachofsamesizeandsetsallbytestozero. Prof. A. Syed Mustafa (Ph.D)
33. 33
Basic ConceptsDynamic Memory Allocation
malloc() & calloc()
Differrence
mallocfunction,whereastheareareservedtothestatesthatareundefined,theareaallocatedbythecallocfunctioncontainsa0.
Infact,thecallocfunctionisinternallymaybeafunctionthatcallsmalloc.Aftersecuringfunctionbymalloc,theareaisfilledwith0.
Prof. A. Syed Mustafa (Ph.D)
34. 34
Basic ConceptsDynamic Memory Allocation
free()
Syntax
void free(void *ptr)
Parameters
•ptr--Pointer to a memory block previously allocated withmalloc(), calloc() or realloc().
Return Value
•None
Note:
If the memeoryis not freed , then Dangling pointer arises which leads to garbagecollection.
Prof. A. Syed Mustafa (Ph.D)
43. 43
Basic ConceptsDynamic Memory Allocation
free()
•Deallocatememory block
•A block of memory previously allocated by a call to malloc(), calloc() or realloc() is deallocated, making it available again for further allocations. Ifptrdoes not point to a block of memory allocated with the above functions, it causesundefined behavior. Ifptris anull pointer, the function does nothing. This function does not change the value ofptritself, hence it still points to the same (now invalid) location.
Prof. A. Syed Mustafa (Ph.D)
45. 45
Basic ConceptsAlgorithm Specification
Analgorithmisafinitesetofinstructionsthat,iffollowed,accomplishesaparticulartask.
Algorithmsmustsatisfyfollowingcriteria:
Input:therearezeroormorequantitiesthatareexternallysupplied.
Output:atleastonequantityisproduced.
Definiteness:Eachinstructionisclearandunambiguous.
Finiteness:forallcases,thealgorithmterminatesafterafinitenumberofsteps.
Effectiveness:Everyinstructionmustbebasicenoughtobecarriedout,itmustalsobefeasible. Prof. A. Syed Mustafa (Ph.D)
46. 46
Basic ConceptsAlgorithm Specification
•Differencebetweenanalgorithmandaprogram:
Theprogramdoesnothavetosatisfythefourthcondition(Finiteness).
•Describinganalgorithm:
NaturallanguagesuchasEnglishcanbeused.Makesureresultinginstructionsaredefinite.
•Flowchart:
workwellonlyforalgorithm,smallandsimple.
Prof. A. Syed Mustafa (Ph.D)
47. 47
Basic ConceptsAlgorithm Specification
•Differencebetweenanalgorithmandaprogram:
Theprogramdoesnothavetosatisfythefourthcondition(Finiteness).
•Describinganalgorithm:
NaturallanguagesuchasEnglishcanbeused.Makesureresultinginstructionsaredefinite.
•Flowchart:
workwellonlyforalgorithm,smallandsimple.
Prof. A. Syed Mustafa (Ph.D)
48. 48
Basic ConceptsAlgorithm Specification
Translating a Problem into an Algorithm
Example-SelectionSort
Deviseaprogramthatsortsasetofnintegers, wheren>=1,fromsmallesttolargest.
SolutionI:
Fromthoseintegersthatarecurrentlyunsorted, findthesmallestandplaceitnextinthesortedlist
. Prof. A. Syed Mustafa (Ph.D)
49. 49
Basic ConceptsAlgorithm Specification
Translating a Problem into an Algorithm
Describessortingtechnique,butitisnotanalgorithm
Problems:
1.Does not describe where and how the integers are initially sorted.
2.Does not indicate where to place the result.
.
Prof. A. Syed Mustafa (Ph.D)
50. 50
Basic ConceptsAlgorithm Specification
Translating a Problem into an Algorithm
SolutionII:SelectionSort
Analgorithm,writteninpartiallyCandEnglish
for(i=0;i<n;i++)
{
Examinelist[i]tolist[n-1]andsupposethat
thesmallestintegerislist[min];
Interchangelist[i]andlist[min];
}
.
51. 51
Basic ConceptsAlgorithm Specification
Selection Sort
-find the smallest integer
-interchange or swap
-we can solve the problem using a function or macro
void swap(int*x, int*y) // both arguments are pointers
{
inttemp= *x;
*x= *y;
*y= temp;
}
Prof. A. Syed Mustafa (Ph.D)
52. 52
Basic ConceptsAlgorithm Specification
Selection Sort
#define swap(x,y,t)((t)= (x), (x)= (y), (y)= (t))
void sort(intlist[ ], intn)
{
inti, j, min, temp;
for (i= 0; i< n-1; i++){
min= i;
for (j= i+1; j< n; j++){
if (list[j]< list[min]) min= j;
}
swap(list[i], list[min], temp);
}
Prof. A. Syed Mustafa (Ph.D)
53. 53
Basic ConceptsAlgorithm Specification
Theorem 1.1:
sort(a, n) correctly sorts a set of n≥ 1 integers; the result remains in a[0] … a[n-1] such that
a[0] ≤ a[1] ≤ … ≤ a[n–1].
Prof. A. Syed Mustafa (Ph.D)
54. 54
Basic ConceptsAlgorithm Specification
Example: Binary Search
Assumethatwehaven≥1distinctintegersthatarealreadysortedandstoredinthearraya[0]…a[n-1]. Ourtaskistodetermineiftheintegerxispresentandifsotoreturnjsuchthatx=a[j];otherwisereturn-1.
Prof. A. Syed Mustafa (Ph.D)
55. 55
Basic ConceptsAlgorithm Specification
Example: Binary Search
1.Let leftand right, respectively, denote the left and right ends of the list to be searched.
2.Initially, left = 0 and right = n –1.
3.Let middle = (left +right) / 2 be the middle position in the list.
4.If we compare a[middle]with x, we obtain one of the three results.
Prof. A. Syed Mustafa (Ph.D)
56. 56
Basic ConceptsAlgorithm Specification
Example: Binary Search
1.x < a[middle]
In this case, if xis present, it must be in the positions between 0 and middle–1. Therefore, we set right to middle–1.
2.x== a[middle]
In this case, we return middle.
3. x> a[middle]
Inthiscase,ifxispresent,itmustbeinthepositionsbetweenmiddle+1andn-1.So,wesetlefttomiddle+1.
Prof. A. Syed Mustafa (Ph.D)
58. 58
Basic ConceptsAlgorithm Specification
Binary Search.
intcompare(intx, inty)
{
if(x < y) return-1;
else if( x == y) return0;
else return1;
} // end of compare
Macro
#define compare(x, y) ( ( (x) < (y) ) ? -1: ( (x) == (y) ) ? 0 : 1 )
Prof. A. Syed Mustafa (Ph.D)
59. 59
Basic ConceptsAlgorithm Specification
Algorithms are implemented as functions in C.
Functions divide the programs into manageable pieces.
They make program easier to read.
Functions can be tested separately.
Declare function first then define it later.
Prof. A. Syed Mustafa (Ph.D)
60. 60
Basic ConceptsAlgorithm Specification
Recursive algorithm
Therearemainlytwoapproachesforrepetitive
approach.
1.Iteration
2.Recursion
Recursionisarepetitiveprocessinwhichanalgorithmcallsitself.
Prof. A. Syed Mustafa (Ph.D)
61. 61
Basic ConceptsAlgorithm Specification
Recursive algorithm
The following Figure 1 and Figure 2 portrayed the typical pictorial examples for recursive calling.
Prof. A. Syed Mustafa (Ph.D)
62. 62
Basic ConceptsAlgorithm Specification
Recursive algorithm
The following Figure2 portrayed the typical pictorial examples for recursive calling.
Prof. A. Syed Mustafa (Ph.D)
63. 63
Basic ConceptsAlgorithm Specification
Recursive algorithm
The following Figure portrayed the typical pictorial examples for recursive calling.
Prof. A. Syed Mustafa (Ph.D)
64. 64
Basic ConceptsAlgorithm Specification
Recursive algorithm
Recursionisaprogrammingtechniqueinwhichamethodcancallitselftosolveaproblem.
TwoTypes:
1.DirectRecursion
2.Indirectrecursion
Prof. A. Syed Mustafa (Ph.D)
65. 65
Basic ConceptsAlgorithm Specification
Recursive algorithm
1.DirectRecursion
Functionscallsthemselves
2.Indirectrecursion
Functions calls other function that invoke the
calling function again.
Any function that we can write using assignment, if- else and while statements can be written recursively.
Prof. A. Syed Mustafa (Ph.D)
66. 66
Basic ConceptsAlgorithm Specification
Value of Recursion
This is well suited an alternative concept in the following situations
1. Recursion can be used to replace loop
2. A recursive procedure is mathematically more elegant than
one using loops
3. Sometime procedure that would tricky to write a loop are
straightforward to using recursion.
4. Recursively defined data structure, like list, are very well suited to processing by recursive procedures and functions
Prof. A. Syed Mustafa (Ph.D)
69. 69
Basic ConceptsAlgorithm Specification
Algorithm to compute factorial using recursive method:
Factorial (N)
1. Receive N
2. if N > 1 return
Factorial(N-1) * N
else
return 1
Prof. A. Syed Mustafa (Ph.D)
70. 70
Basic ConceptsAlgorithm Specification
program to compute factorial using recursive function:
#include<stdio.h>
longfactorial(int);
intmain()
{intn;longf;
printf("Enter an integer to find factorialn");
scanf("%d",&n);
if(n <0)printf("Negative integers are not allowedn");
else{f =factorial(n);printf("%d! = %ldn",n,f);}
return0;}
longfactorial(intn)
{if (n ==0)return 1;
else return(n*factorial(n-1));
}
Prof. A. Syed Mustafa (Ph.D)
71. 71
Basic ConceptsAlgorithm Specification
program to compute factorial using recursive function:
Prof. A. Syed Mustafa (Ph.D)
72. 72
Basic ConceptsAlgorithm Specification
program to compute factorial using recursive function:
Prof. A. Syed Mustafa (Ph.D)
73. 73
Basic ConceptsAlgorithm Specification
program to compute factorial using recursive function:
Prof. A. Syed Mustafa (Ph.D)
74. 74
Basic ConceptsAlgorithm Specification
program to compute factorial using recursive function:
Prof. A. Syed Mustafa (Ph.D)
75. 75
Basic ConceptsAlgorithm Specification
program to compute factorial using recursive function:
Prof. A. Syed Mustafa (Ph.D)
83. 83
Basic ConceptsAlgorithm Specification
Recursive algorithm: Greatest Common Divisor(x, y)
Prof. A. Syed Mustafa (Ph.D)
84. 84
Basic ConceptsAlgorithm Specification
/* PROGRAM TO FIND GCD OF TWO NUMBER USING RECURSION EUCLIDS*/ #include<stdio.h> #include<conio.h> intgcd(int,int); intmain() {inta,b; clrscr(); printf("n Enter two number:" ); scanf("%d %d",&a,&b); printf("GCD of two number : %d" ,gcd(a,b)); getch(); return(0); }
Prof. A. Syed Mustafa (Ph.D)
85. 85
Basic ConceptsAlgorithm Specification
/* PROGRAM TO FIND GCD OF TWO NUMBER USING RECURSION
intgcd(intm, intn) { if(m==0) return n; if(n==0) return m; return gcd(n,m%n); }
Prof. A. Syed Mustafa (Ph.D)
86. 86
Basic ConceptsAlgorithm Specification
/* PROGRAM TO FIND GCD OF TWO NUMBER USING RECURSION
intgcd(inta,intb)
{
if(a !=b)
{
if(a >b)
returngcd(a -b,b);
else
returngcd(a,b -a);
}
returna;
} Prof. A. Syed Mustafa (Ph.D)
87. 87
Basic ConceptsAlgorithm Specification
Recursive algorithm: Greatest Common Divisor(x, y)
Prof. A. Syed Mustafa (Ph.D)
89. 89
Basic ConceptsAlgorithm Specification
Recursive algorithm
Prof. A. Syed Mustafa (Ph.D)
C(n, k) = C(n-1, k-1) + C(n-1, k)
C(n, 0) = C(n, n) = 1
90. 90
Basic ConceptsAlgorithm Specification
Recursive algorithm-Binomial Coefficient
Prof. A. Syed Mustafa (Ph.D)
intbinomialCoeff(intn, intk)// Returns value of Binomial Coefficient C(n, k)
{
if (k==0 || k==n)// Base Cases
return 1;
return binomialCoeff(n-1, k-1) + binomialCoeff(n-1, k);// Recur
}
intmain()/* program to test above function*/
{
intn = 5, k = 2;
printf("Value of C(%d, %d) is %d ", n, k, binomialCoeff(n, k)); // C(5,2) is 10
return 0;
}
91. 91
Basic ConceptsAlgorithm Specification
Recursive algorithm -Binomial Coefficient
Prof. A. Syed Mustafa (Ph.D)
92. 92
Basic ConceptsAlgorithm Specification
Recursive algorithm: Towers of Hanoi
Prof. A. Syed Mustafa (Ph.D)
93. 93
Basic ConceptsAlgorithm Specification
Recursive algorithm: Towers of Hanoi
Prof. A. Syed Mustafa (Ph.D)
•Label the stands Src, Intr,Dest.
•Letnbe the total number of discs.
•Number the discs from 1 (smallest, topmost) ton(largest, bottommost).
To move n discs from stand Srcto stand Dest:
1.Move n-1 plates from Srcto Intr. This leaves plate #n alone on plate Src.
2.Move plate #n from SrctoDest.
3.Move n-1 plates from Intrto Destso they sit on plate #n.
94. 94
Basic ConceptsAlgorithm Specification
Recursive algorithm: Towers of Hanoi
Prof. A. Syed Mustafa (Ph.D)
95. 95
Basic ConceptsAlgorithm Specification
Recursive algorithm: Towers of Hanoi
Prof. A. Syed Mustafa (Ph.D)
FUNCTION MoveTower(disk, source, dest, inter)
IF disk== 1,THEN:
move diskfrom sourceto dest
ELSE:
MoveTower(disk-1, source, inter, dest) // Step 1 above
move diskfrom sourceto dest// Step 2 above
MoveTower(disk-1, inter, dest, source) // Step 3 above END IF
96. 96
Basic ConceptsAlgorithm Specification
Recursive algorithm: Towers of Hanoi
Prof. A. Syed Mustafa (Ph.D)
97. 97
Basic ConceptsAlgorithm Specification
Recursive algorithm: Towers of Hanoi
Prof. A. Syed Mustafa (Ph.D)
98. 98
Basic ConceptsAlgorithm Specification
Recursive algorithm: Towers of Hanoi
Prof. A. Syed Mustafa (Ph.D)
99. 99
Basic ConceptsAlgorithm Specification
Limitations of Recursion
Recursion should not be used if the answer to any of the following questions is no:
Is the algorithm or data structure naturally suited to recursion (tree is the first choice) ?
Is the recursive solution shorter and more understandable?
Does the recursive solution run within acceptable time and space limits ?
As a general rule, recursive algorithms should be effectively used only when their efficiency is logarithmic.
Prof. A. Syed Mustafa (Ph.D)
100. 100
Basic ConceptsData Abstraction
Abstractionistheprocessbywhichdataandprogramsaredefinedwitharepresentationsimilartoitsmeaning(semantics),whilehidingawaytheimplementationdetails.
Prof. A. Syed Mustafa (Ph.D)
101. 101
Basic ConceptsData Abstraction
Abstractiontriestoreduceandfactoroutdetailssothattheprogrammercanfocusonafewconceptsatatime.Asystemcanhaveseveralabstractionlayerswherebydifferentmeaningsandamountsofdetailareexposedtotheprogrammer.
Forexample,low-levelabstractionlayersexposedetailsofthehardwarewheretheprogramisrun,whilehigh- levellayersdealwiththebusinesslogicoftheprogram.
Prof. A. Syed Mustafa (Ph.D)
113. 113
Basic ConceptsPerformance Analysis
Prof. A. Syed Mustafa (Ph.D)
Space & Time
Does the program efficiently use primary and secondary storage ?
Is the program’s running time acceptable for the task ?
115. 115
Basic ConceptsPerformance Analysis
Prof. A. Syed Mustafa (Ph.D)
The space complexity of a program is the amount of memory that it needs to run to completion.
The time complexity of a program is the amount of computer time that it needs to run to completion
126. 126
Basic ConceptsPerformance Analysis
Prof. A. Syed Mustafa (Ph.D)
TP(n) = CaADD(n)+ CsSUB(n)+CLLDA(n)+CstSTA(n)
n –Instance Characteristic
Ca, Cs , CL , Cst–constants-time needed to perorm
each operation
ADD -No of additions
SUB -No of Subtraction
LDA –No of Loads
STA –No of Stores
Performed when the program is run with instance characteristic n.
132. 132
Basic ConceptsPerformance Analysis
Prof. A. Syed Mustafa (Ph.D)
General statements in a C program
Step count
1.Comments 0
2.Declarative statements0
3.Expressions and assignment statements1
4.Iteration statementsN
5.Switch statementN
6.If-else statementN
7.Function invocation1 or N
8.Memory management statements1 or N
9.Function statements0
10.Jump statements1 or N
133. 133
Basic ConceptsPerformance Analysis
Prof. A. Syed Mustafa (Ph.D)
Notethatastepcountdoesnotnecessarilyreflectthecomplexityofthestatement.
Step per execution (s/e):
Thes/eofastatementistheamountbywhichcountchangesasaresultoftheexecutionofthatstatement.