CSCI 255 Fall 2023
Introduction to Algorithms and Discrete Structures
Archived Class
Charles Cusack
Computer Science
Hope College
Main
Schedule
Grading
Gradebook
Homework

Policies
College
    Policies
Advice

Notes
Programs
Tutorials

CSCI 112
CSCI 125
Others

Admin

Homework 9

General Comments

  • For full credit, provide context for each problem, show all calculations, and justify all answers by providing enough comments to explain your reasoning.
  • Homework assignments must be very neatly written or typeset (e.g. using Word or OpenOffice).
  • You can get up to 50% credit on a problem if you get significant outside assistance. Thus, if you are totally stuck on a problem it might be worth getting help. However, you must indicate any assistance/collaboration (See the Homework Assistance section on the Policies page). Failure to do so could result in a failing grade for the course! Note that getting help from the Help Center or me does not count as significant outside assistance, but talking with your classmates or searching on the Internet does!
  • If a problem asks for an algorithm, you should give the most efficient algorithm you can find to ensure full credit. You should also specify the complexity of the algorithm with justification, whether or not the problem asks for it.

Details

  1. Recall that an nth degree polynomial is p(x)= anxn+ an-1xn-1+ an-2xn-2+... a2x2+ a1x+ a0 . Evaluating a polynomial at a point mean plugging in a particular value for x and computing the answer.
    1. (6) Give a brute-force algorithm to evaluate an nth degree polynomial at a particular value c. Assume the coefficient are given in an array (e.g. float[] a), where a[0] is the constant term, a[1] is the coefficient of x,etc. Thus, the function prototype would be
      float evaluate(float[] a, int n, float c). (Note that the array has n+1 entries, not n.)
    2. (4) What is the worst-case efficiency of your algorithm from part (a)? Justify your answer.
    3. (6) If your algorithm from part (a) is Θ(n2) (It shouldn't be worse than this!) give a linear time algorithm and justify that it is linear time. (If your solution from (a) is linear, just say "see (a)".)
    4. (4) Is it possible to give an algorithm that is better than linear time? Explain why or why not, being careful about what assumptions you are making.
  2. (6) Determine the exact number of character comparisons made by the brute-force searching algorithm to determine if the text THESE is contained in the string "THIS_IS_NOT_THEIR_THREE_THINGS_THERE_OR_THE_THING_FOR_THEE". You may assume the length of the string (58) is known. Show your work!