DAA - Algebraic Problems
DAA - Algebraic Problems
Algebraic Problems
Unit-5 Branch and Bound & Algebraic
● Branch and Bound: The method, traveling sales person problem, 0/1
knapsack problem, efficiency considerations.
● Algebraic Problems: The general method, Evaluation and Interpolation.
Algebraic Problems
● Computers already have the built-in ability to manipulate integers and
reals, they are not directly equipped to manipulate symbolic
mathematical expressions such as polynomials.
● One must determine a way to represent them and then write procedures
that perform the desired operation.
● A system that allows for the manipulation of mathematical expressions
(usually including arbitrary precision integers, polynomials, and rational
functions) is called a mathematical symbol manipulation system.
Contd…
● Algebra problems are an integral part of mathematics, focusing on the
use of symbols and the rules for manipulating these symbols. They often
involve an unknown variable, represented by letters and symbols.
● For instance, we're all familiar with the number 5, but what if we see x=5
or 5y? This is where algebra comes into play.
● Algebra is a branch of mathematics that deals not only with numbers but
also variables and alphabets.
Example:
● Solve, 5x + 6 when, x = 4.
● Add 4x + 6x
● Simplify the expression: 13x^2 – 10x + 6x – 5x^2 – 8x + 11.
● Solve (3x+y)^2
● Solve (98)^2
● There are 50 students in a class. This is four more than five times the number of
girls. How many girls are there in the class?
● The present age of Deepak is one-third of his mother’s present age. If his
mother’s age was five times than his age 6 years ago, determine their present
ages.
● The sum of two consecutive numbers is 45. What are the numbers?
Algebraic Transformations
● Algebraic transformation techniques refer to a set of mathematical
methods and manipulations used to transform algebraic expressions,
equations, or functions into different forms.
● Algebraic transformation is a design technique that is used to implement
and manipulate the mathematical expression.
● These techniques are often employed to simplify, solve, or better
understand algebraic problems.
● Some common algebraic transformation techniques include
Simplification, Expansion, Factorization, Substitution, etc.
Algebraic Simplification
● When applied to algebraic problems, algebraic simplification refers to the
process of re-expressing computational formulas so that the required
number of operations to compute these formulas is minimized.
● Representation of a polynomial
1. Dense representation
2. Sparse representation
Dense representation
● In a dense representation of a polynomial, all coefficients, including zero
coefficients, are stored explicitly in an ordered list or array. A dense
representation of a polynomial is typically using a list or array to represent its
coefficients. It is used for easy arithmetic operations and manipulation.
● P(x) = 3x^3 - 2x^2 + 5x - 1 = [3, -2, 5, -1]
● S(x) = 2x^6 - x^4 + 3x^3 + 2x^2 - 5x + 1 = [2, 0, -1, 3, 2, -5, 1]
● In dense representation, you would express this polynomial as a list of
coefficients, where the position in the list corresponds to the exponent of x.
● The degree of the polynomial can be determined by the size of the array (one
less than the number of elements in the list.
● Inefficient for polynomials with many zero coefficients.
Sparse representation
● In sparse representation, only store non-zero coefficients along with their
corresponding exponents.
● This representation is particularly useful for polynomials with many zero
coefficients, as it conserves memory by only recording the terms that matter.
● Common data structures for sparse representations include dictionaries,
linked lists, or arrays with a separate structure to store exponents.
● P(x) = 3x^3 - 2x^2 + 5x – 1 = {3: 3, -2: 2, 5: 1, -1: 0}
● R(x) = 4x^5 - 2x^3 + 5x^2 + 3 = {5: 4, 3: -2, 2: 5, 0: 3}
● More complex to perform arithmetic operations, as you must handle
matching exponents.
Polynomial Evaluation
● A naive way to evaluate a polynomial is to one by one evaluate all terms.
● Evaluate value of 2x3 - 6x2 + 2x - 1 for x = 3, Output: 5
● Evaluate value of 2x3 + 3x + 1 for x = 2, Output: 23
Horner’s Rule to Evaluate a
Polynomial
● Horner's method (or Horner's scheme) is an algorithm for polynomial
evaluation. The algorithm is based on Horner's rule, in which a
polynomial is written in nested form.
● The entries in the third row are the sum of those in the first two. Each
entry in the second row is the product of the x-value (3 in this example)
with the third-row entry immediately to the left. The entries in the first
row are the coefficients of the polynomial to be evaluated.
Contd…
● To evaluate p(x) = 6x3 − 2x2 + 7x + 5 at x = 4,
● Extra- refers to "in addition to," while inter- means "in between.“
● When comparing the Lagrange and Newton interpolation methods, one can
use certain criteria to measure their performance and suitability for different
situations. These criteria include accuracy, complexity, flexibility, and stability.
● Accuracy is determined by how well the interpolating polynomial approximates
the true function within and outside the data interval. Complexity examines
the number of operations and memory needed to construct and evaluate the
interpolating polynomial. Flexibility is evaluated by how easy it is to modify or
extend the interpolating polynomial when new data points are added or
removed. Lastly, stability assesses how sensitive the interpolating polynomial is
to errors or changes in the data points or function values.
Lagrange and Newton interpolation methods
● When comparing Lagrange and Newton interpolation based on certain criteria, it can
be concluded that Lagrange is more accurate when the data points are evenly
spaced and the function is smooth, but is less accurate when the data points are
unevenly spaced or the function is oscillatory or noisy. Meanwhile, Newton
interpolation is more complex in terms of operations and memory, yet less complex
in terms of degree and coefficients.
● Furthermore, Newton interpolation is more flexible as it allows adding or removing
data points without affecting the previous terms, whereas Lagrange interpolation
requires recomputing the whole polynomial. Lastly, Newton interpolation is more
stable than Lagrange interpolation as it is less affected by rounding errors and ill-
conditioning, while Lagrange interpolation can exhibit Runge's phenomenon and
large errors near the boundaries.
Application Example
● For instance, if you need to find the value of a function at a point that is not given by a
table or a formula, you can use either Lagrange or Newton interpolation depending on
the available data points and their spacing. For example, if you have a table of values of
sin(x) at equally spaced points from 0 to pi/2, you can use Lagrange interpolation to
find sin(0.3) with an appropriately low degree polynomial.
● On the other hand, if you have a table of values of exp(x) at unevenly spaced points
from 0 to 1, then Newton interpolation is more suitable for finding exp(0.5) with a
more stable polynomial.
● Similarly, when aiming to smooth or fit a curve to noisy or scattered data, you can
choose between Lagrange or Newton interpolation based on the degree of
smoothness and the number of data points. Lastly, when trying to solve a differential
equation by converting it into a system of algebraic equations, the type of boundary
conditions and the order of accuracy will determine which method is most suitable.
The Lagrange’s Interpolation formula:
● The Lagrange interpolation formula can be used to find a polynomial that
passes through a set of given points, regardless of whether the intervals
between the points are equal or unequal.
● If, y = f(x) takes the values y0, y1, …, yn corresponding to x = x0, x1, …, xn
then,
The Lagrange’s Interpolation formula:
Interpolate the quantity of the product supplied at the price
dollar
P 85.
80 90 100 110 120 THE DIFFERENCE TABLE
S 25 30 42 50 68 P S Δ1 Δ2 Δ3 Δ4
80 25 5 7 -11 25
90 30 12 -4 14
100 42 8 10
110 50 18
120 68
43 13 3 25
Newtonian Interpolation
Analysis of Computing Time of Lagrange Interpolation
to O(𝑛^2)
Horner rule), then time complexity will be reduced
References
● linear interpolation
● polynomial interpolation
● Lagrange interpolation
● Newton polynomial interpolation
● spline interpolation
● spline interpolation
Common Extrapolation methods
● Extrapolation is about predicting hypothetical values that fall outside a
particular data set. The predictive quality of extrapolation means the
method is usually used to predict unknown future values, unlike
interpolation, which is usually about estimating past values.
● linear extrapolation
● polynomial extrapolation
● conic extrapolation
Interpolation Extrapolation
The reading of values between two Estimating a value that's outside the data
points in a data set set
The estimated record is more likely to The estimated values are only probabilities,
be correct. so they may not be entirely correct.
Advantages of Lagrange
Interpolation:
● This formula is used to find the value of the function even when the
arguments are not equally spaced.
● This formula is used to find the value of independent variable x
corresponding to a given value of a function.
Disadvantages of Lagrange
Interpolation:
● A change of degree in Lagrangian polynomial involves a completely new
computation of all the terms.
● For a polynomial of high degree, the formula involves a large number of
multiplications which make the process quite slow.
● In the Lagrange Interpolation, the degree of polynomial is chosen at the
outset. So it is difficult to find the degree of approximating polynomial
which is suitable for given set of tabulated points.
Contd…
Complexity:
● The time complexity of the above solution is O(n2) and auxiliary space is
O(1).