Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8916771
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T05:19:38+00:00 2026-06-15T05:19:38+00:00

I want to compute (for a project) self-avoiding random walks by using a recursive

  • 0

I want to compute (for a project) self-avoiding random walks by using a recursive function. I’ve managed to do that with two arrays StepX and StepY that keep track of the x and y, respectively, of the path. The recursive function is something like:

go(int x, int y, int n,int* StepX,int* StepY)

which can be summarised at “for the n-th step go at (x,y) remembering that you’ve been in StepX and StepY”.

The project is finished and I am happy, but I would like to know how to make it work using (also) a lattice, with 1 and 0 describing visited / not yet visited locations, in order to improve its speed.

I thought that extending the function as

go(int x, int y, int n,int* StepX,int* StepY, int* lattice)

would be what I was looking for, because I thought that everytime the function go is called, it creates a new copy of the lattice and works with it. But apparently this is not the case, since after having explored one direction (and after having reached the maximum level of the recursion allowed), going to a lower level of recursion, the lattice is still the same, with the visited location (of the deeper level) marked , while I wanted each level of the recursion to work on a different copy of the lattice.

Is it a wrong expectation? Is it just a wrong implementation? Any advice to reduce the memory size required by this approach?

My code (actually I didn’t write most of it) can be found here: https://gist.github.com/4144833

Be patient, I’m not an experienced programmer.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T05:19:40+00:00Added an answer on June 15, 2026 at 5:19 am

    No, you are misunderstanding the rules for parameters in C. What is copied for the recursive call is the pointer to the lattice, not the lattice array itself. You’d have to do that yourself.

    The easiest way would be to allocate a new array (with malloc) at the begginning of your call, copy the data with memcpy and then free the array at the end of the recursive call.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to ask how to add a computed column in BIRT that compute
I want this function (defn ret-lowest-str-len Computes the lengths of two strings. Returns default
I have a project in vb 2010 that im working on. I want to
We want to start using the TFS version control on our project. I read
Tell me if I want to run a project that is created in vb.net
I want to import my project from the repository that is on another computer
I downloaded a Java project that I want to study and learn some things
I want to compute the time 4 hours later during the DST transition, either
For use in a rigid body simulation, I want to compute the mass and
I am using CoreGraphics to draw a quadratic bezier but want to computer the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.