Assignment 2: Problem Solving Example


With a challenging problem, what is often hardest is getting started. Where to begin?

Let's start by examining the output more closely:

zyxwvutsrq
zyxwvutsr
zyxwvuts
zyxwvut
zyxwvu
zyxwv
zyxw
zyx
zy
z
    

Here's what we notice:

At this point, it's important NOT to think about coding details. This is a critically useful strategy that deserves some explanation:

So now, let's just think high level but a little code-like.

We call this algorithmic thinking.

Since there are 10 lines, we could say "we're doing something 10 times" (each time slightly differently).

In code-like structure, called pseudcode:

       for i=1 to 10 {
          figure out and print the i-th line
       }
    

It's worth staring at the above for a few minutes. We'll point out that:

Next, if we could somehow figure out the last letter in each line, we'd be in good shape:

       for i=1 to 10 {
           figure out lastLetter in line i
           // Print the line
           for c='z' to lastletter {
               print c
           }
       }
    

We need to figure out the last letter in the i-th line:

 

At this point, let's step back and reflect on problem-solving:



Back to the assignment



© 2017, Rahul Simha