Question 1 · easy
For a problem that requires a terminating answer on every legal input, an algorithm is best described as:
Answer: option B. The idea is independent of the language, and it must handle every legal instance.
Trace a method. Draw what changes. Count the work.
How can we get the right answer with less work?
Find the largest number. Start with a non-empty list.
Algorithm: precise instructions that finish and produce the required output for every allowed input.
Read the first card. Then replace the remembered value only when a larger card appears.
n means the number of cards. Here: 4 reads, 3 comparisons, 1 remembered value.
An unread card could be larger than every card seen so far. We cannot guarantee the maximum without reading it.
Different problem: find 7 in this sorted list. Check the lower middle card; if it is not 7, keep only the side that could contain 7.
9 > 7 → keep the left side.
4 < 7 → keep 7.
7 = 7 → stop.
Works with any order.
Worst case: n checks.
Requires sorted input.
Each failed check leaves at most half the candidates.
On a shuffled list: a middle value cannot tell us which side contains the target.
One check means inspecting one candidate and deciding “found”, “left” or “right”.
| Items, n | One by one: maximum checks | Middle search: maximum checks |
|---|---|---|
| 7 | 7 | 3 |
| 15 | 15 | 4 |
| 31 | 31 | 5 |
| 1,000 | 1,000 | 10 |
29 − 1 = 511 < 1,000 ≤ 1,023 = 210 − 1
So 10 middle checks suffice in the worst case.
One check handles the middle item, then either a left or right subproblem.
Capacity: 1 → 2 × 1 + 1 = 3 → 2 × 3 + 1 = 7 → 15 → 31
After k checks the capacity is 2k − 1. We count checks, including the final candidate; simply halving a size down to one is a different count.
Compare the displayed counts as n increases. The names are introduced later in the course.
Counts depend on the method and input. Seconds also depend on the machine. We will measure seconds later.
“Warm it a bit” → “Heat to 60 °C.”
“Draw enough cards” → “Draw 5 cards from a pile with at least 5.”
“Search the middle” → “Search the middle of a sorted list.”
Judge a method in this order: correct answer → readable instructions → work and memory used.
AA_Week01.ipynb.print("Hello, algorithms!")
print(2 ** 10 - 1)** means “to the power of”. Change 10 to 3; predict the result before running.
Read the last line of the error message. Check that the quotes and parentheses match the example.
A soldering robot must visit every point and return home. The goal is the shortest total distance, not the shortest next move. Choose a case, then step through the decisions.
What each rule does. Nearest neighbour moves from the robot’s current point. Closest pair builds connections anywhere, while preventing branches and early loops. Exhaustive search evaluates every visit order.
Why 64 is optimal on the line. The extremes are −21 and 11, a span of 32. A closed tour must cover that span in both directions: at least 2 × 32 = 64. The order 0 → −1 → −5 → −21 → 1 → 3 → 11 → 0 achieves it.
Correct can still be expensive. Testing all n! orders gives 3,628,800 for n = 10 and approximately 2.43 × 1018 for n = 20. Fixing the start removes duplicate rotations, but the remaining factorial growth is still severe. These counts describe this exhaustive method; they are not a proof that every exact algorithm must test every ordering.
One actor receives fixed film offers. Accept the largest number of non-overlapping roles; every role has equal value. A role ending at time 3 can be followed by one starting at 3: we use intervals [start, finish).
Know the boundary. This proof maximises the number of roles for one actor with fixed, positive-duration intervals and no changeover time. Different fees, travel times or multiple actors change the problem.
10 test questions · 7 written questions · 17 total
Each question is followed by its answer and explanation. Hard questions also include a starting hint and smaller reasoning steps.
Choose one option. Cost questions state their model and whether the bound is tight, expected or worst-case. Here lg means log₂, and heap positions start at 1.
Question 1 · easy
For a problem that requires a terminating answer on every legal input, an algorithm is best described as:
Answer: option B. The idea is independent of the language, and it must handle every legal instance.
Question 2 · easy
A sorting algorithm counts as correct only if it also handles:
Answer: option C. Every legal instance, including the awkward ones, must give the right output.
Question 3 · easy
The nearest-neighbour rule for the robot tour is:
Answer: option B. It is a heuristic: a plausible rule with no general optimality guarantee. With the stated tie rule in written exercise 4, its closed tour has length 84, while a tour of length 64 exists.
Question 4 · easy
For fixed-time jobs of equal value, choose as many nonoverlapping jobs as possible (a job may start when another finishes). Which greedy rule is optimal?
Answer: option C. Taking the job that finishes soonest frees the most time afterwards.
Question 5 · easy · course question
A method says “repeat until the answer looks good.” What is missing?
Answer: option B. “Looks good” gives no test that another person or a computer can apply consistently. State a measurable condition for stopping.
Question 6 · easy · course question
Scan the cards 6, 2, 8, 3, remembering the largest seen so far. What are the remembered values after each card?
Answer: option A. Start with 6. The 2 does not replace it; 8 does; 3 does not replace 8.
Question 7 · easy · course question
Which input would disprove the rule “the first item is the maximum” for every nonempty list?
Answer: option D. The rule returns 2 for [2, 9], although the maximum is 9. One legal failing input disproves a universal correctness claim.
Question 8 · easy · course question
A search checks the middle value and discards one side. What must be known to justify the discarded side?
Answer: option C. Sorted order tells us which side may contain smaller or larger values. Without it, a middle value does not justify discarding either side.
Question 9 · easy · course question
Two methods both return the required result on every legal input. What is a useful next comparison?
Answer: option B. Once correctness is established, compare resource use under the same assumptions and input sizes. Short-looking code can still do much work.
Question 10 · hard
A robot must visit points at −10, −3, 0, 4 and 9 on a line, starting and ending at 0. The length of the shortest closed tour is:
In simpler words: Find the full left-to-right spread and count a return trip.
Starting hint: A closed route must cross the spread in both directions.
Answer: option C. Any closed tour must travel from the leftmost to the rightmost point and back, so 2 × (9 − (−10)) = 38, and walking left then right achieves it.
Read each question together with its explanation, trace or proof. Numbering continues from the test questions.
Question 11 · easy
What are the two things we demand of every algorithm, and what does each one mean?
correctness (it gives the required output on every legal instance) and efficiency (its running time grows slowly enough with the input size to be usable on large inputs).
Question 12 · easy
Why can there be a provably correct algorithm for “find the shortest tour” but not for “find the best tour”?
“Shortest” supplies an objective: minimise total length among legal tours. That lets us state and prove a correctness claim. “Best” needs a defined objective first. Checking a tour’s length is easy; proving that no shorter tour exists is a different and potentially difficult task.
Question 13 · easy
Use nearest neighbour from 0 and, at a distance tie, choose the smaller absolute coordinate. The points are −21, −5, −1, 0, 1, 3, 11. At the initial tie choose +1. Trace the tour, find its length, and compare it with the shortest closed tour.
The specified ties give 0 → 1 → −1 → 3 → −5 → 11 → −21 → 0. Length: 1 + 2 + 4 + 8 + 16 + 32 + 21 = 84. A monotone sweep from one extreme to the other and back has length 2 × (11 − (−21)) = 64. The sweep visits intermediate points on the way. A nearest-neighbour trace needs a tie rule; this is a counterexample for the stated rule.
Question 14 · easy
For fixed-time jobs with equal value, maximise the number of nonoverlapping jobs (adjacent jobs may share a finish/start boundary). Which rule is optimal: earliest start, shortest job, or earliest finish?
earliest finish first, repeatedly accepting the job that ends soonest and discarding whatever overlaps it.
Question 15 · medium
Build a three-job instance where “shortest job first” accepts only one job although two compatible jobs exist.
A = [1, 5], B = [4, 6], C = [5.5, 9]. B is shortest (length 2) but overlaps both A and C, so the rule takes B alone; A and C do not overlap each other, so two jobs were possible.
Question 16 · hard
The robot starts at one of n points on a line and visits any point it passes. Prove that the shortest closed route has length 2 × (rightmost − leftmost), and find that route description in O(n).
In simpler words: Find the least travel needed to visit both ends of a line and return.
Starting hint: Draw the two extreme points. A closed trip has to cross their separation in both directions.
Any closed route reaching both extremes contains a journey from the left extreme to the right extreme and a return journey, costing at least twice their separation. Moving from the start to the left extreme, then to the right extreme, then home achieves this bound and passes every point. One scan finds both extremes, so the route described by these turning points takes O(n) time to find. Producing all points in sorted visitation order would be a separate sorting task.
Question 17 · hard
Change the movie-star problem so that each job pays a fee and the goal is to maximise the total fee earned. Show by example that earliest-finish-first is no longer optimal.
In simpler words: Show why choosing the earliest finish can lose money.
Starting hint: Try two overlapping jobs: one short and cheap, one long and valuable.
Job A = [1, 2) pays 1 and job B = [1, 10) pays 100. Earliest finish first takes A, which blocks B, earning 1 instead of 100. This disproves that greedy rule for unequal fees. Weighted interval scheduling can be solved by dynamic programming; this example does not rule out every possible fee-aware greedy rule by itself.
For 6, 3, 8, 2, 5, write the largest-so-far after each card. Count reads and comparisons separately.
6 → 6 → 8 → 8 → 8. 5 reads, 4 comparisons. For n cards: n reads and n − 1 comparisons.
Guess a secret from 1–100 using the middle each time. For secret 73, record each guess. Compare with counting up from 1.
50 → 75 → 62 → 68 → 71 → 73: 6 guesses. Counting up takes 73. The worst case over all secrets is 7 middle guesses because 26 − 1 < 100 ≤ 27 − 1.
Shuffle the cards. Can a middle check still justify discarding half? Show one arrangement where it discards the target.
Searching for 2 in [9, 4, 2]: the middle is 4. Keeping only the left side discards 2. Sorted order is necessary for this rule.
Sort A, C, E, B, D using only comparisons and swaps. Specify when to stop.
Repeatedly halve 1,000,000, rounding up. How many reductions leave one candidate? Repeat for 1,000,000,000.
20 and 30 reductions. These count reductions to one candidate, not checks of that candidate.
Identify the missing precision, stopping rule or assumption, then repair the instruction.
Find the maximum of 10 unsorted cards, remembering the first card before comparing the rest. How much work?
What lets a middle check safely discard one side?
Middle search covers at most 2ᵏ − 1 items in k checks. How many checks cover 31 items?
Ready for Week 2: explain your trace, name the sorted-input assumption, and run the Colab cell.
From the beginner notes · Lecture 1
A robot visits solder points on a circuit board and returns to its start. “Choose the nearest unvisited point” sounds sensible, but a shorter move now can force a longer move later. Before writing code, say which inputs are allowed, how distance is measured and whether the route must return home.
On a line, any closed route visiting both extremes travels at least twice their separation. That gives a lower bound: a distance no valid route can beat. A sweep from one extreme to the other and back can reach it. Compare the nearest-neighbour trace in the investigation with that bound. One failing example (a counterexample) disproves the claim that the rule always gives the best route. Many successful tests do not prove that claim.
Engineering use. If an AI proposes a routing rule, ask what it tries to minimise, how it chooses between equal options, and whether a small example can show it fails.
Describe a method, trace it, count its work, and run one Python cell.
00:00–01:00: launch, predict–run–explain cycle, questions · 01:00–01:10: break · 01:10–02:00: worked variation, peer instruction, questions · 02:00–02:10: break · 02:10–03:00: core mechatronics practice, exam bridge, and exit ticket.
Ask at any point. Weekly self-checks stay private; optional extensions are not collected.
Need a longer explanation? Open the English + Türkçe reference guide.
You reasoned about steps on paper. Next week the computer does the counting for you — your first lines of Python.