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 595649
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T16:05:08+00:00 2026-05-13T16:05:08+00:00

I am trying to come up with an algorithm for a tree traversal, but

  • 0

I am trying to come up with an algorithm for a tree traversal, but I am getting stuck.

This is a fairly hard question (compared to others I have asked) so I may need to keep figuring on my own. But I thought I would throw it out here.

I have the following class structure:

public class Transition
{
    // The state we are moving from.
    public String From { get; set; }
    // All the To states for this from
    public List<String>To { get; set; }
}

List<Transition> currentTransistions;

When currentTransistions is fully filled out it looks like this (for me):

<?xml version="1.0" encoding="utf-8"?>
<ArrayOfTransition xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <Transition>
    <From />
    <To>
      <string>Not Done</string>
    </To>
  </Transition>
  <Transition>
    <From>Not Done</From>
    <To>
      <string>In Progress</string>
      <string>Deleted</string>
    </To>
  </Transition>
  <Transition>
    <From>Deleted</From>
    <To>
      <string>Not Done</string>
    </To>
  </Transition>
  <Transition>
    <From>In Progress</From>
    <To>
      <string>Done</string>
      <string>Ready For Test</string>
      <string>Deleted</string>
    </To>
  </Transition>
  <Transition>
    <From>Done</From>
    <To>
      <string>In Progress</string>
    </To>
  </Transition>
  <Transition>
    <From>Ready For Test</From>
    <To>
      <string>In Progress</string>
      <string>Done</string>
      <string>Deleted</string>
    </To>
  </Transition>
</ArrayOfTransition>

The idea here is that I have mapped the state transitions for TFS Work items. What I need now is a way to say “Given a current state, how do I get to another state”.

Ideally it would look like this:

 foreach (string state in GetToFinalState(finalState, currentState, currentTransistions)
 {
     // Save the workitem at the state so we can get to the final state.
 }

GetToFinalState, would have to have a way to caclulate the shortest path and use the yield feature of C# to offer them up one at a time for the foreach statement.

I have used yield one before, so I think I can figure that out. But I am not sure how to do that at the same time as finding the shortest path (with out recalculating on each time in the func)?

If you have read this far, thanks. If you offer an answer then double thanks.

  • 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-05-13T16:05:08+00:00Added an answer on May 13, 2026 at 4:05 pm

    You can’t do that efficiently without calculating the shortest path and yielding each path segment after the whole process is completed. The nature of shortest path problem doesn’t lend itself to algorithms that efficiently compute such partial solutions.

    Since the transition graph is not weighted, you can simply run a BFS on it to compute the shortest path. You need to do something like this (I’m not sure of the properties of the TFS object so this is just a pseudocode):

    IEnumerable<string> ShortestPath(string fromState, string toState, Transition[] currentTransitions) {
        var map = new Dictionary<string, string>();
        var edges = currentTransitions.ToDictionary(i => i.From, i => i.To);
        var q = new Queue<string>(); 
        map.Add(fromState, null);
        q.Enqueue(fromState);
        while (q.Count > 0) {
            var current = q.Dequeue();
            foreach (var s in edges[current]) {
                if (!map.ContainsKey(s)) {
                    map.Add(s, current);
                    if (s == toState) {
                        var result = new Stack<string>();
                        var thisNode = s;
                        do {
                            result.Push(thisNode);
                            thisNode = map[thisNode];
                        } while (thisNode != fromState);
                        while (result.Count > 0)
                            yield return result.Pop();
                        yield break;
                    }
                    q.Enqueue(s);
                }
            }
        }
        // no path exists
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 370k
  • Answers 370k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I think you're asking for a dictionary type in Java.… May 14, 2026 at 6:37 pm
  • Editorial Team
    Editorial Team added an answer Use the Post/Redirect/Get pattern to avoid this problem. See also… May 14, 2026 at 6:37 pm
  • Editorial Team
    Editorial Team added an answer I find that changing the UI by hiding/showing controls can… May 14, 2026 at 6:37 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.