aspose file tools*
The moose likes Beginning Java and the fly likes feedback designing a simple algorithem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "feedback designing a simple algorithem" Watch "feedback designing a simple algorithem" New topic
Author

feedback designing a simple algorithem

Branden Bobo
Greenhorn

Joined: Jul 16, 2012
Posts: 15
I'm reading dietel's java how to program and it talks about the the top down, stepwise refinement and using psudocode.

I decided to solve my next Euler problem(11) using this approach. While I know I could easily solve this problem (quicker even) without using this approach I am try to embrace good design techniques, because I am completely self taught , but aspire to one day be a professional.

my psudocode is below (3 stages of refinement) I want to know if I grasped the point of psudocode and stepwise refinement any advice/constructive criticism is much appreciated.

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38765
    
  23
That looks a good example of how to refine an algorithm

One thing to beware: If you are going down, you must stop three rows from the bottom. If you are going right, you must stop three columns from the right.
Another thing which may make things quicker: If you go up for four squares, that give the same result as going down from three rows higher. That means you do not need to check all eight directions, only four of them. You can start going →, ↓ and ↘ from the top left corner, but only start ↙ from three columns to the right.
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7779
    
  21

Branden Bobo wrote:my psudocode is below (3 stages of refinement) I want to know if I grasped the point of psudocode and stepwise refinement any advice/constructive criticism is much appreciated.

Well, I'm afraid I'm not familiar with the book; but I thought that the point of pseudocode was not to include implementation.

ie, You don't describe how something is going to be done, you describe what is going to be done - at least that's the way I was taught - so my pseudocode would never include references to things like Scanner's. To me, you should be able to translate pseudocode into any (or almost any) language.

Example - Suppose I had a piece of high-level pesudocode with the line:
Load grid data from file.

I might 'refine' that by breaking down the action, eg:but that's just the way I do it, and your book may have a completely different notion of 'refinement'.

BTW, one of the businesses of pseudocode is to allow you to refine the logic without resorting to actual code; and, as Campbell already pointed out, yours still contains a fair bit of redundancy:
1. You don't have to check all directions.
2. You don't have to check all 400 cells.

HIH

Winston

Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
Branden Bobo
Greenhorn

Joined: Jul 16, 2012
Posts: 15
Thanks you everyone for the feedback
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: feedback designing a simple algorithem