Efficiency of a solution

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Efficiency of a solution

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which statement best describes the efficiency of a solution?
A How well it uses resources like time, processing, memory, storage and effort to do its job
B How well the solution does what the user asked it to do, whatever resources it uses
2. A search feature takes 12 seconds to return results that a rival app returns in 1 second. Which efficiency measure is poor?
A Storage use
B Processing speed
3. An app stores every photo as a huge uncompressed file, so a phone runs out of space. What is the efficiency problem?
A Slow user effort
B Inefficient use of storage
4. Which change makes a solution MORE efficient for users?
A Auto-filling the customer's address so they type less
B Asking the user to retype their address on every page
5. A program loads a 5 million row table into memory just to look up one customer. Is this efficient?
A No, it uses far more memory than the task needs
B Yes, loading everything is always the fastest approach

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1for i in range(len(items)): for j in range(len(items)): AThis definition is wrong. Correctness is effectiveness, while efficiency is about how well resources such as time, memory, storage and user effort are used.
2del bigList BNested loops that check every item against every other item can slow a program down as the data grows, which hurts processing speed.
3Saving the user time and effort by remembering their details so they do not retype them each visit CFrees up memory by removing a large list that is no longer needed, so the solution uses less memory.
4Using less storage by compressing a large file before saving it DThe whole database is reloaded inside the loop for every customer. This wastes processing time and memory. It should be loaded once before the loop.
5for each customer in customers load entire database again check customer EzipFile(report, "report.zip")
6Efficiency means a solution works correctly and nothing else F<input type="text" name="email" autocomplete="email">

Definitions

efficiency

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
i ← 1 WHILE found = FALSE ___ i <= n
2.
total ← 0 FOR i ← 1 TO 100 total ← total _ mark[i]
3.
name : String age : _______ isMember : Boolean
4.
INPUT price, qty total ← price * qty _______ total
5.
___ i ← 1 TO 50 total ← total + price[i] END FOR

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A SET found TO False
B FOR EACH name IN names
C IF name <> target THEN
D EXIT LOOP
E ENDIF
F ENDFOR
Question 2
A SET total TO 0
B IF more sales exist
C INPUT sale
D SET total TO total + sale
E ENDWHILE
Question 3
A SET country TO "Australia"
B INPUT newCountry
C IF newCountry = "" THEN
D SET country TO newCountry
E ENDIF
Question 4
A SET manualTime TO 120
B SET autoTime TO 30
C SET saved TO manualTime - autoTime
D OUTPUT "Saved: " & autoTime
Question 5
A SET low TO 1
B SET high TO LENGTH(list)
C SET mid TO (low - high) / 2
D IF list[mid] = target THEN
E OUTPUT mid
F ENDIF

Answer Key

Efficiency of a solution
Section A: Quick Questions
Q1
A — How well it uses resources like time, processing, memory, storage and effort to do its job
Q2
B — Processing speed
Q3
B — Inefficient use of storage
Q4
A — Auto-filling the customer's address so they type less
Q5
A — No, it uses far more memory than the task needs
Section B: Match the Pairs
Q1
for i in range(len(items)): for j in range(len(items)): → Nested loops that check every item against every other item can slow a program down as the data grows, which hurts processing speed.
Q2
del bigList → Frees up memory by removing a large list that is no longer needed, so the solution uses less memory.
Q3
Saving the user time and effort by remembering their details so they do not retype them each visit → <input type="text" name="email" autocomplete="email">
Q4
Using less storage by compressing a large file before saving it → zipFile(report, "report.zip")
Q5
for each customer in customers load entire database again check customer → The whole database is reloaded inside the loop for every customer. This wastes processing time and memory. It should be loaded once before the loop.
Q6
Efficiency means a solution works correctly and nothing else → This definition is wrong. Correctness is effectiveness, while efficiency is about how well resources such as time, memory, storage and user effort are used.
Section C: Definitions
Q1
efficiency — How well a solution uses resources such as time, processing, memory, storage and user effort to do its job. An efficient solution is fast, light on memory and storage, and saves the user time.
Section D: Fill in the Blanks
Q1
i ← 1 WHILE found = FALSE AND i <= n
Q2
total ← 0 FOR i ← 1 TO 100 total ← total + mark[i]
Q3
name : String age : Integer isMember : Boolean
Q4
INPUT price, qty total ← price * qty DISPLAY total
Q5
FOR i ← 1 TO 50 total ← total + price[i] END FOR
Section E: Spot the Error
Q1
C — The loop should stop early only when the target is found, which saves processing time. With <> it exits on the first name that does NOT match, so the search is wrong. It should be IF name = target THEN.
Q2
B — A running total uses very little memory because it handles each sale as it arrives. It needs a WHILE loop to repeat. IF only checks once and does not match ENDWHILE. It should be WHILE more sales exist.
Q3
C — A default value saves the user effort, but it should only be replaced when the user types something. Testing for = "" replaces it with a blank entry. It should be IF newCountry <> "" THEN.
Q4
D — The time saved is the manual time minus the automatic time, which is stored in saved. Outputting autoTime shows how long the new way takes, not how much time is saved. It should output saved.
Q5
C — Binary search is fast because it checks the middle item of the range. The middle is the average of low and high, so the line should use + not -. It should be SET mid TO (low + high) / 2.