Igor Ivkovic
2004-11-07 20:39:06 UTC
If you look at my previous post to the newsgroup, it should be clear how
to implement all of the other methods.
If it is not clear, let me repeat that if you know that you are dealing
with a PolynomialAsLinkedList instance - and that will hold for new
instances created in getDerivate, plus, minus, and times as well as for
"this" polynomial - you may directly call LinkedList methods on the
underlying linked lists for any of these polynomials. Hence, you will save
running time by avoiding possible overhead associated with calling
SetCoefficient on new polynomials by using LinkedList "append" method.
With regards to GetCoefficient, let me remind you that your other
implementation of PolynomialAsArray returns the coefficient in O(1) time,
as it accesses it directly from the polynomial array. Therefore, calling
GetCoefficient M times in the case when you are passed a parameter that is
not an instance of PolynomialAsLinkedList will only take O(M) time, and
that compounded with O(n) time required to access the elements of "this"
will result in the overall running time of O(n + M).
Igor
to implement all of the other methods.
If it is not clear, let me repeat that if you know that you are dealing
with a PolynomialAsLinkedList instance - and that will hold for new
instances created in getDerivate, plus, minus, and times as well as for
"this" polynomial - you may directly call LinkedList methods on the
underlying linked lists for any of these polynomials. Hence, you will save
running time by avoiding possible overhead associated with calling
SetCoefficient on new polynomials by using LinkedList "append" method.
With regards to GetCoefficient, let me remind you that your other
implementation of PolynomialAsArray returns the coefficient in O(1) time,
as it accesses it directly from the polynomial array. Therefore, calling
GetCoefficient M times in the case when you are passed a parameter that is
not an instance of PolynomialAsLinkedList will only take O(M) time, and
that compounded with O(n) time required to access the elements of "this"
will result in the overall running time of O(n + M).
Igor
Hey there,
I'm having trouble implementing the "add" method for project 3 within
the time bounds of O(n + M) when "p" is NOT a PolynomialAsLinkedList.
If we're assuming that "p" is any concrete class implementing the
Polynomial interface then the only way to traverse it (that I can see),
is to run a for loop from the degree of the polynomial down to 0 because
we don't know what data structure it implements underneath. Now, once
we do that it's already 0(M), and the only way to access the
coefficients is the "getCoefficient" method which runs O(n). Running an
O(n) inside a for loop is now O(Mn). I cannot see a way around this,
could you perhaps give me some guidance?
Thanks,
Paul
----------------------------------------
This mail sent through www.mywaterloo.ca
I'm having trouble implementing the "add" method for project 3 within
the time bounds of O(n + M) when "p" is NOT a PolynomialAsLinkedList.
If we're assuming that "p" is any concrete class implementing the
Polynomial interface then the only way to traverse it (that I can see),
is to run a for loop from the degree of the polynomial down to 0 because
we don't know what data structure it implements underneath. Now, once
we do that it's already 0(M), and the only way to access the
coefficients is the "getCoefficient" method which runs O(n). Running an
O(n) inside a for loop is now O(Mn). I cannot see a way around this,
could you perhaps give me some guidance?
Thanks,
Paul
----------------------------------------
This mail sent through www.mywaterloo.ca