There's no algorithm; you're using inconsistent logic Consider just the set C:\XML C:\MyProg\Raw C:\MyProg\Subset\MTSAT C:\MyProg\Subset\GOESW There are at least 4 different solutions: C: C:\XML and C:\MyProg C:\XML , C:\MyProg\Raw and C:\MyProg\Subset C:\XML , C:\MyProg\Raw, C:\MyProg\Subset\MTSAT and C:\MyProg\Subset\GOESW You fail to explain why 2. Is the correct solution. It is possible to write an algorithm that finds solution N-1 given solution N as input, so you can get from the input (4) to (1) in three steps.
But we don't understand why we should stop at (2).
There's no algorithm; you're using inconsistent logic. Consider just the set C:\XML C:\MyProg\Raw C:\MyProg\Subset\MTSAT C:\MyProg\Subset\GOESW There are at least 4 different solutions: C:\ C:\XML and C:\MyProg\ C:\XML , C:\MyProg\Raw and C:\MyProg\Subset C:\XML , C:\MyProg\Raw, C:\MyProg\Subset\MTSAT and C:\MyProg\Subset\GOESW You fail to explain why 2. Is the correct solution.It is possible to write an algorithm that finds solution N-1 given solution N as input, so you can get from the input (4) to (1) in three steps.
But we don't understand why we should stop at (2).
Thank you for your answer. 1. C:\XML 2.
C:\MyProg\Raw 3. C:\MyProg\Subset\MTSAT 4. C:\Myprog\Subset\GOESW There are only 2 different solutions: They are: 1.
C:\XML and C:\MyProg 2. C:\XML, C:\MyProg and C:\MyProg\Subset – GoldenLee Sep 22 at 15:33 @GoldenLee: C:\ is the common parent of C:\XML\ and C:\MyProg\ , and therefore a solution. Unless there's some "magical" exception to the rule that Parent\Child1\ and Parent\Child2\ cannot be replaced by Parent\ , in which case you should have told us.
– MSalters Sep 22 at 15:36 Because nobody would like to watch the whole logical drive. As for either only C:\MyProg or both C:\MyProg and C:\MyProg\Subset are watched it depends on user's practical utilization. – GoldenLee Sep 22 at 15:37 I don't want to throw away the path which has no common path with the others.
I expect it to be returned unchanged. The purpose of finding any possible "common path" among the user-defined original path(s) is to minimize the number of watching folder(s) by watching their "parent" folder with "Watch Include Subdirectory" switch setting on. – GoldenLee Sep 22 at 16:26 @GoldenLee: It's an arbitrary rule, but at least it's a rule.
Would have been useful if you had mentioned that. But would people want to watch the whole of C:\Documents And Settings\? We really can't guess your precise rules.
– MSalters Sep 22 at 18:25.
A two-step algorithm: Partition your directories by drive letter and first directory level. For each partition, keep the longest prefix. The longest prefix per partition can be easily obtained by counting how many prefix characters each directory has in common with its next sibling, and keeping the minimum.
Using mismatch, for example.
Thank you very much! But your algorithm is not a "good and generic" one. For example, we have the following paths: "C:/home/user1/tmp/coverage/test", "C:/home/user1/tmp/covert/operator", "C:/home/user1/tmp/coven/members Apparently, "C:/home/user1/tmp" will be expected to be returned, not "C:/home".
– GoldenLee Sep 22 at 15:07 You're not going to have a perfect algorithm until you're able to actually define "least common" instead of saying "your answer isn't it because it fails in such or such case I never told you about beforehand" – JB. Sep 22 at 15:11 For example, keeping your contrived example, what do you expect to happen if I add C:\home\user1\other\directory? What about C:\home\other\directory?
And C:\other\directory? – JB. Sep 22 at 15:14 I'm very sorry for my phrase "least common".
It's somewhat misleading. – GoldenLee Sep 22 at 15:20 For your above-contrived example, I expect to return C:\home and C:\other\directory. – GoldenLee Sep 22 at 15:23.
As JB said I think this is a two step solution and I have tried some basic coding here in C#. If you want it in java I suppose you must be knowing how to use it :) using System; using System.Collections. Generic; using System.
Linq; using System. Text; using System. IO; namespace So_Try1 { class Program { public static int nthOccurrence(String str, char c, int n) { int pos = str.
IndexOf(c, 0); while (n-- > 0 && pos! = -1) pos = str. IndexOf(c, pos + 1); return pos; } static void Main(string args) { List pathString = new List(); pathString.
Add("C:\\XML"); pathString. Add("C:\\MyProg\\Raw"); pathString. Add("C:\\MyProg\\Subset\\MTSAT"); pathString.
Add("C:\\MyProg\\Subset\\GOESW"); pathString. Add("D:\\Folder2\\Mosaic"); pathString. Add("D:\\Folder2\\Mosaic\\SubFolder"); pathString.
Add("D:\\Dataset\\Composite"); pathString. Add("D:\\Dataset\\Global"); pathString. Add("F:\\Folder1\\Mosaic"); pathString.
Add("H:\\Folder2\\Mosaic"); pathString. Add("D:\\Folder2\\Mosaic"); pathString. Add("D:\\Folder2\\Mosaic\\SubFolder"); pathString.
Add("E:\\Dataset\\Mosaic"); Dictionary PathDict = new Dictionary(); foreach (String str in pathString) { int count = 0; foreach (char c in str) if (c == '\\') count++; while (count > 0) { int index = nthOccurrence(str, '\\', count); String tempPath; if (index 0) { PathDictkeys++; } } PathDict. Add(tempPath, 1); } count--; } } foreach(var keyValue in PathDict){ if(keyValue. Value > 1) Console.
WriteLine(keyValue. Key); /*Console. WriteLine(keyValue.
Key + " - " + keyValue. Value);*/ } } } } This is a very simple program that assumes that you have your paths in a string and checking for duplicates. If for a large no.
Of paths you must adopt a much more efficient solution.
I'm not familiar with C# and .NET. Thank you any way. – GoldenLee Sep 22 at 15:26 C# is just a clone of Java.So I think it should not be a problem if you know Java well.
– Ajai Sep 22 at 15:32 Anyways I am having the same doubt as mentioned by @MSalters above. There might be different solutions based upon your question. Can you explain it in a more detailed manner?
– Ajai Sep 22 at 15:33 For the input given in my prog the following is the output. C:\MyProg C:\MyProg\Subset D:\Folder2\Mosaic D:\Folder2 D:\Folder2\Mosaic\SubFolder D:\Dataset – Ajai Sep 22 at 15:44 I don't want to throw away the path which has no common path with the others. I expect it to be returned unchanged.
The purpose of finding any possible "common path" among the user-defined original path(s) is to minimize the number of watching folder(s) by watching their "parent" folder with "Watch Include Subdirectory" switch setting on. – GoldenLee Sep 22 at 16:28.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.