Home Week-2

PDSA - Week 1

For Python

https://pypod.github.io/

 

Number of operation or instruction when program runs

Count the number of operation or instruction executed when program runs.

Identify the relationship between number of instructions and input size.

Our Goal - Want to reduce these numbers of instructions when program runs

 

Computing gcd

Computing gcd - Eliminate the list

Efficiency :- Both versions of gcd take time proportional to min(m, n)

Computing gcd - Better Way

Still not efficient, for example gcd(1,1000) takes 1000 steps.

Computing gcd - Euclid’s algorithm

Can show that this takes time proportional to number of digits in max(m, n)

 

Computing Prime

Counting primes

Computing Primes- Other approach

Computing Primes- Sufficient to check factors up to √ n

 

Exception handling

Our code could generate many types of errors

Types of some common errors

Handling exceptions

 

Classes and objects

Abstract datatype

Class

Object

Example

Output

 

Timer

Set recursion limit

Calculate time for large value

Why Efficiency?

Example-