© All Rights Reserved

12 views

© All Rights Reserved

- CSE565-F08-Lec-11
- CAB301_Levitin_Ch2.pdf
- algoritmos
- Alogrithm and Flowchart
- Data Algorithm Equivalence as an Approach to Natural Computing Paradigm
- hcl_2011
- preskill_1_to_6(LectureNote).pdf
- mcs-31
- Forward-Error Correction Considered Harmfu
- 05976426.pdf
- Background Subtraction
- title grade 1 my robotic friends jr-2
- Enhancement of Object Detection and Definition Using Spatio-Temporal Clustering
- np1
- practice-midterm.pdf
- 1997_Slzing, For, Items_Unknown_~ OehT
- Fundamentals of Algorithms-1
- Table of Contents.docx
- trajectory compression.pdf
- scimakelatex.4032.tototo

You are on page 1of 21

Permasalahan (latihan)

Badu menemukan peti harta karun

Utk membukanya diperlukan PIN 4 digit

PIN-nya adalah 4 digit terakhir dari 9 pa

ngkat N

Solusi 1

9 pangkat 10 = kira2 10 digit

Tidak muat dalam tipe data int

123456789 : 4 digit terakhir = 6789

How to get?

123456789 mod 10000 = 6789

Solusi 1

int N= ____;

int i, pin=1;

for(i=0;i<N;i++) {

pin=(pin*9) mod 10000;

}

printf(pin=%d\n, pin);

Solusi 2

Misal N = 13

Binary = 1101

Misal N = 12

Binary = 1110

Solusi 2

int N= ____;

int i=1, pin=1, pw2 = 9;

while(i<5) { //2^5=32

if(N%2==1)

pin=(pin*pw2) mod 10000;

pw2 = pw2 * pw2;

i++; N=N>>1;

}

printf(pin=%d\n, pin);

Solusi 1

Berjalan N loop

Solusi 2

Berjalan 6 loop

6 = jml digit utk menyimpan angka 100 (max N)

Analysis of Algorithms

Estimate the running time

Estimate the memory space required.

Time and space depend on the input size.

Analysis of Algorithms

Most algorithms transform

input objects into output o

bjects.

The running time of an alg

orithm typically grows with

the input size.

Average case time is often

difficult to determine.

We focus on the worst case

running time.

Easier to analyze

Crucial to applications such a

s games, finance and robotics

Analysis of Algorithms

10

Experimental Studies

Write a program impleme

nting the algorithm

Run the program with inp

uts of varying size and co

mposition

Use a method like System.c

urrentTimeMillis() to get an a

ccurate measure of the ac

tual running time

Plot the results

Analysis of Algorithms

11

Limitations of Experiments

It is necessary to implement the algorith

m, which may be difficult

Results may not be indicative of the run

ning time on other inputs not included i

n the experiment.

In order to compare two algorithms, th

e same hardware and software environ

ments must be used

Analysis of Algorithms

12

Theoretical Analysis

Uses a high-level description of the al

gorithm instead of an implementation

Characterizes running time as a functi

on of the input size, n.

Takes into account all possible inputs

Allows us to evaluate the speed of an

algorithm independent of the hardwa

re/software environment

Analysis of Algorithms

13

Pseudocode (3.2)

Example: find max element

of an array

High-level description

of an algorithm

More structured than Algorithm arrayMax(A, n)

Input array A of n integers

English prose

Output maximum element of A

Less detailed than a p

currentMax A[0]

rogram

for i 1 to n 1 do

Preferred notation for

if A[i] currentMax then

currentMax A[i]

describing algorithms

return currentMax

Hides program design

issues

Analysis of Algorithms

14

Pseudocode Details

Control flow

if then [else ]

while do

repeat until

for do

Indentation replaces braces

Expressions

Method declaration

Algorithm method (arg [, arg])

Input

Output

Analysis of Algorithms

Assignment

(like in Java)

Equality testing

(like in Java)

n2 Superscripts and other

mathematical formatti

ng allowed

15

Basic computations perform

Examples:

ed by an algorithm

Evaluating an expr

Identifiable in pseudocode

ession

Assigning a value

Largely independent from t

to a variable

he programming language

Indexing into an a

rray

Exact definition not importa

Calling a method

nt (we will see why later)

Returning from a

Assumed to take a constant

method

Comparison x==y

amount of time in the RAM

x>Y

model

Analysis of Algorithms

16

3.4)

By inspecting the pseudocode, we can determine the maximu

m number of primitive operations executed by an algorithm, a

s a function of the input size

Algorithm arrayMax(A, n)

# operations

currentMax A[0]

2

for (i =1; i<n; i++)

2n

(i=1 once, i<n n times, i++ (n-1) time

s)

currentMax A[i]

return currentMax

Total

6n

Analysis of Algorithms

2(n 1)

2(n 1)

1

17

Algorithm arrayMax executes 6n 1 primitive o

perations in the worst case.

Define:

a = Time taken by the fastest primitive operation

b = Time taken by the slowest primitive operation

a (8n 2) T(n) b(8n 2)

Hence, the running time T(n) is bounded by tw

o linear functions

Analysis of Algorithms

18

Changing the hardware/ software en

vironment

Affects T(n) by a constant factor, but

Does not alter the growth rate of T(n)

time T(n) is an intrinsic property of al

gorithm arrayMax

Analysis of Algorithms

19

logn

nlogn

n2

n3

2n

16

64

16

24

64

512

256

16

16

64

256

4,096

65,536

32

32

160

1,024

32,768

4,294,967,296

64

64

384

4,094

262,144

1.84 * 1019

128

128

896

16,384

2,097,152

3.40 * 1038

256

256

2,048

65,536

16,777,216

1.15 * 1077

512

512

4,608

262,144

134,217,728

1.34 * 10154

1024

10

1,024

10,240

1,048,576

1,073,741,824

1.79 * 10308

Analysis of Algorithms

20

Big-Oh Notation

To simplify the running time estimatio

n,

for a function f(n), we ignore the con

stants and lower order terms.

Example: 10n3+4n2-4n+5 is O(n3).

Analysis of Algorithms

21

- CSE565-F08-Lec-11Uploaded byRaj Kumar
- CAB301_Levitin_Ch2.pdfUploaded byArchie Rudy Su'a
- algoritmosUploaded byJustin Mccoy
- Alogrithm and FlowchartUploaded byvishwaschoudhary
- hcl_2011Uploaded byjormn
- Data Algorithm Equivalence as an Approach to Natural Computing ParadigmUploaded byGokul B. Alex
- preskill_1_to_6(LectureNote).pdfUploaded byIvan Cheung
- mcs-31Uploaded bySonali Ghanwat
- Background SubtractionUploaded byHai Nguyen
- 05976426.pdfUploaded byRajeev Pandey
- title grade 1 my robotic friends jr-2Uploaded byapi-438472259
- practice-midterm.pdfUploaded byfkdkf
- Forward-Error Correction Considered HarmfuUploaded byLittle Johhny
- Enhancement of Object Detection and Definition Using Spatio-Temporal ClusteringUploaded byMike Seese
- 1997_Slzing, For, Items_Unknown_~ OehTUploaded byVaibhav Chaudhary
- Table of Contents.docxUploaded bybhatiaharryjassi
- np1Uploaded byWill Smith Smith
- Fundamentals of Algorithms-1Uploaded byMilan Antony
- trajectory compression.pdfUploaded byJS Trum
- scimakelatex.4032.tototoUploaded byOne TWo
- Introduction to Structured ProgrammingUploaded byKevin Ochieng
- Challenging problems - Copy.pdfUploaded byMuhammad Dihya
- Algo Summary Ch1 Ch6Uploaded byHaneen Odeh
- Semantic Annotation and Composition of Business Processes With MaestroUploaded byAbcbatata666
- AlgorithmUploaded bySir Thomas Rates
- 23789Uploaded byAdamo Ghirardelli
- 1105.6162Uploaded bydinhbi
- output_1Uploaded bymonu
- rock aUploaded byParendra Singh
- cse_551_mcsUploaded byIoana Tiriac

- p100_13 Could BeUploaded byEudaldo Saltos
- NTSB Factual ReportUploaded byGary Detman
- Enzymes NpUploaded byBharatSheth
- SIM300 SoftwareUploaded byVan Teo
- IEEE-1547Uploaded bySaul Ruvalcaba
- Auxiliary and Ground Power UnitsUploaded byNedu Japsi
- SAFETY IN IRON AND STEEL INDUSTRIES.pptxUploaded bySanil Kuriakose
- Sdlc in BreifUploaded byramachandra
- w edwards deming tqmUploaded byapi-302134896
- Global SCM Assignment MBAUploaded byRamneet Parmar
- MNS 3 0_MNSUploaded bymarkfoy
- Converter Stations Design YG ZhangUploaded byNunna Baskar
- Expert Advisor Programming - Creating Automated Trading System in MQL for Metatrader 4Uploaded bypgeronazzo8450
- Final Question Paper- Question Bank - Production and Operations Management -MBA 025Uploaded byDr Rushen Singh
- geo distUploaded byrkaarathy
- 20664_03Uploaded byoliver270694
- 117450410-amoniakUploaded byalfii
- Weber.premix FiberUploaded byabobeedo
- ewc_content.docxUploaded byshaman
- An Overview of Monolithic Zirconia in DentistryUploaded bymmsbabak
- Fuel Injector Lag TimeUploaded byasser_saleh
- Change LogUploaded byIosif Cristian Dietter
- Engineering-in-society.pdfUploaded bytansnvarma
- ENGR 1990 Application of Quadratics in Electric CircuitsUploaded byandrewgrholmes
- fact-reference.pdfUploaded byshivam_dubey4004
- Patches para Zoom G1XUploaded by40889335
- C-Track Festoon System 000-3300 R1.pdfUploaded bysamuel
- Cognos Performance Tuning WebinarUploaded bySrivishnu Reddy
- w 34137142Uploaded byAnonymous 7VPPkWS8O
- Lab2 - Combinational Logic CircuitsUploaded byFarishat Nusabbee An Nafs