AP Classroom

AP Classroom. Provide answers and thoughts on theoritical question form college board Video in section 4.3. They start at about the 9 minute mark.

Example 1

A particular computer has two identical processors which can run in parallel. Each Process must be executed on a single processor and each processor can only run one process at a time.

The table below lists the amount of time it takes to execute each of the processes on a single computer. None of the processes are dependent on any of the others.

What is the minimum amount of time to execute all three processes when the two processors are run in parallel?

Process Execution Time on Either Processor
X 50 seconds
Y 10 seconds
Z 30 seconds

Answer 1

50 seconds

If we run the processes sequentially on a single processor, it will take a total of 50 + 10 + 30 = 90 seconds. However, we have two identical processors available, so we can run two processes in parallel. The bottleneck process will be the one with the longest execution time, which is process X with 50 seconds. The other two processes can be completed in the remaining time it takes to complete process X. So, we can run processes Y and Z simultaneously on the two processors, which will take a total of 30 seconds (since Z takes 30 seconds to execute). Once process Z is complete, we can use one processor to complete process X, which will take another 20 seconds. Therefore, the total time required to complete all three processes using both processors is 20 + 30 = 50 seconds. Thus, the minimum amount of time required to execute all three processes when the two processors are run in parallel is 50 seconds.

Example 2

A computer has two duplicate processors that are able to run in parallel. The table below shows the amount of time it takes each processor to execute each of two processes. Neither process is dependent on the other.

Process Execution Time on Either Processor
A 25 seconds
B 45 seconds

What is the difference in execution time between running the two processes in parallel in place of running them one after the other on a single processor?

Answer 2

If the two processors are run in parallel, then process A and process B can be executed simultaneously on each processor. The total execution time will then be equal to the time required to complete the longest running process. So, in this case, the total execution time will be equal to the maximum of the execution time for process A and process B on either processor, which is:max(25 seconds, 45 seconds) = 45 seconds Therefore, the difference in execution time between running the two processes in parallel and running them one after the other on a single processor is:

45 seconds - (25 seconds + 45 seconds) = 45 seconds - 70 seconds = -25 seconds

This negative result indicates that running the two processes in parallel is faster than running them one after the other on a single processor. The parallel execution would take 45 seconds to complete, while running them sequentially on a single processor would take 70 seconds.

Data Structures. Build a List Comprehension example

original_list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
even_numbers = [x for x in original_list if x % 2 == 0]
print(even_numbers)
[2, 4, 6, 8, 10]