272,297 views
7 votes
7 votes
A group of students wants to develop a calculator to reduce a fraction. The steps to do so are laid out in their math book as follows:

Express both the numerator (top number) and denominator (bottom number) as a product of their prime factors.
Strike out any common factors.
Multiply the remaining numbers to obtain the reduced numerator and denominator.
Which of the following elements would be appropriate to use in the algorithm?

A. two queues to pop out the prime factors for comparison
B. a queue and a stack to pop out the prime factors for comparison
C. two stacks to pop out the prime factors for comparison
D. two lists to hold the prime factors for comparison

User Robert Green MBA
by
2.7k points

1 Answer

23 votes
23 votes

Answer:

D. two lists

Step-by-step explanation:

You don't want to use a stack, because you can only reach the top element and decide to pop it. Not useful.

A list will give you the random access you need.

User Karoll
by
2.8k points