{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Lecture topic-BruteForce

# 0 for i n down to 0 do for power 1 power for j 1 to

This preview shows page 1. Sign up to view the full content.

This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: nt x = x0 a Algorithm: Algorithm: a a x := x0 := p := 0.0 for i := n down to 0 do for power := 1 power for j := 1 to i do power := power * x power p := p + a[i] * power power return p Efficiency: Θ (n2) Efficiency: Can we design a esign and Analysis of Algorithms – for this problem linear algorithm Chapter 3 D 25 Polynomial evaluation: Polynomial improvement improvement a We can do better by evaluating from right to left: We 1 p(x) = anxn + an-1xn--1 +… + a1x1 + a0 +… point x = x0 a Algorithm: Algorithm: a at a Efficiency: Θ (n) Efficiency: x := x0 := p := a[0] power := 1 for i := 1 to n do for power := power * x p := p + a[i] * power power return p Design and Analysis of Algorithms – Chapter 3 26 Polynomial evaluation: Polynomial improvement improvement a a a a We can do better by evaluating from right to left: We 1 p(x) = anxn + an-1xn--1 +… + a1x1 + a0 +… point x = x0 at a Algorithm: Algorithm: x := x0 := p := a[0] power := 1 for i := 1 to n do for power := power * x p := p + a[i] * power power return p Efficiency: Θ (n) Efficiency: Can we design a better than linear algorithm for this Can problem problem Design and Analysis of Algorithms – Chapter 3 27 Brute force closest-pair algorithm a Closest pair • Problem: find the closest pair among n points in k-dimensional find -dimensional space space Design and Analysis of Algorithms – Chapter 3 28 Brute force closest-pair algorithm a Closest pair • Problem: find the closest pair among n points in k-dime...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online