SlideShare una empresa de Scribd logo
1 de 163
Descargar para leer sin conexión
1
2
Syllabus 
3 Prof. A. Syed Mustafa (Ph.D)
Syllabus 
4 Prof. A. Syed Mustafa (Ph.D)
Syllabus 
5 Prof. A. Syed Mustafa (Ph.D)
Syllabus 
6 Prof. A. Syed Mustafa (Ph.D)
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 
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 
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 
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.
Unit -1 
11 Prof. A. Syed Mustafa (Ph.D) 
Basic concepts
12 Prof. A. Syed Mustafa (Ph.D) 
Basic Concepts 
Topics : 
Pointers and Dynamic Memory Allocation 
Algorithm Specification 
Data Abstraction 
Performance Analysis 
Performance Measurement
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 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 Prof. A. Syed Mustafa (Ph.D) 
Basic ConceptsSystem Life Cycle 
•Large-Scaleprogramcontainsmanycomplexinteractingparts. 
•Programsundergoadevelopmentprocesscalledthesystemlifecycle. 
•Solidfoundationin 
1.dataabstraction 
2.algorithmspecification 
3.performanceanalysisandmeasurement 
providesnecessarymethodology.
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 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.
18 
•ForanytypeTinCthereisacorrespondingtypepointer-to-T. 
•Theactualvalueofapointertypeisanaddressofmemory. 
–&theaddressoperator. 
–*thedereferencing(orindirection)operator. 
–Declaration 
•inti,*ip;//iisanintegervariableandipisapointertoaninteger. 
•ip=&i; 
then&ireturnstheaddressofiandassignsitasthevalueofpi. Basic ConceptsPointers 
Prof. A. Syed Mustafa (Ph.D)
19 
Basic ConceptsPointers 
•i=10or*ip=10; 
Inbothcasestheinteger10isstoredasthevalueofi. 
Insecondcase,the*infrontofthepointeripcausesittobedereferenced, 
bywhichwemeanthatinsteadofstoring10intothepointer,10isstoredintothelocationpointedatbythepointerip. 
Prof. A. Syed Mustafa (Ph.D)
20 
Basic ConceptsPointers 
Thesizeofapointercanbedifferentondifferentcomputers. 
Thesizeofapointertoacharcanbelongerthanapointertoafloat. 
TestforthenullpointerinC 
if(ip==NULL)orif(ip==0)orif(!ip)
21 
Basic ConceptsPointers 
Thenullpointerpointstonoobjectorfunction. 
Thenullpointerisrepresentedbytheintegeras0anincharacteras‘0’.TheASCIIvalueforNULLis0. 
Thenullpointerisinterpretedasfalseinrelationalexpressions. 
Prof. A. Syed Mustafa (Ph.D)
22 
Basic ConceptsDynamic Memory Allocation 
•Whenwewriteprogram,wemaynotknowhow 
muchspacewemayneed,tostoredata. 
•Cprovidesamechanismcalledaheap,for 
allocatingstorageatrun-time. 
•Thefunctionmalloc()isusedtoallocateanew 
areaofmemory. 
Prof. A. Syed Mustafa (Ph.D)
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 
Basic ConceptsDynamic Memory Allocation 
malloc() 
•The name mallocstands for "memory allocation". 
•Thefunctionmalloc()reservesablockofmemoryofspecifiedsizeandreturnapointeroftypevoidwhichcanbecastedintopointerofanyform. 
Prof. A. Syed Mustafa (Ph.D)
25 
Basic ConceptsDynamic Memory Allocation 
•Whenmemoryisnolongerneeded,wemayfreeitbycallingfree()function. 
•Thecalltomalloc()determinessizeofstoragerequiredtoholdintorthefloat. 
•Thenotations(int*)and(float*)aretypecastexpressions. 
Prof. A. Syed Mustafa (Ph.D)
26 
Basic ConceptsDynamic Memory Allocation 
•Theresultisapointertothefirstbyteofastorageareaofthepropersize. 
•Thereturnvalueofthemalloc()isvoid*. 
•Acalltomalloc()mayfailforlackofsufficientmemory 
Prof. A. Syed Mustafa (Ph.D)
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 
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 
Basic ConceptsDynamic Memory Allocation 
calloc() 
•The name callocstands for "contiguous memory allocation“ or ‘c’for cleared. 
•Thefunctioncalloc()allocatesablockofmemoryforanarrayofnumelements,eachofthemsizebyteslong,andinitializesallitsbitstozero.
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 
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 
Basic ConceptsDynamic Memory Allocation 
malloc() & calloc() 
Differrence 
Theonlydifferencebetweenmalloc()andcalloc()isthat,malloc()allocatessingleblockofmemorywhereascalloc()allocatesmultipleblocksofmemoryeachofsamesizeandsetsallbytestozero. Prof. A. Syed Mustafa (Ph.D)
33 
Basic ConceptsDynamic Memory Allocation 
malloc() & calloc() 
Differrence 
mallocfunction,whereastheareareservedtothestatesthatareundefined,theareaallocatedbythecallocfunctioncontainsa0. 
Infact,thecallocfunctionisinternallymaybeafunctionthatcallsmalloc.Aftersecuringfunctionbymalloc,theareaisfilledwith0. 
Prof. A. Syed Mustafa (Ph.D)
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)
35 
Basic ConceptsDynamic Memory Allocation 
Prof. A. Syed Mustafa (Ph.D)
36 
Basic ConceptsDynamic Memory Allocation 
Prof. A. Syed Mustafa (Ph.D)
37 
Basic ConceptsDynamic Memory Allocation 
Prof. A. Syed Mustafa (Ph.D)
38 
Basic ConceptsDynamic Memory Allocation 
Prof. A. Syed Mustafa (Ph.D)
39 
Basic ConceptsDynamic Memory Allocation 
realloc() -Reallocate memory block 
void*realloc(void*ptr,size_tsize) 
•TheClibraryfunctionattemptstoresizethememoryblockpointedtobyptrthatwaspreviouslyallocatedwithacalltomallocorcallocorrealloc 
Parameters 
ptr--Thisisthepointertoamemoryblockpreviouslyallocatedwithmalloc,callocorrealloctobereallocated.IfthisisNULL,anewblockisallocatedandapointertoitisreturnedbythefunction 
•size--Thisisthenewsizeforthememoryblock,inbytes.Ifitis0andptrpointstoanexistingblockofmemory,thememoryblockpointedbyptrisdeallocatedandaNULLpointerisreturned. 
ReturnValue 
Thisfunctionreturnsapointertothenewlyallocatedmemory,orNULLiftherequestfails. 
Prof. A. Syed Mustafa (Ph.D)
40 
Basic ConceptsDynamic Memory Allocation 
realloc() -Reallocate memory block 
•Thefunctionrealloc()reallocatesamemoryblockwithaspecificnewsize. 
•Ifwecallrealloc()thesizeofthememoryblockpointedtobythepointerischangedtothegivensizeinbytes. 
•Thiswayweareabletoexpandandreducetheamountofmemoryyouwanttouse(ifavailableofcourse.) 
•Itispossiblethatthefunctionmovesthememoryblocktoanewlocation, inwhichwaythefunctionwillreturnthisnewlocation. 
•Ifthesizeoftherequestedblockislargerthenthepreviousblockthenthevalueofthenewportionisindeterminate. 
Prof. A. Syed Mustafa (Ph.D)
41 
Basic ConceptsDynamic Memory Allocation 
realloc() -Reallocate memory block 
•Thereturnvalueisapointertothereallocatedmemoryblock,whichmaybeeitherthesameasptroranewlocation. 
•Thetypeofreturnpointerisvoid*,whichcanbecasttothedesiredtypeofdatapointerinordertobedereferenceable 
•IfthepointerisNULLthenthefunctionwillbehaveexactlylikethefunctionmalloc().Itwillassignanewblockofasizeinbytesandwillreturnapointertoit. 
•Ifthesizeis0thenthememorythatwaspreviouslyallocatedisfreedasifacallofthefunctionfree()wasgiven.ItwillreturnaNULLpointerinthatcase. 
Prof. A. Syed Mustafa (Ph.D)
42 
•. 
#include<stdlib.h> 
#include<stdio.h> 
intmain() 
{char*str; 
str=(char*)malloc(4);/* Initial memory allocation */ 
strcpy(str,“data"); 
printf("String = %s, Address = %pn",str,str); 
/* Reallocating memory */ 
str=(char*)realloc(str,13); 
strcat(str,“structure"); 
printf("String = %s, Address = %pn",str,str); 
free(str); 
return(0); 
} Basic ConceptsDynamic Memory Allocation 
Prof. A. Syed Mustafa (Ph.D)
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)
44 
Basic ConceptsDynamic Memory Allocation 
free() 
/* example */ 
#include <stdlib.h> /* malloc, calloc, realloc, free */ 
intmain () 
{ 
int* i1, * i2, * i3; 
i1 = (int*) malloc(100*sizeof(int)); 
i2 = (int*) calloc(100,sizeof(int)); 
i3 = (int*) realloc(i2,500*sizeof(int)); 
free (i1); 
free (i3); 
return 0; 
} 
Prof. A. Syed Mustafa (Ph.D)
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 
Basic ConceptsAlgorithm Specification 
•Differencebetweenanalgorithmandaprogram: 
Theprogramdoesnothavetosatisfythefourthcondition(Finiteness). 
•Describinganalgorithm: 
NaturallanguagesuchasEnglishcanbeused.Makesureresultinginstructionsaredefinite. 
•Flowchart: 
workwellonlyforalgorithm,smallandsimple. 
Prof. A. Syed Mustafa (Ph.D)
47 
Basic ConceptsAlgorithm Specification 
•Differencebetweenanalgorithmandaprogram: 
Theprogramdoesnothavetosatisfythefourthcondition(Finiteness). 
•Describinganalgorithm: 
NaturallanguagesuchasEnglishcanbeused.Makesureresultinginstructionsaredefinite. 
•Flowchart: 
workwellonlyforalgorithm,smallandsimple. 
Prof. A. Syed Mustafa (Ph.D)
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 
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 
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 
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 
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 
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 
Basic ConceptsAlgorithm Specification 
Example: Binary Search 
Assumethatwehaven≥1distinctintegersthatarealreadysortedandstoredinthearraya[0]…a[n-1]. Ourtaskistodetermineiftheintegerxispresentandifsotoreturnjsuchthatx=a[j];otherwisereturn-1. 
Prof. A. Syed Mustafa (Ph.D)
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 
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)
57 
Basic ConceptsAlgorithm Specification 
Binary Search. 
Prof. A. Syed Mustafa (Ph.D)
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 
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 
Basic ConceptsAlgorithm Specification 
Recursive algorithm 
Therearemainlytwoapproachesforrepetitive 
approach. 
1.Iteration 
2.Recursion 
Recursionisarepetitiveprocessinwhichanalgorithmcallsitself. 
Prof. A. Syed Mustafa (Ph.D)
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 
Basic ConceptsAlgorithm Specification 
Recursive algorithm 
The following Figure2 portrayed the typical pictorial examples for recursive calling. 
Prof. A. Syed Mustafa (Ph.D)
63 
Basic ConceptsAlgorithm Specification 
Recursive algorithm 
The following Figure portrayed the typical pictorial examples for recursive calling. 
Prof. A. Syed Mustafa (Ph.D)
64 
Basic ConceptsAlgorithm Specification 
Recursive algorithm 
Recursionisaprogrammingtechniqueinwhichamethodcancallitselftosolveaproblem. 
TwoTypes: 
1.DirectRecursion 
2.Indirectrecursion 
Prof. A. Syed Mustafa (Ph.D)
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 
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)
67 
Basic ConceptsAlgorithm Specification 
Prof. A. Syed Mustafa (Ph.D)
68 
Basic ConceptsAlgorithm Specification 
Prof. A. Syed Mustafa (Ph.D)
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 
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 
Basic ConceptsAlgorithm Specification 
program to compute factorial using recursive function: 
Prof. A. Syed Mustafa (Ph.D)
72 
Basic ConceptsAlgorithm Specification 
program to compute factorial using recursive function: 
Prof. A. Syed Mustafa (Ph.D)
73 
Basic ConceptsAlgorithm Specification 
program to compute factorial using recursive function: 
Prof. A. Syed Mustafa (Ph.D)
74 
Basic ConceptsAlgorithm Specification 
program to compute factorial using recursive function: 
Prof. A. Syed Mustafa (Ph.D)
75 
Basic ConceptsAlgorithm Specification 
program to compute factorial using recursive function: 
Prof. A. Syed Mustafa (Ph.D)
76 
Basic ConceptsAlgorithm Specification 
Prof. A. Syed Mustafa (Ph.D)
77 
Basic ConceptsAlgorithm Specification 
Prof. A. Syed Mustafa (Ph.D)
78 
Basic ConceptsAlgorithm Specification 
Prof. A. Syed Mustafa (Ph.D)
79 
Basic ConceptsAlgorithm Specification 
Recursive program: Fibonacci 
intmain() 
{ 
intn=10; 
printf(“%d”, rfib(n)); 
} 
intrfib(intn) 
{ 
if (n==1 || n==2) return 1; 
return rfib(n1) + rfib(n2); 
} 
Prof. A. Syed Mustafa (Ph.D)
80 
Basic ConceptsAlgorithm Specification 
Recursive program: Fibonacci 
Prof. A. Syed Mustafa (Ph.D)
81 
Basic ConceptsAlgorithm Specification 
Recursive program: Fibonacci 
Prof. A. Syed Mustafa (Ph.D)
82 
Basic ConceptsAlgorithm Specification 
Recursive program: Fibonacci 
Prof. A. Syed Mustafa (Ph.D)
83 
Basic ConceptsAlgorithm Specification 
Recursive algorithm: Greatest Common Divisor(x, y) 
Prof. A. Syed Mustafa (Ph.D)
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 
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 
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 
Basic ConceptsAlgorithm Specification 
Recursive algorithm: Greatest Common Divisor(x, y) 
Prof. A. Syed Mustafa (Ph.D)
88 
Basic ConceptsAlgorithm Specification 
Recursive algorithm 
Prof. A. Syed Mustafa (Ph.D)
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 
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 
Basic ConceptsAlgorithm Specification 
Recursive algorithm -Binomial Coefficient 
Prof. A. Syed Mustafa (Ph.D)
92 
Basic ConceptsAlgorithm Specification 
Recursive algorithm: Towers of Hanoi 
Prof. A. Syed Mustafa (Ph.D)
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 
Basic ConceptsAlgorithm Specification 
Recursive algorithm: Towers of Hanoi 
Prof. A. Syed Mustafa (Ph.D)
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 
Basic ConceptsAlgorithm Specification 
Recursive algorithm: Towers of Hanoi 
Prof. A. Syed Mustafa (Ph.D)
97 
Basic ConceptsAlgorithm Specification 
Recursive algorithm: Towers of Hanoi 
Prof. A. Syed Mustafa (Ph.D)
98 
Basic ConceptsAlgorithm Specification 
Recursive algorithm: Towers of Hanoi 
Prof. A. Syed Mustafa (Ph.D)
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 
Basic ConceptsData Abstraction 
Abstractionistheprocessbywhichdataandprogramsaredefinedwitharepresentationsimilartoitsmeaning(semantics),whilehidingawaytheimplementationdetails. 
Prof. A. Syed Mustafa (Ph.D)
101 
Basic ConceptsData Abstraction 
Abstractiontriestoreduceandfactoroutdetailssothattheprogrammercanfocusonafewconceptsatatime.Asystemcanhaveseveralabstractionlayerswherebydifferentmeaningsandamountsofdetailareexposedtotheprogrammer. 
Forexample,low-levelabstractionlayersexposedetailsofthehardwarewheretheprogramisrun,whilehigh- levellayersdealwiththebusinesslogicoftheprogram. 
Prof. A. Syed Mustafa (Ph.D)
102 
Basic ConceptsData Abstraction 
Prof. A. Syed Mustafa (Ph.D)
103 
Basic ConceptsData Abstraction 
Prof. A. Syed Mustafa (Ph.D)
104 
Basic ConceptsData Abstraction 
Prof. A. Syed Mustafa (Ph.D)
105 
Basic ConceptsData Abstraction 
Prof. A. Syed Mustafa (Ph.D)
106 
Basic ConceptsData Abstraction 
Prof. A. Syed Mustafa (Ph.D)
107 
Basic ConceptsData Abstraction 
Prof. A. Syed Mustafa (Ph.D)
108 
Basic ConceptsData Abstraction 
Prof. A. Syed Mustafa (Ph.D)
109 
Basic ConceptsData Abstraction 
Prof. A. Syed Mustafa (Ph.D)
110 
Basic ConceptsData Abstraction 
Prof. A. Syed Mustafa (Ph.D)
111 
Basic ConceptsData Abstraction 
Prof. A. Syed Mustafa (Ph.D)
112 
Basic ConceptsPerformance Analysis 
Prof. A. Syed Mustafa (Ph.D)
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 ?
114 
Basic ConceptsPerformance Analysis 
Prof. A. Syed Mustafa (Ph.D)
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
116 
Basic ConceptsPerformance Analysis 
Prof. A. Syed Mustafa (Ph.D)
117 
Basic ConceptsPerformance Analysis 
Prof. A. Syed Mustafa (Ph.D)
118 
Basic ConceptsPerformance Analysis 
Prof. A. Syed Mustafa (Ph.D)
119 
Basic ConceptsPerformance Analysis 
Prof. A. Syed Mustafa (Ph.D)
120 
Basic ConceptsPerformance Analysis 
Prof. A. Syed Mustafa (Ph.D)
121 
Basic ConceptsPerformance Analysis 
Prof. A. Syed Mustafa (Ph.D)
122 
Basic ConceptsPerformance Analysis 
Prof. A. Syed Mustafa (Ph.D)
123 
Basic ConceptsPerformance Analysis 
Prof. A. Syed Mustafa (Ph.D)
124 
Basic ConceptsPerformance Analysis 
Prof. A. Syed Mustafa (Ph.D)
125 
Basic ConceptsPerformance Analysis 
Prof. A. Syed Mustafa (Ph.D)
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.
127 
Basic ConceptsPerformance Analysis 
Prof. A. Syed Mustafa (Ph.D)
128 
Basic ConceptsPerformance Analysis 
Prof. A. Syed Mustafa (Ph.D)
129 
Basic ConceptsPerformance Analysis 
Prof. A. Syed Mustafa (Ph.D)
130 
Basic ConceptsPerformance Analysis 
Prof. A. Syed Mustafa (Ph.D)
131 
Basic ConceptsPerformance Analysis 
Prof. A. Syed Mustafa (Ph.D)
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 
Basic ConceptsPerformance Analysis 
Prof. A. Syed Mustafa (Ph.D) 
Notethatastepcountdoesnotnecessarilyreflectthecomplexityofthestatement. 
Step per execution (s/e): 
Thes/eofastatementistheamountbywhichcountchangesasaresultoftheexecutionofthatstatement.
134 
Basic ConceptsPerformance Analysis 
Prof. A. Syed Mustafa (Ph.D)
135 
Basic ConceptsPerformance Analysis 
Prof. A. Syed Mustafa (Ph.D)
136 
Basic ConceptsPerformance Analysis 
Prof. A. Syed Mustafa (Ph.D)
137 
Basic ConceptsPerformance Analysis 
Prof. A. Syed Mustafa (Ph.D)
138 
Basic ConceptsPerformance Analysis 
Prof. A. Syed Mustafa (Ph.D)
139 
Basic ConceptsPerformance Analysis 
Prof. A. Syed Mustafa (Ph.D)
140 
Basic ConceptsPerformance Analysis 
Prof. A. Syed Mustafa (Ph.D)
141 
Basic ConceptsPerformance Analysis 
Prof. A. Syed Mustafa (Ph.D)
142 
Basic ConceptsPerformance Analysis 
Prof. A. Syed Mustafa (Ph.D)
143 
Basic ConceptsPerformance Analysis 
Prof. A. Syed Mustafa (Ph.D)
144 
Basic ConceptsPerformance Analysis 
Prof. A. Syed Mustafa (Ph.D)
145 
Basic ConceptsPerformance Analysis 
Prof. A. Syed Mustafa (Ph.D)
146 
Basic ConceptsPerformance Analysis 
Prof. A. Syed Mustafa (Ph.D)
147 
Basic ConceptsPerformance Analysis 
Prof. A. Syed Mustafa (Ph.D)
148 
Basic ConceptsPerformance Analysis 
Prof. A. Syed Mustafa (Ph.D)
149 
Basic ConceptsPerformance Analysis 
Prof. A. Syed Mustafa (Ph.D)
150 
Basic ConceptsPerformance Analysis 
Prof. A. Syed Mustafa (Ph.D)
151 
Basic ConceptsPerformance Analysis 
Prof. A. Syed Mustafa (Ph.D)
152 
Basic ConceptsPerformance Analysis 
Prof. A. Syed Mustafa (Ph.D)
153 
Basic ConceptsPerformance Analysis 
Prof. A. Syed Mustafa (Ph.D)
154 
Basic ConceptsPerformance Analysis 
Prof. A. Syed Mustafa (Ph.D)
155 
Basic ConceptsPerformance Analysis 
Prof. A. Syed Mustafa (Ph.D)
156 
Basic ConceptsPerformance Analysis 
Prof. A. Syed Mustafa (Ph.D)
157 
Basic ConceptsPerformance Analysis 
Prof. A. Syed Mustafa (Ph.D)
158 
Basic ConceptsPerformance Analysis 
Prof. A. Syed Mustafa (Ph.D)
159 
Basic ConceptsPerformance Analysis 
Prof. A. Syed Mustafa (Ph.D)
160 
Basic ConceptsPerformance Analysis 
Prof. A. Syed Mustafa (Ph.D)
161 
Basic ConceptsPerformance Analysis 
Prof. A. Syed Mustafa (Ph.D)
162 
Basic ConceptsPerformance Analysis 
Prof. A. Syed Mustafa (Ph.D)
Prof. A. Syed Mustafa (Ph.D) 163

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

Recursion in c
Recursion in cRecursion in c
Recursion in c
 
User defined functions in C
User defined functions in CUser defined functions in C
User defined functions in C
 
Function in C
Function in CFunction in C
Function in C
 
Functions in c
Functions in cFunctions in c
Functions in c
 
Prsentation on functions
Prsentation on functionsPrsentation on functions
Prsentation on functions
 
Programming Fundamentals Functions in C and types
Programming Fundamentals  Functions in C  and typesProgramming Fundamentals  Functions in C  and types
Programming Fundamentals Functions in C and types
 
Functions
FunctionsFunctions
Functions
 
Presentation on Function in C Programming
Presentation on Function in C ProgrammingPresentation on Function in C Programming
Presentation on Function in C Programming
 
Function in C Language
Function in C Language Function in C Language
Function in C Language
 
user defined function
user defined functionuser defined function
user defined function
 
Lecture20 user definedfunctions.ppt
Lecture20 user definedfunctions.pptLecture20 user definedfunctions.ppt
Lecture20 user definedfunctions.ppt
 
RECURSION IN C
RECURSION IN C RECURSION IN C
RECURSION IN C
 
predefined and user defined functions
predefined and user defined functionspredefined and user defined functions
predefined and user defined functions
 
Introduction to c
Introduction to cIntroduction to c
Introduction to c
 
Functions in C
Functions in CFunctions in C
Functions in C
 
functions in C and types
functions in C and typesfunctions in C and types
functions in C and types
 
Function
FunctionFunction
Function
 
Function lecture
Function lectureFunction lecture
Function lecture
 
Function in c
Function in cFunction in c
Function in c
 
Function in c
Function in cFunction in c
Function in c
 

Destacado

Introduction to trees
Introduction to treesIntroduction to trees
Introduction to treesRajendran
 
C++ Programming Course
C++ Programming CourseC++ Programming Course
C++ Programming CourseDennis Chang
 
Graphics in C programming
Graphics in C programmingGraphics in C programming
Graphics in C programmingKamal Acharya
 
Chapter 4 Form Factors Power Supplies
Chapter 4 Form Factors Power SuppliesChapter 4 Form Factors Power Supplies
Chapter 4 Form Factors Power SuppliesPatty Ramsey
 
Guidelines for Modelling Groundwater Surface Water Interaction in eWater Source
Guidelines for Modelling Groundwater Surface Water Interaction in eWater SourceGuidelines for Modelling Groundwater Surface Water Interaction in eWater Source
Guidelines for Modelling Groundwater Surface Water Interaction in eWater SourceeWater
 
Ch7(publishing my sql data on the web)
Ch7(publishing my sql data on the web)Ch7(publishing my sql data on the web)
Ch7(publishing my sql data on the web)Chhom Karath
 
5 Accessing Information Resources
5 Accessing Information Resources5 Accessing Information Resources
5 Accessing Information ResourcesPatty Ramsey
 
Ch3(working with file)
Ch3(working with file)Ch3(working with file)
Ch3(working with file)Chhom Karath
 
Groundwater Research and Technology, Stefan Schuster
Groundwater Research and Technology, Stefan SchusterGroundwater Research and Technology, Stefan Schuster
Groundwater Research and Technology, Stefan SchusterTXGroundwaterSummit
 
final emoji-board EMAIL ME NOWSWAG11
final emoji-board EMAIL ME NOWSWAG11final emoji-board EMAIL ME NOWSWAG11
final emoji-board EMAIL ME NOWSWAG11Joe Humphreys
 
Chapter 10 Synchronous Communication
Chapter 10 Synchronous CommunicationChapter 10 Synchronous Communication
Chapter 10 Synchronous CommunicationPatty Ramsey
 
Chapter 9 Asynchronous Communication
Chapter 9 Asynchronous CommunicationChapter 9 Asynchronous Communication
Chapter 9 Asynchronous CommunicationPatty Ramsey
 
Appendex b
Appendex bAppendex b
Appendex bswavicky
 
Preparing LiDAR for Use in ArcGIS 10.1 with the Data Interoperability Extension
Preparing LiDAR for Use in ArcGIS 10.1 with the Data Interoperability ExtensionPreparing LiDAR for Use in ArcGIS 10.1 with the Data Interoperability Extension
Preparing LiDAR for Use in ArcGIS 10.1 with the Data Interoperability ExtensionSafe Software
 
WE1.L10 - GRACE Applications to Regional Hydrology and Water Resources
WE1.L10 - GRACE Applications to Regional Hydrology and Water ResourcesWE1.L10 - GRACE Applications to Regional Hydrology and Water Resources
WE1.L10 - GRACE Applications to Regional Hydrology and Water Resourcesgrssieee
 
Survey Grade LiDAR Technologies for Transportation Engineering
Survey Grade LiDAR Technologies for Transportation EngineeringSurvey Grade LiDAR Technologies for Transportation Engineering
Survey Grade LiDAR Technologies for Transportation EngineeringQuantum Spatial
 

Destacado (20)

Introduction to trees
Introduction to treesIntroduction to trees
Introduction to trees
 
C++ Programming Course
C++ Programming CourseC++ Programming Course
C++ Programming Course
 
Graphics in C programming
Graphics in C programmingGraphics in C programming
Graphics in C programming
 
Introduction to graphics programming in c
Introduction to graphics programming in cIntroduction to graphics programming in c
Introduction to graphics programming in c
 
Chapter 4 Form Factors Power Supplies
Chapter 4 Form Factors Power SuppliesChapter 4 Form Factors Power Supplies
Chapter 4 Form Factors Power Supplies
 
Guidelines for Modelling Groundwater Surface Water Interaction in eWater Source
Guidelines for Modelling Groundwater Surface Water Interaction in eWater SourceGuidelines for Modelling Groundwater Surface Water Interaction in eWater Source
Guidelines for Modelling Groundwater Surface Water Interaction in eWater Source
 
Ch7(publishing my sql data on the web)
Ch7(publishing my sql data on the web)Ch7(publishing my sql data on the web)
Ch7(publishing my sql data on the web)
 
5 Accessing Information Resources
5 Accessing Information Resources5 Accessing Information Resources
5 Accessing Information Resources
 
Ch3(working with file)
Ch3(working with file)Ch3(working with file)
Ch3(working with file)
 
Groundwater Research and Technology, Stefan Schuster
Groundwater Research and Technology, Stefan SchusterGroundwater Research and Technology, Stefan Schuster
Groundwater Research and Technology, Stefan Schuster
 
final emoji-board EMAIL ME NOWSWAG11
final emoji-board EMAIL ME NOWSWAG11final emoji-board EMAIL ME NOWSWAG11
final emoji-board EMAIL ME NOWSWAG11
 
Chapter 10 Synchronous Communication
Chapter 10 Synchronous CommunicationChapter 10 Synchronous Communication
Chapter 10 Synchronous Communication
 
Chapter 9 Asynchronous Communication
Chapter 9 Asynchronous CommunicationChapter 9 Asynchronous Communication
Chapter 9 Asynchronous Communication
 
Chapter 5 Input
Chapter 5 InputChapter 5 Input
Chapter 5 Input
 
Appendex b
Appendex bAppendex b
Appendex b
 
Intermediate PHP
Intermediate PHPIntermediate PHP
Intermediate PHP
 
Preparing LiDAR for Use in ArcGIS 10.1 with the Data Interoperability Extension
Preparing LiDAR for Use in ArcGIS 10.1 with the Data Interoperability ExtensionPreparing LiDAR for Use in ArcGIS 10.1 with the Data Interoperability Extension
Preparing LiDAR for Use in ArcGIS 10.1 with the Data Interoperability Extension
 
WE1.L10 - GRACE Applications to Regional Hydrology and Water Resources
WE1.L10 - GRACE Applications to Regional Hydrology and Water ResourcesWE1.L10 - GRACE Applications to Regional Hydrology and Water Resources
WE1.L10 - GRACE Applications to Regional Hydrology and Water Resources
 
Unix Master
Unix MasterUnix Master
Unix Master
 
Survey Grade LiDAR Technologies for Transportation Engineering
Survey Grade LiDAR Technologies for Transportation EngineeringSurvey Grade LiDAR Technologies for Transportation Engineering
Survey Grade LiDAR Technologies for Transportation Engineering
 

Similar a Data Structure with C

Agile performance engineering with cloud 2016
Agile performance engineering with cloud   2016Agile performance engineering with cloud   2016
Agile performance engineering with cloud 2016Ken Chan
 
DSA 1- Introduction.pdf
DSA 1- Introduction.pdfDSA 1- Introduction.pdf
DSA 1- Introduction.pdfAliyanAbbas1
 
Presentation 7.pptx
Presentation 7.pptxPresentation 7.pptx
Presentation 7.pptxShivam327815
 
Dynamic Memory Allocation, Pointers and Functions, Pointers and Structures
Dynamic Memory Allocation, Pointers and Functions, Pointers and StructuresDynamic Memory Allocation, Pointers and Functions, Pointers and Structures
Dynamic Memory Allocation, Pointers and Functions, Pointers and StructuresSelvaraj Seerangan
 
The Diabolical Developers Guide to Performance Tuning
The Diabolical Developers Guide to Performance TuningThe Diabolical Developers Guide to Performance Tuning
The Diabolical Developers Guide to Performance TuningjClarity
 
Learning Software Performance Models for Dynamic and Uncertain Environments
Learning Software Performance Models for Dynamic and Uncertain EnvironmentsLearning Software Performance Models for Dynamic and Uncertain Environments
Learning Software Performance Models for Dynamic and Uncertain EnvironmentsPooyan Jamshidi
 
Rapid pruning of search space through hierarchical matching
Rapid pruning of search space through hierarchical matchingRapid pruning of search space through hierarchical matching
Rapid pruning of search space through hierarchical matchinglucenerevolution
 
Using SigOpt to Tune Deep Learning Models with Nervana Cloud
Using SigOpt to Tune Deep Learning Models with Nervana CloudUsing SigOpt to Tune Deep Learning Models with Nervana Cloud
Using SigOpt to Tune Deep Learning Models with Nervana CloudSigOpt
 
The process of software engineering
The process of software engineeringThe process of software engineering
The process of software engineeringJohn Lynch
 
Using Bayesian Optimization to Tune Machine Learning Models
Using Bayesian Optimization to Tune Machine Learning ModelsUsing Bayesian Optimization to Tune Machine Learning Models
Using Bayesian Optimization to Tune Machine Learning ModelsScott Clark
 
Using Bayesian Optimization to Tune Machine Learning Models
Using Bayesian Optimization to Tune Machine Learning ModelsUsing Bayesian Optimization to Tune Machine Learning Models
Using Bayesian Optimization to Tune Machine Learning ModelsSigOpt
 
files_1575611773_2100523175.pdf
files_1575611773_2100523175.pdffiles_1575611773_2100523175.pdf
files_1575611773_2100523175.pdfbeherapravat936
 
Machine learning key to your formulation challenges
Machine learning key to your formulation challengesMachine learning key to your formulation challenges
Machine learning key to your formulation challengesMarc Borowczak
 

Similar a Data Structure with C (20)

Functions with heap and stack
Functions with heap and stackFunctions with heap and stack
Functions with heap and stack
 
Agile performance engineering with cloud 2016
Agile performance engineering with cloud   2016Agile performance engineering with cloud   2016
Agile performance engineering with cloud 2016
 
AutoML lectures (ACDL 2019)
AutoML lectures (ACDL 2019)AutoML lectures (ACDL 2019)
AutoML lectures (ACDL 2019)
 
DSA 1- Introduction.pdf
DSA 1- Introduction.pdfDSA 1- Introduction.pdf
DSA 1- Introduction.pdf
 
Presentation 7.pptx
Presentation 7.pptxPresentation 7.pptx
Presentation 7.pptx
 
Dynamic Memory Allocation, Pointers and Functions, Pointers and Structures
Dynamic Memory Allocation, Pointers and Functions, Pointers and StructuresDynamic Memory Allocation, Pointers and Functions, Pointers and Structures
Dynamic Memory Allocation, Pointers and Functions, Pointers and Structures
 
The Diabolical Developers Guide to Performance Tuning
The Diabolical Developers Guide to Performance TuningThe Diabolical Developers Guide to Performance Tuning
The Diabolical Developers Guide to Performance Tuning
 
Be cse
Be cseBe cse
Be cse
 
Learning Software Performance Models for Dynamic and Uncertain Environments
Learning Software Performance Models for Dynamic and Uncertain EnvironmentsLearning Software Performance Models for Dynamic and Uncertain Environments
Learning Software Performance Models for Dynamic and Uncertain Environments
 
Defuzzification
DefuzzificationDefuzzification
Defuzzification
 
Rapid pruning of search space through hierarchical matching
Rapid pruning of search space through hierarchical matchingRapid pruning of search space through hierarchical matching
Rapid pruning of search space through hierarchical matching
 
Scolari's ICCD17 Talk
Scolari's ICCD17 TalkScolari's ICCD17 Talk
Scolari's ICCD17 Talk
 
Using SigOpt to Tune Deep Learning Models with Nervana Cloud
Using SigOpt to Tune Deep Learning Models with Nervana CloudUsing SigOpt to Tune Deep Learning Models with Nervana Cloud
Using SigOpt to Tune Deep Learning Models with Nervana Cloud
 
thesis
thesisthesis
thesis
 
The process of software engineering
The process of software engineeringThe process of software engineering
The process of software engineering
 
Using Bayesian Optimization to Tune Machine Learning Models
Using Bayesian Optimization to Tune Machine Learning ModelsUsing Bayesian Optimization to Tune Machine Learning Models
Using Bayesian Optimization to Tune Machine Learning Models
 
Using Bayesian Optimization to Tune Machine Learning Models
Using Bayesian Optimization to Tune Machine Learning ModelsUsing Bayesian Optimization to Tune Machine Learning Models
Using Bayesian Optimization to Tune Machine Learning Models
 
Final Document
Final DocumentFinal Document
Final Document
 
files_1575611773_2100523175.pdf
files_1575611773_2100523175.pdffiles_1575611773_2100523175.pdf
files_1575611773_2100523175.pdf
 
Machine learning key to your formulation challenges
Machine learning key to your formulation challengesMachine learning key to your formulation challenges
Machine learning key to your formulation challenges
 

Más de Syed Mustafa

BPOPS203 PRINCIPLES OF PROGRAMMING USING C LAB Manual.pdf
BPOPS203 PRINCIPLES OF PROGRAMMING USING C LAB Manual.pdfBPOPS203 PRINCIPLES OF PROGRAMMING USING C LAB Manual.pdf
BPOPS203 PRINCIPLES OF PROGRAMMING USING C LAB Manual.pdfSyed Mustafa
 
18CSL58 DBMS LAB Manual.pdf
18CSL58 DBMS LAB Manual.pdf18CSL58 DBMS LAB Manual.pdf
18CSL58 DBMS LAB Manual.pdfSyed Mustafa
 
Syed IoT - module 5
Syed  IoT - module 5Syed  IoT - module 5
Syed IoT - module 5Syed Mustafa
 
15CS81- IoT- VTU- module 3
15CS81- IoT- VTU- module 315CS81- IoT- VTU- module 3
15CS81- IoT- VTU- module 3Syed Mustafa
 
15CS81- IoT Module-2
15CS81- IoT Module-215CS81- IoT Module-2
15CS81- IoT Module-2Syed Mustafa
 
Internet of Things - module 1
Internet of Things -  module 1Internet of Things -  module 1
Internet of Things - module 1Syed Mustafa
 
15CS664- Python Application Programming- Question bank 1
15CS664- Python Application Programming- Question bank 115CS664- Python Application Programming- Question bank 1
15CS664- Python Application Programming- Question bank 1Syed Mustafa
 
15CS664- Python Application Programming VTU syllabus
15CS664- Python Application Programming  VTU syllabus15CS664- Python Application Programming  VTU syllabus
15CS664- Python Application Programming VTU syllabusSyed Mustafa
 
15CS664- Python Application Programming - Module 3
15CS664- Python Application Programming - Module 315CS664- Python Application Programming - Module 3
15CS664- Python Application Programming - Module 3Syed Mustafa
 
15CS664-Python Application Programming - Module 3 and 4
15CS664-Python Application Programming - Module 3 and 415CS664-Python Application Programming - Module 3 and 4
15CS664-Python Application Programming - Module 3 and 4Syed Mustafa
 
15CS664 Python Question Bank-3
15CS664 Python Question Bank-315CS664 Python Question Bank-3
15CS664 Python Question Bank-3Syed Mustafa
 
Data structures lab manual
Data structures lab manualData structures lab manual
Data structures lab manualSyed Mustafa
 
Grid computing notes
Grid computing notesGrid computing notes
Grid computing notesSyed Mustafa
 
Unix system programming
Unix system programmingUnix system programming
Unix system programmingSyed Mustafa
 
answer-model-qp-15-pcd13pcd
answer-model-qp-15-pcd13pcdanswer-model-qp-15-pcd13pcd
answer-model-qp-15-pcd13pcdSyed Mustafa
 
VTU PCD Model Question Paper - Programming in C
VTU PCD Model Question Paper - Programming in CVTU PCD Model Question Paper - Programming in C
VTU PCD Model Question Paper - Programming in CSyed Mustafa
 
Data structures lab c programs
Data structures lab  c programsData structures lab  c programs
Data structures lab c programsSyed Mustafa
 
Infix prefix postfix expression -conversion
Infix  prefix postfix expression -conversionInfix  prefix postfix expression -conversion
Infix prefix postfix expression -conversionSyed Mustafa
 

Más de Syed Mustafa (20)

BPOPS203 PRINCIPLES OF PROGRAMMING USING C LAB Manual.pdf
BPOPS203 PRINCIPLES OF PROGRAMMING USING C LAB Manual.pdfBPOPS203 PRINCIPLES OF PROGRAMMING USING C LAB Manual.pdf
BPOPS203 PRINCIPLES OF PROGRAMMING USING C LAB Manual.pdf
 
18CSL58 DBMS LAB Manual.pdf
18CSL58 DBMS LAB Manual.pdf18CSL58 DBMS LAB Manual.pdf
18CSL58 DBMS LAB Manual.pdf
 
Syed IoT - module 5
Syed  IoT - module 5Syed  IoT - module 5
Syed IoT - module 5
 
IoT - module 4
IoT - module 4IoT - module 4
IoT - module 4
 
15CS81- IoT- VTU- module 3
15CS81- IoT- VTU- module 315CS81- IoT- VTU- module 3
15CS81- IoT- VTU- module 3
 
15CS81- IoT Module-2
15CS81- IoT Module-215CS81- IoT Module-2
15CS81- IoT Module-2
 
Internet of Things - module 1
Internet of Things -  module 1Internet of Things -  module 1
Internet of Things - module 1
 
15CS664- Python Application Programming- Question bank 1
15CS664- Python Application Programming- Question bank 115CS664- Python Application Programming- Question bank 1
15CS664- Python Application Programming- Question bank 1
 
15CS664- Python Application Programming VTU syllabus
15CS664- Python Application Programming  VTU syllabus15CS664- Python Application Programming  VTU syllabus
15CS664- Python Application Programming VTU syllabus
 
15CS664- Python Application Programming - Module 3
15CS664- Python Application Programming - Module 315CS664- Python Application Programming - Module 3
15CS664- Python Application Programming - Module 3
 
15CS664-Python Application Programming - Module 3 and 4
15CS664-Python Application Programming - Module 3 and 415CS664-Python Application Programming - Module 3 and 4
15CS664-Python Application Programming - Module 3 and 4
 
15CS664 Python Question Bank-3
15CS664 Python Question Bank-315CS664 Python Question Bank-3
15CS664 Python Question Bank-3
 
Data structures lab manual
Data structures lab manualData structures lab manual
Data structures lab manual
 
Usp notes unit6-8
Usp notes unit6-8Usp notes unit6-8
Usp notes unit6-8
 
Grid computing notes
Grid computing notesGrid computing notes
Grid computing notes
 
Unix system programming
Unix system programmingUnix system programming
Unix system programming
 
answer-model-qp-15-pcd13pcd
answer-model-qp-15-pcd13pcdanswer-model-qp-15-pcd13pcd
answer-model-qp-15-pcd13pcd
 
VTU PCD Model Question Paper - Programming in C
VTU PCD Model Question Paper - Programming in CVTU PCD Model Question Paper - Programming in C
VTU PCD Model Question Paper - Programming in C
 
Data structures lab c programs
Data structures lab  c programsData structures lab  c programs
Data structures lab c programs
 
Infix prefix postfix expression -conversion
Infix  prefix postfix expression -conversionInfix  prefix postfix expression -conversion
Infix prefix postfix expression -conversion
 

Último

Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseAnaAcapella
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxJisc
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxEsquimalt MFRC
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsKarakKing
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxDr. Ravikiran H M Gowda
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxPooja Bhuva
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptxMaritesTamaniVerdade
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the ClassroomPooky Knightsmith
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxAmanpreet Kaur
 

Último (20)

Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 

Data Structure with C

  • 1. 1
  • 2. 2
  • 3. Syllabus 3 Prof. A. Syed Mustafa (Ph.D)
  • 4. Syllabus 4 Prof. A. Syed Mustafa (Ph.D)
  • 5. Syllabus 5 Prof. A. Syed Mustafa (Ph.D)
  • 6. Syllabus 6 Prof. A. Syed Mustafa (Ph.D)
  • 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.
  • 18. 18 •ForanytypeTinCthereisacorrespondingtypepointer-to-T. •Theactualvalueofapointertypeisanaddressofmemory. –&theaddressoperator. –*thedereferencing(orindirection)operator. –Declaration •inti,*ip;//iisanintegervariableandipisapointertoaninteger. •ip=&i; then&ireturnstheaddressofiandassignsitasthevalueofpi. Basic ConceptsPointers Prof. A. Syed Mustafa (Ph.D)
  • 19. 19 Basic ConceptsPointers •i=10or*ip=10; Inbothcasestheinteger10isstoredasthevalueofi. Insecondcase,the*infrontofthepointeripcausesittobedereferenced, bywhichwemeanthatinsteadofstoring10intothepointer,10isstoredintothelocationpointedatbythepointerip. Prof. A. Syed Mustafa (Ph.D)
  • 20. 20 Basic ConceptsPointers Thesizeofapointercanbedifferentondifferentcomputers. Thesizeofapointertoacharcanbelongerthanapointertoafloat. TestforthenullpointerinC if(ip==NULL)orif(ip==0)orif(!ip)
  • 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)
  • 35. 35 Basic ConceptsDynamic Memory Allocation Prof. A. Syed Mustafa (Ph.D)
  • 36. 36 Basic ConceptsDynamic Memory Allocation Prof. A. Syed Mustafa (Ph.D)
  • 37. 37 Basic ConceptsDynamic Memory Allocation Prof. A. Syed Mustafa (Ph.D)
  • 38. 38 Basic ConceptsDynamic Memory Allocation Prof. A. Syed Mustafa (Ph.D)
  • 39. 39 Basic ConceptsDynamic Memory Allocation realloc() -Reallocate memory block void*realloc(void*ptr,size_tsize) •TheClibraryfunctionattemptstoresizethememoryblockpointedtobyptrthatwaspreviouslyallocatedwithacalltomallocorcallocorrealloc Parameters ptr--Thisisthepointertoamemoryblockpreviouslyallocatedwithmalloc,callocorrealloctobereallocated.IfthisisNULL,anewblockisallocatedandapointertoitisreturnedbythefunction •size--Thisisthenewsizeforthememoryblock,inbytes.Ifitis0andptrpointstoanexistingblockofmemory,thememoryblockpointedbyptrisdeallocatedandaNULLpointerisreturned. ReturnValue Thisfunctionreturnsapointertothenewlyallocatedmemory,orNULLiftherequestfails. Prof. A. Syed Mustafa (Ph.D)
  • 40. 40 Basic ConceptsDynamic Memory Allocation realloc() -Reallocate memory block •Thefunctionrealloc()reallocatesamemoryblockwithaspecificnewsize. •Ifwecallrealloc()thesizeofthememoryblockpointedtobythepointerischangedtothegivensizeinbytes. •Thiswayweareabletoexpandandreducetheamountofmemoryyouwanttouse(ifavailableofcourse.) •Itispossiblethatthefunctionmovesthememoryblocktoanewlocation, inwhichwaythefunctionwillreturnthisnewlocation. •Ifthesizeoftherequestedblockislargerthenthepreviousblockthenthevalueofthenewportionisindeterminate. Prof. A. Syed Mustafa (Ph.D)
  • 41. 41 Basic ConceptsDynamic Memory Allocation realloc() -Reallocate memory block •Thereturnvalueisapointertothereallocatedmemoryblock,whichmaybeeitherthesameasptroranewlocation. •Thetypeofreturnpointerisvoid*,whichcanbecasttothedesiredtypeofdatapointerinordertobedereferenceable •IfthepointerisNULLthenthefunctionwillbehaveexactlylikethefunctionmalloc().Itwillassignanewblockofasizeinbytesandwillreturnapointertoit. •Ifthesizeis0thenthememorythatwaspreviouslyallocatedisfreedasifacallofthefunctionfree()wasgiven.ItwillreturnaNULLpointerinthatcase. Prof. A. Syed Mustafa (Ph.D)
  • 42. 42 •. #include<stdlib.h> #include<stdio.h> intmain() {char*str; str=(char*)malloc(4);/* Initial memory allocation */ strcpy(str,“data"); printf("String = %s, Address = %pn",str,str); /* Reallocating memory */ str=(char*)realloc(str,13); strcat(str,“structure"); printf("String = %s, Address = %pn",str,str); free(str); return(0); } Basic ConceptsDynamic Memory Allocation 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)
  • 44. 44 Basic ConceptsDynamic Memory Allocation free() /* example */ #include <stdlib.h> /* malloc, calloc, realloc, free */ intmain () { int* i1, * i2, * i3; i1 = (int*) malloc(100*sizeof(int)); i2 = (int*) calloc(100,sizeof(int)); i3 = (int*) realloc(i2,500*sizeof(int)); free (i1); free (i3); return 0; } 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)
  • 57. 57 Basic ConceptsAlgorithm Specification Binary Search. 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)
  • 67. 67 Basic ConceptsAlgorithm Specification Prof. A. Syed Mustafa (Ph.D)
  • 68. 68 Basic ConceptsAlgorithm Specification 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)
  • 76. 76 Basic ConceptsAlgorithm Specification Prof. A. Syed Mustafa (Ph.D)
  • 77. 77 Basic ConceptsAlgorithm Specification Prof. A. Syed Mustafa (Ph.D)
  • 78. 78 Basic ConceptsAlgorithm Specification Prof. A. Syed Mustafa (Ph.D)
  • 79. 79 Basic ConceptsAlgorithm Specification Recursive program: Fibonacci intmain() { intn=10; printf(“%d”, rfib(n)); } intrfib(intn) { if (n==1 || n==2) return 1; return rfib(n1) + rfib(n2); } Prof. A. Syed Mustafa (Ph.D)
  • 80. 80 Basic ConceptsAlgorithm Specification Recursive program: Fibonacci Prof. A. Syed Mustafa (Ph.D)
  • 81. 81 Basic ConceptsAlgorithm Specification Recursive program: Fibonacci Prof. A. Syed Mustafa (Ph.D)
  • 82. 82 Basic ConceptsAlgorithm Specification Recursive program: Fibonacci 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)
  • 88. 88 Basic ConceptsAlgorithm Specification Recursive algorithm 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)
  • 102. 102 Basic ConceptsData Abstraction Prof. A. Syed Mustafa (Ph.D)
  • 103. 103 Basic ConceptsData Abstraction Prof. A. Syed Mustafa (Ph.D)
  • 104. 104 Basic ConceptsData Abstraction Prof. A. Syed Mustafa (Ph.D)
  • 105. 105 Basic ConceptsData Abstraction Prof. A. Syed Mustafa (Ph.D)
  • 106. 106 Basic ConceptsData Abstraction Prof. A. Syed Mustafa (Ph.D)
  • 107. 107 Basic ConceptsData Abstraction Prof. A. Syed Mustafa (Ph.D)
  • 108. 108 Basic ConceptsData Abstraction Prof. A. Syed Mustafa (Ph.D)
  • 109. 109 Basic ConceptsData Abstraction Prof. A. Syed Mustafa (Ph.D)
  • 110. 110 Basic ConceptsData Abstraction Prof. A. Syed Mustafa (Ph.D)
  • 111. 111 Basic ConceptsData Abstraction Prof. A. Syed Mustafa (Ph.D)
  • 112. 112 Basic ConceptsPerformance Analysis 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 ?
  • 114. 114 Basic ConceptsPerformance Analysis Prof. A. Syed Mustafa (Ph.D)
  • 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
  • 116. 116 Basic ConceptsPerformance Analysis Prof. A. Syed Mustafa (Ph.D)
  • 117. 117 Basic ConceptsPerformance Analysis Prof. A. Syed Mustafa (Ph.D)
  • 118. 118 Basic ConceptsPerformance Analysis Prof. A. Syed Mustafa (Ph.D)
  • 119. 119 Basic ConceptsPerformance Analysis Prof. A. Syed Mustafa (Ph.D)
  • 120. 120 Basic ConceptsPerformance Analysis Prof. A. Syed Mustafa (Ph.D)
  • 121. 121 Basic ConceptsPerformance Analysis Prof. A. Syed Mustafa (Ph.D)
  • 122. 122 Basic ConceptsPerformance Analysis Prof. A. Syed Mustafa (Ph.D)
  • 123. 123 Basic ConceptsPerformance Analysis Prof. A. Syed Mustafa (Ph.D)
  • 124. 124 Basic ConceptsPerformance Analysis Prof. A. Syed Mustafa (Ph.D)
  • 125. 125 Basic ConceptsPerformance Analysis Prof. A. Syed Mustafa (Ph.D)
  • 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.
  • 127. 127 Basic ConceptsPerformance Analysis Prof. A. Syed Mustafa (Ph.D)
  • 128. 128 Basic ConceptsPerformance Analysis Prof. A. Syed Mustafa (Ph.D)
  • 129. 129 Basic ConceptsPerformance Analysis Prof. A. Syed Mustafa (Ph.D)
  • 130. 130 Basic ConceptsPerformance Analysis Prof. A. Syed Mustafa (Ph.D)
  • 131. 131 Basic ConceptsPerformance Analysis Prof. A. Syed Mustafa (Ph.D)
  • 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.
  • 134. 134 Basic ConceptsPerformance Analysis Prof. A. Syed Mustafa (Ph.D)
  • 135. 135 Basic ConceptsPerformance Analysis Prof. A. Syed Mustafa (Ph.D)
  • 136. 136 Basic ConceptsPerformance Analysis Prof. A. Syed Mustafa (Ph.D)
  • 137. 137 Basic ConceptsPerformance Analysis Prof. A. Syed Mustafa (Ph.D)
  • 138. 138 Basic ConceptsPerformance Analysis Prof. A. Syed Mustafa (Ph.D)
  • 139. 139 Basic ConceptsPerformance Analysis Prof. A. Syed Mustafa (Ph.D)
  • 140. 140 Basic ConceptsPerformance Analysis Prof. A. Syed Mustafa (Ph.D)
  • 141. 141 Basic ConceptsPerformance Analysis Prof. A. Syed Mustafa (Ph.D)
  • 142. 142 Basic ConceptsPerformance Analysis Prof. A. Syed Mustafa (Ph.D)
  • 143. 143 Basic ConceptsPerformance Analysis Prof. A. Syed Mustafa (Ph.D)
  • 144. 144 Basic ConceptsPerformance Analysis Prof. A. Syed Mustafa (Ph.D)
  • 145. 145 Basic ConceptsPerformance Analysis Prof. A. Syed Mustafa (Ph.D)
  • 146. 146 Basic ConceptsPerformance Analysis Prof. A. Syed Mustafa (Ph.D)
  • 147. 147 Basic ConceptsPerformance Analysis Prof. A. Syed Mustafa (Ph.D)
  • 148. 148 Basic ConceptsPerformance Analysis Prof. A. Syed Mustafa (Ph.D)
  • 149. 149 Basic ConceptsPerformance Analysis Prof. A. Syed Mustafa (Ph.D)
  • 150. 150 Basic ConceptsPerformance Analysis Prof. A. Syed Mustafa (Ph.D)
  • 151. 151 Basic ConceptsPerformance Analysis Prof. A. Syed Mustafa (Ph.D)
  • 152. 152 Basic ConceptsPerformance Analysis Prof. A. Syed Mustafa (Ph.D)
  • 153. 153 Basic ConceptsPerformance Analysis Prof. A. Syed Mustafa (Ph.D)
  • 154. 154 Basic ConceptsPerformance Analysis Prof. A. Syed Mustafa (Ph.D)
  • 155. 155 Basic ConceptsPerformance Analysis Prof. A. Syed Mustafa (Ph.D)
  • 156. 156 Basic ConceptsPerformance Analysis Prof. A. Syed Mustafa (Ph.D)
  • 157. 157 Basic ConceptsPerformance Analysis Prof. A. Syed Mustafa (Ph.D)
  • 158. 158 Basic ConceptsPerformance Analysis Prof. A. Syed Mustafa (Ph.D)
  • 159. 159 Basic ConceptsPerformance Analysis Prof. A. Syed Mustafa (Ph.D)
  • 160. 160 Basic ConceptsPerformance Analysis Prof. A. Syed Mustafa (Ph.D)
  • 161. 161 Basic ConceptsPerformance Analysis Prof. A. Syed Mustafa (Ph.D)
  • 162. 162 Basic ConceptsPerformance Analysis Prof. A. Syed Mustafa (Ph.D)
  • 163. Prof. A. Syed Mustafa (Ph.D) 163