• Tidak ada hasil yang ditemukan

What is the Algorithms

N/A
N/A
Protected

Academic year: 2024

Membagikan "What is the Algorithms"

Copied!
12
0
0

Teks penuh

(1)

Introduction to Algorithms

lecture 1

(2)

What is the Algorithms

A sequence of procedure input -> output

example – finding max value

60 80 70 90 40 20 60 100

(3)

Expression

Natural language

flow chart

pseudo code

Programming language

(4)

Data structure

data structure is important in Algorithms

array

Pros

Cons

linked list

Pros

Cons 10 50 30 40

10 50 30 40 20 15

(5)

Data structure

queue

FIFO (First In First Out)

stack

LIFO (Last In First Out)

In 40 30 20 10 Out

In Out 40

30 20 10

Insert 10, 20, 30, 40

(6)

Data structure

graph

G=( V, E )

V: vertex, E: edge

undirected graph

directed graph

loop

degree, in-degree, out-degree

path

u v

u v

(u,v) = (v,u)

<u,v>

u v

(7)

Data structure

graph

tree

rooted tree binary tree

root

leaf

ancestor descendant parent

child sibling depth height

(8)

Evaluation of an Algorithm

Accuracy

Efficiency

big O

O(1) : constant

O(logn) : logarithmic

O(n) : linear

O(nlogn)

O(n2) :quadratic

O(n3) :cubic

O(nk) : polynomial

O(2n) :, exponential

O(n!)

(9)

Exchanging coins

Greedy Algorithm

Choose next step based on current state

greedy

Input: M= 37, c=(25, 20, 10, 5, 1), d=5

Output: k =

(10)

Exchanging coins

Greedy Algorithm

O(Md)

O(d)

GreedyChange ( M, c, d ) GreedyChange2 ( M, c, d )

(11)

Evaluation

(correctness)

Coin change problem

M=40, c = (25,20,10,5,1) greedy: k=

Correct answer: k=

(12)

Coin change problem

Exhaustive search/Brute force Algorithm) BruteForceChange ( M, c, d )

O(Md)

Examines every possible alternative to find one particular solution

Referensi

Dokumen terkait