CMSC 104, Algorithms

Practice Problem Set ( Algorithms )

Definitions:

1.) An Algorithm is a finite set of unambiguous executable instructions that directs a terminating activity.

2.) A generic algorithm will work with any values for input. For example, any integer, any sentence, any set of numbers.

Problems:

1. First solve each of the following problems.
2. Then write an algorithm for each problem. Either English sentences OR pseudocode is acceptable.

1. A merchant wishes to mix peanuts costing \$1.50 per pound with cashews costing \$4.00 per pound, obtaining 50 pounds of a mixture costing \$2.40 per pound. How many pounds of each type of nut should be used?
• The algorithm should allow for changes in the costs of the peanuts and cashews.
• The user should be specify the final weight of the purchase (50 lbs).

2. A store holding a clearance sale advertises that all prices have been discounted 20%. If a certain item is on sale for \$28.00. , what was its price before the sale?

• The algorithm should allow for the item to be at any sale price.
• The algorithm should allow for any percent discount.
1. It costs a toy company ( 1000. + 2x ) dollars to manufacture x Big Bertha dolls. Each doll sells for \$5.00 How many dolls must be sold to make \$10,000 profit?

• The algorithm should allow for different sale prices for the dolls
• The user should be able to specify the amount of money to be made.

1. A student in a C programming course has test scores of 75, 82, 71, and 84. What score on the next test will raise the students average to 80? All tests are of equal value.
• Allow the user to input different test scores
• Allow the user to specify a different number of tests each time.

1. A newspaper boy has 125 coins, consisting of nickels and pennies. If the total amount is \$4.25 how many coins of each type does he have?
1. The pressure acting at a certain depth in a liquid is directly proportional to the distance form the surface of the liquid to that depth. In a certain oil tank the pressure at a depth of 2 feet is 118 pounds per square foot. Find the pressure at a depth of 5 feet.
• The algorithm should allow for different liquids. ie, different pressures of the liquid at a given depth.
• The algorithm should allow for different depths to be measured.
1. A manufacturer sells a certain article to dealers at a rate of \$20. each if less than 50 are ordered. If 50 or more are ordered, the price of each article is reduced 50 cents. What is the total cost of 100 units?
• The algorithm should allow for changes in the \$20 price, for purchases under 50 units.
• The algorithm should allow for changes in the 50 cents reduced rate.