Danielle Gardner
Fundamentals of Computer Science
Dr. Kihlstrom
12 September 2006
Chapter 2- # 4, 5, 9, 14, 17
4.
Get value for price and quantity.
Set total value to be price x quantity.
Set final value to be 1.06 x the total
Print value of total cost.
5.
A)
Find the value of x and y
If (y 0) then
Compute value of x Úy
Print value of x/y
Else
Print message Ôunable to perform the division.Õ
B)
Find the value of r
If (r³1.0) then
Compute value of ¸r^2 and 2¸r
Else
Compute value of 2¸r
9.
1. Set total=0
2 While (total < 1000) do step 3 through 6
3. Get value for price and quantity.
4. Set total value to be price x quantity.
5. Set final value to 1.06 x total
6. Set value of total to (total + 1)
7. End of Loop
8. Print value of total
9. Stop
14.
1. Get values of N, the size of the list.
2. Get values for A1, A2, ÉAn, the list to be searched
3. Set the marker for the unsorted section at the end of the list.
4. While the unsorted section of the list is not empty, do steps 5 through 7
5. Select the largest number in the unsorted section of the list.
6. Exchange the number with the last number in the unsorted section of the list.
7. Move the marker for the unsorted section left one position.
8. Print out value of A4 as Median.
9. Stop
17.
a. If Ai ³ largest so far then set largest so far to Ai and set location to i because it does not matter whether it is more or equal to because you would still set it to the largest so far or move over the same exact number and thus represent the same number in the sorted line.
B. If Ai < largest so far then we do not want the algorithm to do anything. We would use this format:
Else
Do not do anything at all to largest so far and location.
These symbols corresponding to the correct relational operation are important because as some signify stopping for the completion of an operation, others allow for an iterative operation to occur and the correct amount of loops to take place in order to lead to the eventual answer. The symbol < the largest so far would mean not doing something while the symbol > in this example led to setting the marker at a different location and making adjustments.
Chapter 3 pp. 120-124 # 3, 9, 10, 24, 27
3.
43/2=21. 5 21/2= 10.5 11/2= 5.5 6/2=3 3/2= 1.5 2/2=1
171 + 85 + 43 + 21+ 11+ 5+ 3+ 1+ 1= 341 matches
I felt like the first algorithm was much more clear and easier to understand. The second algorithm made little sense to me and did not really present a system for determining the answer. The first algorithm seemed more efficient because you were able to break down each number for efficiency purposes, therefore, there was little room for error.
9.
The bubble sort algorithm does (-)(N^2) comparisons of an N-element list. Used as a selection sort tool, both swaps and comparisons are proportional to N^2. There are a number of loops in the problem The outer loop in this case executes N times and the inner loop executes N times for each cycle of the outer loop. Thus, N x N times= N^2.
10. Yes, the math step regarding bubble sort is its comparison then exchange ability, but since the list is already sorted, the bubble sort does not need to make any further exchanges.
24. Number of comparisons to find each of items 1-7 in a seven element list using binary search.
#1- three comparisons
#2 two comparisons
#3- three comparisons
#4- one comparison
#5- three comparisons
#6- two comparisons
#7- three comparisons
Average= 3+2+3+1+3+2+3=17/7= 2.4
Worse case would be three comparisons, which is 0.6 over the average number.
27. 100n^2 ÉÉ..0.01 (2^n) when n is around the value of 22.5 does the 100n^2 become more efficient than the one that does 0.01 (2^n).