Skip to content
Ameen Abozaid
BEG-016

Problem-solving

  • 6 Lessons
  • 71 min of reading
  • 5 h practice (estimate)
On this page 8 topics

Overview

Topics

  • Decomposition
  • pseudocode
  • flowcharts
  • tracing
  • debugging
  • edge cases

Learn first

71 min of reading · 5 h of practice (estimate)

Learning outcomes

  1. Restate a problem in their own words and identify inputs, outputs, and constraints.
  2. Decompose a problem into steps and express them as pseudocode or a flowchart before coding.
  3. Trace a program by hand with a variable table.
  4. List edge cases (empty, one element, maximum, negative, invalid) before writing code.

Lessons

  1. 01Understanding the problem first12 min read
  2. 02Decomposition12 min read
  3. 03Pseudocode and flowcharts12 min read
  4. 04Hand-tracing with a variable table12 min read
  5. 05Thinking in edge cases12 min read
  6. 06Demo: plan before code on an unseen problem11 min read

Lab and exercises

Lab

BEG-016-LAB1 · Plan before code

Outcomes: 1–4 · Time: ~3 h For each of three unseen problems (supplied by the instructor, for example: second largest value, palindrome check, count vowels):

  1. Restate the problem and list inputs, outputs, constraints.
  2. Write pseudocode or a flowchart.
  3. List edge cases with expected results.
  4. Hand-trace one example with a variable table.
  5. Only then write the Java code and submit the plan with it.

Acceptance: plan and code match; all listed edge cases handled.

Exercises (assessment: one unseen problem solved with a plan, graded on the plan as much as the code)

IDOutcomeTask
BEG-016-EX011Restate "give each customer a loyalty discount" and list inputs, outputs, and three questions to ask.
BEG-016-EX022Decompose "print a report of the highest-scoring student" into 5 steps.
BEG-016-EX032Write pseudocode for "is a number prime?" and draw its flowchart.
BEG-016-EX043Trace int x = 10; int c = 0; while (x > 1) { x = x / 2; c++; } with a variable table.
BEG-016-EX054List at least six edge cases for "average of an array of grades".
Show solutions
  • EX01 Inputs: customer data, purchase history. Output: discount percent. Questions: what makes a customer loyal? maximum discount? can discounts stack?
  • EX02 1 read the scores; 2 start the best at the first student; 3 compare each other student; 4 update the best; 5 print the name and score.
  • EX03 If n < 2 not prime; for d from 2 up to the square root of n, if n % d == 0 then not prime; otherwise prime. The flowchart has one decision diamond for each test.
  • EX04 Rows: x 10, c 0 → x 5, c 1 → x 2, c 2 → x 1, c 3; the loop ends. Final c is 3.
  • EX05 Empty array; one grade; all equal; zero grades; negative or above 100 (invalid); very large array; decimals.
  • Lab acceptance and the graded unseen problem cover the full routine (outcomes 1-4 together).

Quiz

Outcomes: O1 understand the problem · O2 decompose and plan · O3 hand-trace · O4 edge cases.

A self-check for you: nothing is graded, saved or sent anywhere. Choose an answer, then check it. You can try again as often as you like.

  1. 1The first step in solving a problem is to:O1
  2. 2Which is NOT one of inputs, outputs, constraints?O1
  3. 3Decomposition means:O2
  4. 4Pseudocode is:O2
  5. 5In a flowchart a yes/no decision is drawn as a:O2
  6. 6A variable table is used to:O3
  7. 7In hand-tracing, the bug is usually at:O3
  8. 8Which is an edge case for "largest in an array"?O4
  9. 9Testing only the happy path:O4
  10. 10Which pair are both edge cases?O4

Practical part

The graded unseen problem (plan first, then code) and the three-problem lab. Pass: plan and code match, edge cases listed before coding and all handled, and quiz at least 8/10.

Common mistakes

Coding before understanding; testing only the happy path.

Assessment

Unseen problem solved with a plan, graded on the plan as much as the code.

Career relevance

The habit behind requirement clarification (MID-064) and requirements engineering (SRC-001).

Type to search levels, phases, modules and lessons.