01 - Introduction To DS
01 - Introduction To DS
GTU # 3130702
Unit-1
Introduction to
Data Structure
Floating Pointers
Point Linear Non-linear
List List
Array
File
List
Linear / Non-Linear data structure
Linear data structures
A data structure is said to be Linear, if its elements are connected in linear fashion by means of logically or in
sequence memory locations.
Examples of Linear Data Structure are Stack and Queue.
Nonlinear data structures
Nonlinear data structures are those data structure in which data items are not arranged in a sequence.
Examples of Non-linear Data Structure are Tree and Graph.
Algorithm /
Initial Input Step wise Procedure Final Output
Example: Let us estimate the frequency count of the statement x = x+2 occurring in the
following three program segments A, B and C.
Calculate Time Complexity of Algorithm
Time Complexity is most commonly estimated by counting the number of elementary
functions performed by the algorithm.
Since the algorithm's performance may vary with different types of input data,
hence for an algorithm we usually use the worst-case Time complexity of an algorithm because that is the
maximum time taken for any input size.
Calculating Time Complexity
Calculate Time Complexity of Sum of elements of List (One dimensional Array)
A is array, n is no of elements in array
SumOfList(A,n)
{ Line Cost No of Times
Line 1 total = 0 1 1 1
Line 2 for i = 0 to n-1 2 2 n+1
Line 3 total = total + A[i] 3 2 n
Line 4 return total 4 1 1
}
TSumOfList = 1 + 2 (n+1) + 2n + 1
= 4n + 4 We can neglate constant 4
=n
f(n) = O(g(n)) ( read as f of n is big oh of g of n), if there exists a positive integer n0 and a
positive number c such that |f(n)| ≤ c |g(n)| for all n ≥ n0.
f(n) = Ω(g(n)) ( read as f of n is omega of g of n), if there exists a positive integer n0 and a
positive number c such that |f(n)| ≥ c |g(n)| for all n ≥ n0.
f(n) = Θ(g(n)) (read as f of n is theta of g of n), if there exists a positive integer n0 and two
positive constants c1 and c2 such that c1 |g(n)| ≤ |f(n)| ≤ c2 |g(n)| for all n ≥ n0.
The function g(n) is both an upper bound and a lower bound for the function f(n) for all values
of n, n ≥ n0 .
Time Complexity
Data Structures (DS)
GTU # 3130702
Thank
You