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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T08:03:53+00:00 2026-05-29T08:03:53+00:00

I am making a timetabling application. The important classes are: Period id: int clazz:

  • 0

I am making a timetabling application. The important classes are:

Period
    id: int
    clazz: Clazz  
SubjectTeacher
    subject: String
    teacher: String
    clazz: Clazz
    AllocablePeriods: List<Period>

Here is example data, where Jane and John teach at one class, and Jane in another class.

{sub435, Jane-Algebra-Class1, {1,2,3,4,5,6,7,8}}
{sub124, Jane-Calculus-Class2, {9,10,11,12,13,14,15,16}}
{sub875, John-English-Class1, {1,2,3,4,5,6,7}} //he cannot take #8

My objective is to detect possible swaps for each SubjectTeacher. For example, in the above example, Jane-Algebra-Class1 and John-English-Class1 have potential swaps

{1,Jane-Algebra-Class1,John-English-Class1}
{2,Jane-Algebra-Class1,John-English-Class1}
...
{7,Jane-Algebra-Class1,John-English-Class1}

What is a good algorithm/technique to detect all possible swaps for all SubjectTeachers?

  • 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-29T08:03:54+00:00Added an answer on May 29, 2026 at 8:03 am

    I would expect that the number of AllocablePeriods is relatively small. Then what you can do is iterate over all teachers, iterate over all their periods and add each such period to a Map mapping a period identifier to the teachers that can teach during this period:

    Map<Integer, List<String> > periodTeachersMap = new HashMap<Integer, List<String>>();
    for (Teacher teacher: teachers) {
       for (AllocablePeriod period: teacher.getPeriods()) {
           if (periodTeachersMap.get(period.getId()) == null) {
               periodTeachersMap.put(period.getId(), new ArrayList<String>());
           }
           periodTeachersMap.get(period.getId()).add(teacher.getName());
       }
    }
    

    After this cycle you will have in periodTeachersMap for every period all the teachers that can teach in it. If you want the pairs themselves you can easily construct them from the List. I hope this will help you.

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

Sidebar

Related Questions

Making a new shooter game here in the vein of Galaga (my fav shooter
Making a search result list (like in Google) is not very hard, if you
Making a piano/keyboard application and trying to figure out the best way to set
Making my PHP Command line application support Linux and Windows. Currently it has this
im making a server for an application, and I made a thread for accepting
im making an application where i have to load my database from html file
After making a few changes in my application, my textures are no longer showing.
When making the case for library usage within an application, what arguments lead to
Making an argument parser. I want to split a string into an array where
im making a todo list app in php and im using unordered lists to

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.