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

  • Home
  • SEARCH
  • 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 114121
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T02:48:37+00:00 2026-05-11T02:48:37+00:00

I have a resource scheduling issue in Java where things need to be sequenced,

  • 0

I have a resource scheduling issue in Java where things need to be sequenced, but there are restrictions on what resources can be next to each other. A good analogy is a string of ‘digits’, where only certain digits can be next to each other. My solution was recursive, and works fine for small strings, but run time is O(X^N), where X is the number of possible digits (the base), and N is the length of the string. It quickly becomes unmanageable.

Using the compatibility matrix below, here are a few examples of allowed strings
Length of 1: 0, 1, 2, 3, 4
Length of 2: 02, 03, 14, 20, 30, 41
Length of 3: 020, 030, 141, 202, 203, 302, 303, 414

      0  1  2  3  4    --------------------- 0|  0  0  1  1  0 1|  0  0  0  0  1 2|  1  0  0  0  0 3|  1  0  0  0  0 4|  0  1  0  0  0 

My solution for counting all strings of length N was start with an empty string, permute the first digit, and make a recursive call for all strings of length N-1. The recursive calls check the last digit that was added and try all permutations that can be next to that digit. There are some optimizations made so that I don’t try and permute 00, 01, 04 every time, for example – only 02, 03, but performance is still poor as it scales from base 5 (the example) to base 4000.

Any thoughts on a better way to count the permutations other than trying to enumerate all of them?

  • 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. 2026-05-11T02:48:37+00:00Added an answer on May 11, 2026 at 2:48 am

    If you just want the number of strings of a certain length, you could just multiply the compatibility matrix with itself a few times, and sum it’s values.

    n = length of string
    A = compatibility matrix
    number of possible strings = sum of An-1

    A few examples:

    n = 1 | 1 0 0 0 0 | | 0 1 0 0 0 | | 0 0 1 0 0 | | 0 0 0 1 0 | | 0 0 0 0 1 | sum: 5  n = 3 | 2 0 0 0 0 | | 0 1 0 0 0 | | 0 0 1 1 0 | | 0 0 1 1 0 | | 0 0 0 0 1 | sum: 8  n = 8 | 0 0 8 8 0 | | 0 0 0 0 1 | | 8 0 0 0 0 | | 8 0 0 0 0 | | 0 1 0 0 0 | sum: 34 

    The original matrix (row i, column j) could be thought of as the number of strings that start with symbol i, and whose next symbol is symbol j. Alternatively, you could see it as number of strings of length 2, which start with symbol i and ends with symbol j.

    Matrix multiplication preserves this invariant, so after exponentiation, An-1 would contain the number of strings that start with symbol i, has length n, and ends in symbol j.

    See Wikipedia: Exponentiation by squaring for an algorithm for faster calculation of matrix powers.

    (Thanks stefan.ciobaca)

    This specific case reduces to the formula:

    number of possible strings = f(n) = 4 + Σk=1..n 2⌊k-1⁄2⌋ = f(n-1) + 2⌊n-1⁄2⌋

    n       f(n) ----    ----    1       5    2       6    3       8    4      10    5      14    6      18    7      26    8      34    9      50   10      66 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Not the .map file that I know. PDB files are… May 12, 2026 at 6:53 pm
  • Editorial Team
    Editorial Team added an answer Well, I found some answer but it didn't solved the… May 12, 2026 at 6:53 pm
  • Editorial Team
    Editorial Team added an answer MySQL has a ROUND() function. So just round your average… May 12, 2026 at 6:53 pm

Related Questions

ORIGINAL Q: I'm wondering if anyone has had experience of migrating a large Cobol/PL1
I'm writing up a scheduling application for my wife, and I ran into the
I am using simulated annealing to solve an NP-complete resource scheduling problem. For each
I needed to do some higher-level project planning that doesn't really fit into the

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.