Module - 1 - PART-A
Module - 1 - PART-A
101009/IT200C (Module 1)
S2 CU
• The logical or mathematical model to organize the data in the computer memory (main
or secondary) and the method to process them are collectively called Data Structures.
• Data structure: organization or structuring of data which can be used to effectively solve
a problem.
• Flowchart
• Program
• A simple solution is - From those integers that are currently unsorted, find
the smallest and place it next in the sorted list.
• For example, it does not tell us where and how the integers are initially
stored, or where we should place the result.
• We assume that the integers are stored in an array, list, such that the ith
integer is stored in the ith position, list [i ], 0 <= i < n.
101009/IT200C _S2 CU_Module-1 DIT, RSET 9
Algorithm Example (Selection Sort)
0 1 2 3 4 5 6 7
12 5 87 25 9 65 98 34
5 12 87 25 9 65 98 34
5 9 87 25 12 65 98 34
5 9 12 25 87 65 98 34
5 9 12 25 87 65 98 34
5 9 12 25 34 65 98 87
5 9 12 25 34 65 98 87
5 9 12 25 34 65 87 98
• Two clearly defined subtasks remain: finding the smallest integer and
interchanging it with list [i]
• Indirect recursion- function that call another function that invoke the
calling function again
Step 4: decrease n
2 Highly efficient if items are in sorted form Highly efficient if items are fewer & present at the
starting of the list
3 Fast access Slow access
5 Not suitable for linked list Appropriate for both array and linked list
34 7 23 56 32 87
7 23 32 34 56 87
3. Does the program contain documentation that shows how to use it and how it
works?
Performance Analysis-
• Focus on estimating the time and space which are machine independent.
• Time complexity of a program is the amount of computer time that it needs to run
to completions.
2. Variable space requirements- consists of space needed by structured variables whose size
depends on the particular instance, I, of the problem being solved.
• Includes additional space required when a function uses recursion.
• Characteristics – number, size and values of the inputs and outputs associated with I.
101009/IT200C _S2 CU_Module-1 DIT, RSET 29
Space Complexity
• Eg: if our input is an array containing n numbers then n is an instance
characteristics.
• Total space complexity S(P) = c + Sp(I), c is the constant representing the fixed
space requirements.
• Compile time is similar to fixed space component since it does not depend on the
instance characteristics.
• Determining Tp is not an easy task because we must know how the compiler translates
our source program into object code.
• Running time – use system clock to time the program or count the number of
operations the program performs, which is machine independent, but we must know
how101009/IT200C
to divide the program into distinct
_S2 CU_Module-1 DIT, RSET steps. 33
Time Complexity
• A program step is a syntactically or semantically meaningful program segment
whose execution time is independent of the instance characteristics.
• The time required to execute each statement that is counted as one step be
independent of the instance characteristics.
• a= 2*b+3*c/d-e+g/g/a/b/c; count =1
• 1<logn<√n<n<nlogn<n2<n3….<2n<3n..<nn
101009/IT200C _S2 CU_Module-1 DIT, RSET 47
Big ‘oh’ (O)
• Definition - f(n) = O(g(n)) iff (if and only if) there exit positive constants c and n0
• Definition - f(n) = Ω(g(n)) iff (if and only if) there exit positive
constants c and n0 such that f(n) >= c. g(n) for all n, n>=n0
n>=n0
• Eg: 3n + 2 = θ(n) as 3n + 2 >=3n for all n>=2 and 3n+2<=4n for all
n>=2
--------------------------------------------------------------------------------------
sum = 0 -------------------------1
for (i=0;i<n;i++) ----------------n O(n2)
for (j=0;j<n;j++) ----------------n
sum ++ ---------1
= = n => O(n2)
_S2 CU_Module-1
101009/IT200C DIT, RSET 54
Examples
sum = 0 -------------------------1
for (i=0;i<n;i++) ----------------n O(n3)
for (j=0;j<n;j++) ----------------n
for (k=0;k<n;k++) ----------------n
sum ++ ---------1
= n = n2 => O(n3)
= n2 => O(n3)