Lecture No.06 Data Structures and Algorithms
Lecture No.06 Data Structures and Algorithms
06
1
ALGORITHM ANALYSIS
3
SIMPLE EXAMPLE
int sum( int n )
{
int partialSum;
1 partialSum = 0;
2 for( int i = 1; i <= n; ++i )
3 partialSum += i * i * i;
4 return partialSum;
}
4
SIMPLE EXAMPLE
• Declaration takes no time in the
program.
• HOMEWORK
• long fib( int n )
• {
• 1 if( n <= 1 )
8
• 2 return 1;
2.4.2 GENERAL RULES
• HOMEWORK
9
3.1 ADT’s
• An abstract data type (ADT) is a set of objects together
with a set of operations.
• ADT’S implement operations but does not know how the set
of operations is implemented. Objects such as lists, sets, and
graphs,along with their operations, can be viewed as ADTs,
just as integers, reals, and booleans are data types. Integers,
reals, and booleans have operations associated with them, and
so do ADTs. For the set ADT, we might have such operations
as add, remove, size, and contains. Alternatively, we might
only want the two operations union and find, which would
define a different ADT on the set.
11