Developing Algorithm to Recursively Walk Array: arr[4] Example

Click For Summary

Discussion Overview

The discussion revolves around developing an algorithm to recursively walk through an array, specifically focusing on generating combinations of indices from a given array of size four. Participants explore the necessity of recursion for this task and the challenges associated with it.

Discussion Character

  • Exploratory
  • Technical explanation
  • Debate/contested

Main Points Raised

  • The original poster (OP) seeks to create a recursive algorithm to explore combinations of indices in an array of size four, mentioning specific combinations they wish to achieve.
  • Some participants suggest that the problem may not require recursion, questioning the OP's reasoning for needing a recursive approach.
  • One participant notes that recursion may not be a viable solution for all problems and emphasizes the importance of defining requirements and program design before coding.
  • A participant introduces the idea of needing a "sentinel" to manage the end of sequences, suggesting that without it, the resulting sequences may be limited to the size of the original array.
  • Several posts reference a common saying about tools and problem-solving, indicating a philosophical perspective on the use of recursion in programming.

Areas of Agreement / Disagreement

Participants express differing views on the necessity of recursion for the OP's problem, with some questioning its applicability while others explore the concept further. The discussion remains unresolved regarding the best approach to take.

Contextual Notes

Participants highlight the need for clear requirements and design specifications before attempting to implement a recursive solution, indicating potential limitations in the OP's approach.

anonim
Messages
39
Reaction score
2
TL;DR
to walk around the array
I want to write code walk around the array recursively. For some reason I cannot share my code. Let's say I have a array like this: arr[4], I want to look 012 123 013 or 01 12 23 02 03 13. In code I write I can look 012 123 or 01 12 23 but I cannot look 013 or 02 03 13. What algorithm should I develop?
 
Technology news on Phys.org
  • Like
Likes   Reactions: FactChecker and Klystron
Filip Larsen said:
This is not a particularly recursive algorithm, so perhaps you can elaborate on why you think you need recursion (that is, what problem are you trying to solve)?
"If the only tool you have is a hammer, everything begins to look like a nail."
The OP has started a number of threads with the goal of trying to solve some problem by the use of recursion. For some of the problems, recursion isn't a viable solution.
 
  • Like
Likes   Reactions: jim mcnamara
@Mark44 - that is a great concept-
"If the only tool you have is a hammer, everything begins to look like a nail."
Where did you encounter that?
 
jim mcnamara said:
@Mark44 - that is a great concept-
"If the only tool you have is a hammer, everything begins to look like a nail."
Where did you encounter that?
It might have been in a programming class I took back in the early 80s.
 
I started to sketch such a recursive program, but I had not written more than 7 or 8 lines before i stopped. I suddenly discovered that my mantra in programming was not satisfied - I had not written a requirement spec (what is the desired output of the program) or a program design (how do we go about solving this using a recursive method). And then I found out that it was too much work anyhow.
 
One thing I thought of late yesterday night: You need a "sentinel" (meaning end-of-sequence) in your list (otherwise you will only get resulting sequences the same size as your list of symbols).
 
jim mcnamara said:
@Mark44 - that is a great concept-
"If the only tool you have is a hammer, everything begins to look like a nail."
Where did you encounter that?
It is related to the "Golden Hammer".
But the first use I heard of it was in the early 1980's.
The US Senate was looking at the burgeoning use of CT Scan machines - and the problems that were arising when more of these machines were being purchased by hospitals within a market area then the patient population in that area could ever use. One Senator's remark went something like this: If you've just spent $3 million on a CT Scanner, everything looks like a nail.
 
  • Like
Likes   Reactions: jim mcnamara
jim mcnamara said:
@Mark44 - that is a great concept-
"If the only tool you have is a hammer, everything begins to look like a nail."
Where did you encounter that?
I heard it as "give a kid a hammer, and everything needs poundin'" ##-## in various forms, it's an old saw.
 

Similar threads

  • · Replies 23 ·
Replies
23
Views
2K
  • · Replies 22 ·
Replies
22
Views
4K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 5 ·
Replies
5
Views
14K
  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 16 ·
Replies
16
Views
2K
  • · Replies 25 ·
Replies
25
Views
5K
  • · Replies 4 ·
Replies
4
Views
2K