0% found this document useful (0 votes)
48 views12 pages

Lect01 102 2019

This document provides an introduction to the Data Structures course CSN-102 taught by Dr. Balasubramanian at IIT Roorkee. It outlines the syllabus, real-time applications, and importance of the course. It discusses algorithms, programs, data structures and how to evaluate them based on efficiency. It also demonstrates how to analyze the time complexity of algorithms using examples like addition and summing elements in an array. The document introduces asymptotic notation to classify algorithms based on their time complexity growth rates.

Uploaded by

Mukesh Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views12 pages

Lect01 102 2019

This document provides an introduction to the Data Structures course CSN-102 taught by Dr. Balasubramanian at IIT Roorkee. It outlines the syllabus, real-time applications, and importance of the course. It discusses algorithms, programs, data structures and how to evaluate them based on efficiency. It also demonstrates how to analyze the time complexity of algorithms using examples like addition and summing elements in an array. The document introduces asymptotic notation to classify algorithms based on their time complexity growth rates.

Uploaded by

Mukesh Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

INDIAN INSTITUTE OF TECHNOLOGY ROORKEE

Data Structures
CSN- 102

Dr. R. Balasubramanian
Professor
Department of Computer Science and Engineering
Indian Institute of Technology Roorkee
Roorkee 247 667
balarfcs@iitr.ac.in
https://sites.google.com/site/balaiitr/
CSN 102

• Syllabus

• Real Time Applications

2
Why This Course?

• You will be able to evaluate the quality of a program


(Analysis of Algorithms: Running time and memory
space )
• You will be able to write fast programs
• You will be able to solve new problems
• You will be able to give non-trivial methods to solve
problems.
(Your algorithm (program) will be faster than others.)

3
• Algorithm:
– A set of explicit, unambiguous finite steps, which when carried out
for a given set of initial condition to produce the corresponding
output and terminate in finite time.
• Program:
– An implementation of an algorithm in some programming languages
• Data Structure:
– Organization of data needed to solve the problem

4
Good Algo.’?

• Efficient
– Running Time
– Space Used
• Running time depends on
– Single vs Multi processor
– Read or Write speed to Memory
– 32 bit vs 64 bit
– Input -> rate of growth of time, Efficiency as a function of input
(number of bits in an input number, number of data elements…)

5
• Time Complexity: Amount of computation time (CPU time)
where program needs to run

• Space complexity: Amount of memory program needs to


run for completion

6
Measuring the Running Time

• The C standard library provides a function called clock (in


header file time.h) that can sometimes be used in a simple
way to time computations:
clock_t start, finish;
start = clock();
sort(x.begin(), x.end());
// Call to STL generic sort algorithm
finish = clock();
cout << "Time for sort (seconds): " <<
((double)(finish - start))/CLOCKS_PER_SEC;

7
Limitations

• It is necessary to implement and test the algorithm in order


to determine its running time.
• In order to compare two or more algorithms, the same
hardware and software environments should be used.

8
How to Analyze Time Complexity?

• Machine - Single Processor


- 32 bit
- Sequential executer
- 1 unit time for Arithmetic
and Logical Operations
- 1 unit time for assignment
and return

9
Few Examples

int Add(int a, int b)


{ return a+b;}

TAdd=1+1=2 units of
time
= Constant time

10
Sum of all elements in the list

int Sum_of_list(int A[], int n)


{int sum=0;
for (int i=0;i<n;i++)
sum=sum+A[i];
return sum; Cost No. of Times
} ---- ------------
1 1
1 1
2 n+1
2 n
1 1
11
• TSum_of_list=1+1+2(n+1)+2n+1
=4n+5

=cn+c’

• Tsum_of_Matrices =a*n^2+b*n+c

TAdd =O(1)
TSum_of_list = O(n)
Tsum_of_Matrices =O(n2)

Asymptotic Notation
12

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy