Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

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]
[LanX]: choroba yes
[erix]: Utrecht has a beautiful old center, and less mass-tourism than Amsterdam
[erix]: next time, drop by :)
[LanX]: religion is also the reason how the house of Hanover aquire the English throne, all other candidates on succession where catholics...
[erix]: Henry VIII has a lot to answer for :P
[LanX]: erix sure next time you miss a conference nearby we drop by ...
[LanX]: did you even go to the Dutch Perl Workshop in Utrecht?
[erix]: haha ok. I'm going to Glasgow though, and make a long road trip round the isles
[erix]: [Lanx} not the last time but the one before (there have been two)

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (9)
As of 2017-12-15 16:40 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (439 votes). Check out past polls.