Data Structure Unit 1
Data Structure Unit 1
CS2001
UNIT 1 - INTRODUCTION
CONTENT:
• Broad categories:
• Linear DS: elements are accessed in sequential manner not
necessarily stored in sequential manner too. E.g. Arrays, lists.
• Non Linear DS: stored/accessed in non linear manner. E.g.
Graph and trees.
DATA STRUCTURE TYPES
• Another Categorization:
• Primitive data types:
(integer, float, character)
• Derived data types: uses primitive types
(Array, pointers, structure, union)
ABSTRACT DATA TYPE (ADT)
• Characteristics of an Algorithm:
• May take zero or more number of inputs
• The sequence of steps is well defined and each step produces
a definite effect
• Contains finite number of steps
• Must have a termination point
• May produce one or more outputs
EXAMPLE
• Worst case
The input set for which an algorithm takes maximum
time and effort to execute
• Best case
The input sets for which an algorithm takes minimum
time and effort to execute
• Average case
The input sets for which an algorithm takes average
time and effort to execute
INPUT VS ALGO WORKLOAD
void insertionSort(int
array_tobe_sorted[], int array_size)
{
int i, value, j;
array_tobe_sorted[j + 1] = value;
}
}
ASYMPTOTIC NOTATIONS
• Big – „O‟
• Theta ()
• Omega ()
• Little – „o‟
• Little omega – ()
BIG – ‘O’
then, f(n)=O(g(n)),
read as, f(n) is equal to big-O g(n)
n= 1 2 3 4 5 6 7 8 9 10
n2 1 4 9 16 25 36 49 64 81 100
2n 2 4 8 16 32 64 128 256 512 1024
• Hence, f(n)=O(g(n))
i.e. g(n) is upper bound of function f(n) or f(n)≤ g(n),
asymptotically.
CONTINUED…
Similarly,
meaning, g(n) and f(n) has same order of growth for n input size
CONTINUED…
• n0 is the value of
„n‟ after which the
behavior of the
complexity of the
two functions does
not change for
each other, if other
factors remains
constant. n0
DEFINITION – BIG ‘O’
DEFINITION – OMEGA ‘’
DEFINITION – THETA ‘ ’
ARRAYS
Arrays
Two- Multi-
Linear
Dimensional Dimensional
CONTINUED…
• 1-D Arrays
• Declaring the arrays
• Storing values in an array
• Printing the values of an array
• Array Traversal
• Insertion of element
• Searching of element
• Deleting an element
• Sorting of an array
ARRAY AND POINTERS
This will print the value of element stored at index 3 of the given array
• Storing values
int arr[0][0]=5;
int arr[0][1]=7;
Int arr[2][4]={{5,7,9,0},{2,4,6,8}}
CONTINUED…
struct student
{
int r_no;
char name[20];
char course[20];
float fees;
};
DOT OPERATOR
• Nested structures
ASSIGNMENT