Hw 05: Trivial Algorithms
Hw 05: Trivial Algorithms

 

Due Date: Friday, Oct. 6, 2017, 23:55

See the General Guidelines for homework assignments.

This assignment must be done individually.

For each question below, design an algorithm that satisfies the stated requirements. Express your answer using the pseudocode notation covered in the course notes on Algorithms. Use descriptive names for your variables, and include comments as necessary. Note: if you do not use the pseudo-code notation from the course notes, we will not grade your submission.

1. [50 points] Design an algorithm that will use simple arithmetic operations to estimate the base-2 logarithm of a given positive number. The algorithm should report the exact answer if it is an integer and otherwise state upper and lower bounds for it. For example, given the input 256 your algorithm should report 8, and given the input 81 your algorithm should report the logarithm lies between 6 and 7. Note that numbers less than 1 but greater than zero are positive. (Your solution may not invoke a log function/operator.)

2. [50 points] Design an algorithm that will take a list of numbers and the number of values in the list, and reverse the order of the elements in the list, without making use of a second list variable.

Computer Science 2104 Introduction to Problem Solving
D. Barnette