Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

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


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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://649294]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (4)
As of 2018-05-25 03:09 GMT
Find Nodes?
    Voting Booth?