Learning Polynomials, Tree Sort & Synthetic Division: Horner's Method & Binary Trees, Slides of Data Structures and Algorithms

Lecture notes on polynomials and tree sort, covering topics such as synthetic division, horner's method, and binary trees. Explanations, examples, and algorithms for polynomial evaluation, horner's method, and binary trees. It is suitable for university students studying computer science or mathematics.

Typology: Slides

2012/2013

Uploaded on 04/30/2013

patel
patel 🇮🇳

3.8

(15)

80 documents

1 / 46

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Lecture 11
POLYNOMIALS and Tree sort
1
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e

Partial preview of the text

Download Learning Polynomials, Tree Sort & Synthetic Division: Horner's Method & Binary Trees and more Slides Data Structures and Algorithms in PDF only on Docsity!

Lecture 11

POLYNOMIALS and Tree sort

  • INTRODUCTION
  • EVALUATING POLYNOMIAL FUNCTIONS
  • Horner’s method
  • Permutation
  • Tree sort

INTRODUCTION

  • The problems examined in this lecture arepolynomial evaluation (with and without preprocessing of the coefficients), polynomial multiplication, and multiplication of matrices and vectors.
  • Several algorithms in this lecture use the divide-and- conquer method: evaluating a polynomial withpreprocessing of coefficients, Strassen’s matrix multiplication algorithm.

EVALUATING POLYNOMIAL FUNCTIONS Consider the polynomial: P(x) = a n x^ n + a n-1x^ n-1 + … + a 1 x +a 0 with real coefficients and n>=

Suppose the coefficients of agiven and that the problem is the evaluate p(x). 0 , a 1 , …, a n and x are

In this section we look at some algorithms and somelower bounds for this problem.

Use synthetic division to find the quotient and remainder when f x x x x g x x

( ) ( ).

= − + − = +

3 2 10 3

(^4 3 2) is divided by

x + 3 = x − − ( 3 )

Algorithms

  • The obvious way to solve the problem is to compute each term and add it to the sum of the others already computed. The following algorithm does this

Algorithm Polynomial Evaluation—Term by Term

  • Input n>=0, the degree of p; and x, the point at which to : The coefficients of polynomial p(x) in the array a;
  • evaluate p. Output : The value of p(x). float poly(float[] a, int n, float x) float p, xpower; int i; for (i = 1; i <= n; i++)^ p = a[0]; xpower = 1; xpower = xpower * x; return p;^ p+=a[i] * xpower; Note: This algorithm does 2n multiplications and n additions

Algorithm Polynomial Evaluation – Horner’s Method

  • InputOutput : a, n, and x as in Algorithm 12.1.: The value of p(x). float hornerPoly(float[]a, int n, float x) float p; int i; p = a[n]; for (i = n – 1; i>= 0; i--) p = p * x + a[i]; return p; Thus simply by factoring p we have cut the number ofmultiplications in half without increasing the number of additions.