Library › Coding AI › College students
Find why your binary search hangs, without the fix
Practice: Setting limits and rules. About 5 minutes.
About this exercise
Your binary search for an algorithms side project sometimes never returns. You want to fix it yourself, so ask for exactly 3 numbered lines labeled 'Bug: line N - ...', 'Hangs on: find([...], x) - ...' with a concrete call that really loops forever, and 'Hint: ...', each under 20 words. No code blocks, no corrected line, under 75 words.
Common mistakes when you ask AI for this
- Getting the fix. The AI hands you lo = mid + 1 and a rewritten function, so you never trace it yourself. Try: Say: "Don't give the corrected line or code. Clues only."
- Blaming the wrong line. Your note points at line 9, and the AI may follow your guess. Try: Ask: "Which line causes the hang? Label it 'Bug: line N'."
- No input to trace. Without a small failing call, you can't see the loop get stuck. Try: Add: "Give a concrete call that hangs, labeled 'Hangs on:'."
- A long lesson. The AI explains binary search from the start. Try: Add: "Exactly 3 numbered lines, each under 20 words."
What a strong prompt includes
- Asks for clues, not the fix
- Gives the labels
- Asks for a failing input
- Sets the number of lines
- Caps each line
Related exercises
- Add a cron line that matches the others in a crontab (Coding AI · Product managers)
- Add dark mode by overriding your existing CSS variables (Coding AI · Software developers)
- Add input checks to your number guessing game (Coding AI · High school students)
- Add input validation to a Java method with exact messages (Coding AI · Software developers)
- Add labels to a signup form without rewriting the page (Coding AI · High school students)