2.8 Problem solving

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

Suppose the time to place an item into one of the 26 sub-stacks is 1 second. How many seconds are required to place all 1000 name tags onto a sub-stack?

1,000 sec 26 is not a large number; all substacks can be on a table and in order so a person can quickly (about 1 sec) toss each name tag onto the right substack.

1,000 name tags are to be sorted by last name by first placing tags into 26 unsorted substacks (for A's, B's, etc.), then sorting each substack. If last names are equally distributed among the alphabet, what is the largest number of name tags in any one substack?

39 1,000 / 26 is 39 (rounded up).

When sorting each substack, suppose the time to insert a name tag into the appropriate location of a sorted N-item sub-stack is N * 0.1 sec. If the largest substack is 50 tags, what is the longest time to insert a tag?

5 Sec 50 * 0.1 sec is 5 sec.

Suppose the time to insert a name tag into an N-item stack is N * 0.1 sec. How many seconds are required to insert a name tag into the appropriate location of a 500-item stack? 5 sec 50 sec

50 sec 500 * 0.1 sec is 50 sec. The larger the stack, the harder the stack is to work with.

problem solving

A chef may write a new recipe in English, but creating a new recipe involves more than just knowing English. Similarly, creating a new program involves more than just knowing a programming language. Programming is largely about problem solving: creating a methodical solution to a given task.

Solving a (nonprogramming) problem: Matching socks.

A person stated a dislike for mismatching socks after doing laundry, indicating there were three kinds of socks. A friend suggested just putting the socks in a drawer and finding a matching pair each morning. The person said that finding a matching pair could take forever: Pulling out a first sock and then pulling out a second, placing them back and repeating until the second sock matches the first could go on many times (5, 10, or more). The friend provided a better solution approach: Pull out a first sock, then pull out a second, and repeat (without placing back) until a pair matches. In the worst case, if three kinds of socks exist, then the fourth sock will match one of the first three.

If sock type A is pulled first, sock type B second, and sock type C third, the fourth sock type must match one of A, B, or C.

True The sock type will be either A, B, or C, which matches one already pulled.

If socks are pulled one at a time and kept until a match is found, at least four pulls are necessary.

False If the first pull is A and the second is A, a match would be found in just 2 pulls, which is fewer than 4 pulls.

If socks are pulled two at a time and put back if not matching, and the process is repeated until the two pulled socks match, the maximum number of pulls is 4.

False Mismatched pairs are put back, so no limit on the number of pulls exists.


Set pelajaran terkait

Cellular Regulation Practice NCLEX Questions

View Set

Chapter 23 Antianginal drugs - Sherpath EAQ

View Set

Physics 101: Chapter 1- The Scientific Method HW 1

View Set

NAT 503 Final Study Guide Questions

View Set

Regents Chemistry (High School): What is the pH scale?

View Set