CSCI 3322 (Principles of Algorithms), Fall 2022:
Homework 1

Credit:
52.5 points.

Reading

Be sure you have read, or at least skimmed, Chapter 2 of the textbook.

Problems

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.)

  1. Consider the searching problem, which you probably saw in CS1:

    Input: A sequence of $n$ numbers $a_1, a_2, \ldots a_n$ stored in an array $A[1:n]$ and a value $x$.

    Output: An index $i$ such that $x = A[i]$, or the special value NIL if $x$ does not appear in $A$.

    One way to solve this problem is with linear search algorithm, which scans through the array from beginning to end.

  2. Another way to solve the same problem, possible if $A$ is sorted, is binary search: Check the midpoint of $A$ against the value to find ($x$). You can then eliminate half the array from further consideration -- if $x$ is less than the midpoint of the array, you need only search the left part of the array, while if $x$ is larger than the midpoint, you need only search the right part.

  3. (10 points) You probably remember the bubblesort algorithm from CS1. The textbook presents pseudocode for this algorithm on p. 46.

Pledge

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!

Essay

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