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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T09:04:51+00:00 2026-05-19T09:04:51+00:00

A colleague came to me with a problem that I managed to answer but

  • 0

A colleague came to me with a problem that I managed to answer but I don’t know if my answer is right or even good…

He is creating a program to compare data in various files – in this case excel spreadsheets. He has a list of comparisons which will boil down to two files with references to cells in them. For each comparison it is necessary to open the files, do the comparison and then close the files.

Of course this can be optimised if you order the comparisons such that you can keep one file and just change the other.

So how should you sort the files to minimise the number of times you need to close and open files?

It should be noted that the idea of just having all files open is not feasible since there could be over 500 different spreadsheets being compared.

My solution was to find the table that occurs in most comparisons and process all the comparisons involving that first. Then repeat the process ignoring all the comparisons that have already been done.

I am wondering if when you process that first batch you want to do the least common ones first, ending up with the most common appearing table – this is then the table you process next (meaning still only one file change).

So can anybody either give me a better option or confirm that my idea is good (or good enough)?

Concrete example:

Here is an example list of comparisons with a note next to them showing how many files need to be unloaded and loaded each time. eg after Comparing fileA and fileB it only needs to unload FileB and load FileC to do the next compariosn. After comparing FileA and FileF it needs to unload both to load FileB and FileC.

FileA   FileB   
FileA   FileC   One file change
FileA   FileD   One file change
FileA   FileE   One file change
FileA   FileF   One file change
FileB   FileC   Two file changes
FileB   FileF   One file change
FileC   FileD   Two file changes
FileC   FileE   One file change
FileD   FileF   Two file changes
FileE   FileF   One file change

In theory in this example the order of the comparisons can be rearranged to make it so that at each step you only need to unload and reload one file.

FileA   FileB   
FileA   FileD   One file change
FileA   FileE   One file change
FileA   FileF   One file change
FileA   FileC   One file change
FileB   FileC   One file change
FileC   FileD   One file change
FileC   FileE   One file change
FileE   FileF   One file change
FileB   FileF   One file change
FileD   FileF   One file change

So what I want to know is what the best algorithm is to sort the file pairs to get the minimum number of total file unload/load operations.

I should note that it is not always going to be posible to get it down to one file change each time as demonstrated by the trivial pair of comparisons below:

FileA   FileB   
FileC   FileD   Two file changes
  • 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-19T09:04:51+00:00Added an answer on May 19, 2026 at 9:04 am

    Here’s an idea:

    Consider a graph where each file is a node, and each required comparison is an edge.

    Now, if you find a Eulerian Path in the graph, this path will represent a sequence such that only one file replacement happens after each comparison.

    If no Eulerian Path exists, then once you cannot proceed with the path, just jump to some node with an odd number of edges (and if all of them have an even number of edges, just pick any node). This approach will probably still give you the best results, but at some point(s) in the sequence, you will have to replace two files instead of one. I believe it should be easy to prove that if no Eulerian Path exists, then no sequence exists that only replaces one file at each step.

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

Sidebar

Related Questions

Possible Duplicate: Learning efficient algorithms I recently came across an problem that was solved
I came across this problem via a colleague today. He had a design for
A colleague came across some code that looked like this and couldn't understand how
Yesterday I read some code of a colleague and came across this: class a_class
A colleague once told me that the last option when everything has failed to
A colleague of mine states that booleans as method arguments are not acceptable .
A colleague recently asked me how to deep-clone a Map and I realized that
My colleague here argues that new programmers must learn ASP first, before they learn
I just came across a piece of code written by my ex-colleague few years
A colleague once said that God is killing a kitten every time I write

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.