CSCI 3322 (Principles of Algorithms), Fall 2022:
Homework 1
- Credit:
- 52.5 points.
Be sure you have read, or at least skimmed, Chapter 2 of the textbook.
Answer the following questions. You may write out your answers by
hand and scan them, or you may use a word processor
or other program, but please turn in a PDF or plain text file.
(No links to shared files on Google Drive please, and no word-processor files.)
Turn it in by putting it in your course “TurnIn” folder on
Google Drive.
Please be sure to include your name somewhere in the file,
so when I print it for grading I know whose work it is.
(In the pledge is fine.)
- Consider the searching problem, which you probably saw in CS1:
Input: A sequence of numbers
stored
in an array and a value .
Output: An index such that , or the special
value NIL if does not appear in .
One way to solve this problem is with linear search algorithm,
which scans through the array from beginning to end.
- (5 points) Write pseudocode for an iterative algorithm for linear
search.
- (5 points) Use a loop invariant to argue that your algorithm is
correct, as the textbook does for INSERTION-SORT.
- (5 points) Analyze the worst-case execution time for your algorithm.
- (5 points) Write pseudocode for a recursive version of the same algorithm.
- Another way to solve the same problem, possible if is sorted, is binary search:
Check the midpoint of against the value to find (). You can then eliminate half
the array from further consideration -- if is less than the midpoint of the array,
you need only search the left part of the array, while if is larger than the midpoint,
you need only search the right part.
- (10 points) You probably remember the bubblesort algorithm from CS1. The textbook
presents pseudocode for this algorithm on p. 46.
This should include the Honor Code pledge, or just the word “pledged”,
plus at least one of the following about
collaboration and help (as many as apply).
Text in italics is explanatory or something for you to
fill in;
you don't need to repeat it!
- I did not get outside help aside from course
materials, including starter code,
readings, sample programs, the instructor.
- I worked with names of other students on this
assignment.
- I got help with this assignment from
source of help -- ACM
tutoring, another student in the course, etc.
(Here, “help” means significant help,
beyond a little assistance with tools or compiler errors.)
- I got help from outside source --
a book other than the textbook (give title and author),
a Web site (give its URL), etc..
(Here too, you only need to mention significant help --
you don't need to tell me that you
looked up an error message on the Web, but if you found
an algorithm or a code sketch, tell me about that.)
- I provided help to names of students on this
assignment.
(And here too, you only need to tell me about
significant help.)
This should be a brief essay
(a sentence or two is fine, though you can write as much as you like)
telling me what if anything you think
you learned from the assignment,
and what if anything you found
interesting, difficult, or otherwise noteworthy.
2022-09-21