4
$\begingroup$

My question about a brute force algorithm over the array was put on-hold because it was said to be "software development or programming tools"
How to iterate through all values of an array?

I don't think this is the case. Although I explain the idea in a Java like language, since Java is my language of use, however I do not ask for any tool or particular language feature.

Mod David Richerby explained that the algorithm I asked is "low-level". I don't understand, is it the same as trivial?

I would like to re-open, and I want to put a bounty for it. Thanks.

$\endgroup$
  • 4
    $\begingroup$ By the way, I'm not a moderator, but that doesn't make much difference. For reference, you can recognise the mods by the diamond next to their names. There's also a list of them. $\endgroup$ – David Richerby Feb 11 '16 at 19:59
  • $\begingroup$ I think the mods should be saying the question title doesn't make sense more than anything I'v ever titled. $\endgroup$ – Friendly Person 44 Feb 20 '16 at 20:32
5
$\begingroup$

Sorry to see the negative reaction your question got. I will say that I view the question a bit differently than others here. Given the clarification that you are looking for an algorithm, not an implementation, I think the question is on-topic and suitable for this site.

And thank you for responding to the feedback by editing the question. That was exactly the right thing to do.

However, your edit introduces a new issue with the question. The original question was asking: "how do I enumerate all MAX^SIZE values?" That I think is a reasonable question, and one that can be answered algorithmically. But your latest edit makes clear that you already know a solution to that question; you already know of an algorithm to do this. After the latest edit, it sounds like your question has changed and become: "can I call my algorithm brute force? and, is there a better way?"

These two questions, I feel, are problematic:

  • "Can I call my algorithm brute force?" does not strike me as a question that's a very good fit here, as it sounds like it might be a matter of opinion what counts as a brute force, and the answer might well depend on other information you haven't given us (about what you're going to use this algorithm for). Also, it's not clear how you're going to use answers (how is the answer going to change what you do with this?), and it doesn't seem likely to be useful to anyone in the future.

  • "Is there a better way?" is a bit problematic because you haven't defined what would qualify as "better", and "better" might be a matter of opinion. You could improve that question by giving a metric for how you want to evaluate answers (e.g., asking "Is there another algorithm whose asymptotic running time is asymptotically lower?").

So, I recommend that you do one of two things:

  • Option 1: Stick with the original question, "how do I enumerate all MAX^SIZE values?" Edit the question to ask that, and to remove your solution and the other questions. (If the question is re-opened, you can then post your solution as an answer.)

  • Option 2: Edit the question to remove "Can I call my algorithm brute force?", and focus on "Is there a better way?" -- but ask a more specific question, by removing "better" and instead asking if there is an algorithm that is faster/simpler/uses less space/whatever.

If you did either of those two things, I imagine that I'd be inclined to vote to re-open it (and I don't think you'd need a bounty to get a useful answer).

Alternatively, you can leave it as is, and leave it to the community to vote on whether to close or re-open it. Personally, I don't recommend this option, for the reasons I articulated above, but it is your choice.

Finally -- thank you for asking here on Meta about how to improve your question. That was constructive.

$\endgroup$
  • $\begingroup$ Thanks, I would like to stick to my original question. Would you please to re-open it? $\endgroup$ – qsp Feb 11 '16 at 22:32
1
$\begingroup$

One problem with your original question is switching between notations of X, x, x - for unlike things (scalar <-> array).

My next problem with the question is the, hm, type designator int in for (int x = {1,1,..1} ; … - ints do not take on composite values.

I can't figure out for sure

  • whether you are asking about one-dimensional arrays or multi-dimensional ones
    (one dimensional, more likely than not)
  • whether you are asking about notation or algorithm
    (I noticed your no, but there is in a similar way. With a one-dimensional array, I'm another one not seeing algorithm: just iterate over all values - trivial for the likes of int, difficult for irrational numbers.)
  • whether the number of dimensions of X is known at the point of iteration

Not every traversal is a search - if yours is a search, please mention why all values/elements shall be evaluated.
If you "operate on the leaves, only", what would be the difference between breadth- and depth-first traversals? If it doesn't matter, I don't see the advantage of thinking/arguing about it that way, even if the implementation looks the type.

Evaluating every possible value/element is brute force in my book. Calling it that is pointless if there obviously (CS: provably) is no alternative.

Presenting ideas in a notation with documented interpretation should make interpretation less prone to divergence. This not being CS, chose a language/notation and present what you are trying to achieve (with comments in case of programming language code). Have a look at python's itertools. Provide more context!

$\endgroup$
  • $\begingroup$ Honestly, I feel that complaining about different uses of x/X and the precise use of type designators in pseudocode is just nipicking. And I don't think the number of dimensions in the array really matters: anyone who understands how to do this for 1D arrays should be able to adapt the technique for higher dimensions (e.g., flatten the array to the 1D case and process it accordingly). $\endgroup$ – David Richerby Feb 11 '16 at 20:09
  • $\begingroup$ @DavidRicherby: in my eyes one fixed number of dimensions would be as good as any other, opposed to number of dimension varies at runtime. $\endgroup$ – greybeard Feb 11 '16 at 21:08
1
$\begingroup$

Fundamentally, algorithms and programs are the same thing, except that algorithms tend to be expressed more abstractly, e.g., in pseudocode. Thus, one can regard any programming question as a request for an algorithm, which is to be expressed in a particular language.

As such, "algorithms questions" versus "programming questions" isn't black and white. There are shades of grey.

I do feel, though, that some algorithms are so basic that they are just programming tasks. For example, if somebody asks for an algorithm to compute the total of the numbers in some array, then, sure, there's an "algorithm" to do that. However, it's so simple that, in quite a strong sense, "Sum the values in the array" is the algorithm, rather than

total := 0
for each i in [1..length]
    total := total + A[i]

At the other end of the spectrum, with something like the AKS primality algorithm, you'd expect the process to be broken down into a number of smaller steps, each of which is much more basic than "Check if n is prime."

To me, the question we're discussing here (looping through all possible values that an array could take) is at the more basic end of this range. I agree that, it's more complicated than "sum the elements of the array" but it's the sort of thing I'd expect a programmer to be able to implement without needing detailed descriptions of how. So, to me, it's a programming question, rather than an algorithms question.

However, I accept that this is a completely subjective judgement. I see there's a reopen vote in progress and people seem to think the question should be reopened. I disagree but I'm not going to vote against, since I've already had my say and my feeling is "This question isn't quite right for the site", and not "This question is bad and must be closed."

$\endgroup$
  • $\begingroup$ I disagree with your paragraph about summing the elements in an array. There are many algorithms other than iterating linearly, for example to avoid overflow, optimize precision, take advantage of multiple processors... “Sum the values in the array” is not an algorithm, it's a specification that covers multiple algorithms. $\endgroup$ – Gilles 'SO- stop being evil' Feb 11 '16 at 20:56
  • 1
    $\begingroup$ I don't think it is fair if you pick a trivial example, namely sum of an array, and implicitly assume that my question is also in the same level of triviality. It is true that what I consider difficult may be too trivial for you, but I don't think it is trivial for everybody. In particular, the only answer I got is completely wrong, and other hints and comments (now all deleted) did not make any sense. $\endgroup$ – qsp Feb 11 '16 at 22:40
  • 1
    $\begingroup$ @qsp I explicitly say that your question is more complicated than summing the values in an array. So I don't think it's fair for you to complain that I'm being unfair. $\endgroup$ – David Richerby Feb 12 '16 at 0:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .