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

In summary: I encountered it first in a programming class I took in the early 80s.It is related to the "Golden Hammer".But the first use I heard of it was in the early 1980's.
  • #1
anonim
40
2
TL;DR Summary
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
  • #2
  • Like
Likes FactChecker and Klystron
  • #3
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 jim mcnamara
  • #4
@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?
 
  • #5
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.
 
  • #6
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.
 
  • #7
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).
 
  • #8
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 jim mcnamara
  • #9
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.
 

1. What is an algorithm?

An algorithm is a step-by-step procedure or set of instructions used to solve a problem or complete a task. In computer science, algorithms are used to create programs and software to process and manipulate data.

2. How does recursion work in algorithm development?

Recursion is a programming technique where a function calls itself repeatedly until it reaches a base case. In the context of developing an algorithm to recursively walk an array, it means that the function will continue to call itself on smaller and smaller portions of the array until it reaches the end.

3. What is a recursive function?

A recursive function is a function that calls itself within its own definition. It is used to solve problems that can be broken down into smaller subproblems, eventually reaching a base case where the function will stop calling itself and return a value.

4. How does an algorithm recursively walk an array?

An algorithm to recursively walk an array will start by checking if the array is empty or if it has reached the end. If not, it will perform a specific action on the first element of the array and then call itself on the remaining elements of the array. This process will continue until the entire array has been traversed.

5. What are the advantages of using recursion in algorithm development?

Recursion can simplify code by breaking down a complex problem into smaller subproblems. It also allows for a more efficient use of memory, as only one copy of the recursive function needs to be stored in memory at a time. Additionally, some problems are naturally recursive in nature, making it easier to design an algorithm using recursion.

Similar threads

  • Programming and Computer Science
Replies
23
Views
1K
  • Programming and Computer Science
Replies
1
Views
674
  • Programming and Computer Science
Replies
7
Views
1K
  • Programming and Computer Science
Replies
22
Views
3K
  • Programming and Computer Science
Replies
4
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
1K
  • Programming and Computer Science
Replies
4
Views
3K
  • Programming and Computer Science
Replies
16
Views
2K
  • Programming and Computer Science
Replies
25
Views
5K
  • Programming and Computer Science
Replies
5
Views
12K
Back
Top