Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find differences between 2 almost-identical files very fast?

Tags:

People also ask

How can I compare two files faster?

Right-click on the first file. Click on “Select for Compare” from the menu. Proceed to right-click on the second file. Click on “Compare with Selected.

How do I compare data between two files?

From the Micro Focus Data File Tools window, click Tools > Compare Files. The File Compare dialog box appears. Select the two data files to compare: In the File 1 section, click and select the required file.


If you have two mainly identical files with 1000s of records, how will you write code to find differences between them. Assume that unix/linux commands are not allowed to be used.

My idea:

Because most of entries are the same, we can sort the entries of the two files, then compare each entry one by one, e.g. entry i in file1 compare to entry i in file2. It is O(n lg n), n is size of file.

Are there O(n) solution ?