Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 1b4bf8e

Browse files
author
Ram swaroop
committed
comments added
1 parent 66e5dc1 commit 1b4bf8e

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/me/ramswaroop/arrays/SubsetOfArray.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,19 @@
1111
*/
1212
public class SubsetOfArray {
1313

14+
/**
15+
* Determines if array {@param b} is a subset of array {@param a}.
16+
* <p/>
17+
* Explanation: The below method uses sorting + merge method of merge sort. Time
18+
* complexity is O(mlogm + nlogn) where m and n are lengths of array a and b resp.
19+
* You could also have used sorting + binary search but this fails when superset
20+
* array has repeating elements for example, a={1,4,4,2} and b={1,4,2}. Time
21+
* complexity would be O(mlogm + nlogm).
22+
*
23+
* @param a
24+
* @param b
25+
* @return
26+
*/
1427
public static boolean isSubsetOfArray(int[] a, int[] b) {
1528

1629
QuickSort.quickSort(a);

0 commit comments

Comments
 (0)