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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T06:39:49+00:00 2026-06-06T06:39:49+00:00

I have a vector of pairs representing hops between nodes which I would like

  • 0

I have a vector of pairs representing hops between nodes which I would like to collapse when there are cycles (as in aggregate time between the hops in a cycle to display it as just one). So, for example, The path A –> B –> C –> D –> B –> C –> D –> E traverses the subpath B–> C –> D twice, so in my structure I would have something like:

(A,B,1)(B,C,3)(C,D,2)(D,B,4)(B,C,5)(C,D,8)(D,E,6)

which I would ideally reduce to:

(A,B,1)(B,C,3+5)(C,D,2+8)(D,E,6)

storing also the 4 from D to B (loop-back edge time) to aggregate separately and be able to display B –> C –> D in a condensed way (the aggregated edge times and an aggregated loop-back time for all the D–>B instances alongside a count of how many times we looped)

How can I go about this?

  • 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-06T06:39:52+00:00Added an answer on June 6, 2026 at 6:39 am

    I would go for a suffix array or suffix tree.
    Just produce tokens (in this case (from, to) ) and put it in the Suffix Array or Suffix Tree. Then you can get the pairs.
    Simple but not efficietn way:

    produce tokens, produce all suffixes of this tokenstream. sort them. and then you have all common subsequences in that sorted list near each other (tokenstream length – tokenstream suffix length = position)
    You could do the sorting with quicksort for example, or you just looking for a suffix array implemantation. Suffix Arrays could be constructed in O(n) and with O(n) space. And finding maximal pairs/repeats (thats what you want) can be done in O(n+k) (where n = tokennumber, and k = cycles in your list)

    Perhaps this helps. Then you could produce a tokenstream like: ABCDBCDE

    Quick and dirty solution is here

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

Sidebar

Related Questions

I have a vector of pointers. I would like to call a function for
I have an arbitrary number of lists which I would like to process using
If I have a vector of pairs: std::vector<std::pair<int, int> > vec; Is there and
I have the following class which stores pairs of dates and prices: #include <vector>
I have a vector of pointers to objects. I'd like to remove objects from
Suppose that I have a vector of key-value pairs that I want to put
I have a map with about 100,000 pairs . Is there any way that
In R, I have two vectors of pairs like this: x <- c(A=5, B=1,
So I tried to make a vector which elements are pairs of a struct
so I have a vector of pairs of pointers in c++: vector<pair<Move *,Piece *>

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.