Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Subroutine overhead in Perl

by thezip (Vicar)
on Nov 06, 2007 at 18:03 UTC ( #649294=note: print w/replies, xml ) Need Help??


in reply to Subroutine overhead in Perl

Hmmm...

It's seems like your grid_check subroutine will always have speed issues, as you have two foreach loops nested within foreach loops, which then recurse back into to the grid_check function.

Yikes. What is this, like a Big O of O(N3)? I'm betting that the Java solution used a different algorithm that did not use this design. This becomes a huge problem as N increases.

As to how to fix it, I don't know how to play Sudoku, so I cannot comment on a fix. Perhaps you might improve efficiency by exiting the foreach loops as quickly as possible so that you don't iterate on remaining unusable values?

I'm certain this code can be improved, so maybe other Monks can provide enlightenment.

Update: Changed Big O terminology

Where do you want *them* to go today?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://649294]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (6)
As of 2016-10-01 20:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?






    Results (7 votes). Check out past polls.