Skip to content

Commit 8237fb9

Browse files
committed
Array Programs
1 parent 924d848 commit 8237fb9

File tree

9 files changed

+59
-33
lines changed

9 files changed

+59
-33
lines changed

InterviewPrograms/src/com/java/array/Average.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ public static void main(String[] args) {
3737
}
3838
/*
3939
OUTPUT
40-
4140
The Given Array is :
4241
10 20 30 40 50 60 70 80 90 100
4342
The Average of Given Array is : 55.0
4443
44+
OUTPUT
4545
The Given Array is :
4646
10 10 10 10 10
4747
The Average of Given Array is : 10.0

InterviewPrograms/src/com/java/array/FindMissingNo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@ public static void main(String[] args) {
5858
}
5959
/*
6060
OUTPUT
61-
6261
The Given Array is :
6362
2 4 1 6 7 5 3 9
6463
Missing Number is : 8
6564
65+
OUTPUT
6666
The Given Array is :
6767
2 4 1 6 3
6868
Missing Number is : 5

InterviewPrograms/src/com/java/array/FindMostFrequent.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,21 +61,21 @@ public static void main(String[] args) {
6161
}
6262
}
6363
/*
64-
Input
64+
INPUT
6565
{3, 9, 1, 3, 6, 3, 8, 1, 6}
66-
Output
66+
OUTPUT
6767
Most Frequent element is :: 3
6868
Occurred 3 times.
6969
70-
Input
70+
INPUT
7171
{1, 9, 1, 3, 2, 3, 10}
72-
Output
72+
OUTPUT
7373
Most Frequent element is :: 1
7474
Occurred 2 times.
7575
76-
Input
76+
INPUT
7777
{2, 1, 2, 2, 1, 3}
78-
Output
78+
OUTPUT
7979
Most Frequent element is :: 2
8080
Occurred 3 times.
8181
*/

InterviewPrograms/src/com/java/array/FindMostFrequentUsingHashtable.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
* 1 --> 1
5555
*
5656
* So 3 is the output
57-
* Because 3 repeated 3 times (max frequncy).
57+
* Because 3 repeated 3 times (max frequency).
5858
*
5959
*/
6060
public class FindMostFrequentUsingHashtable {
@@ -84,21 +84,21 @@ public static void main(String[] args) {
8484
}
8585
}
8686
/*
87-
Input
87+
INPUT
8888
{3, 9, 1, 3, 6, 3, 8, 1, 6}
89-
Output
89+
OUTPUT
9090
Most Frequent element is :: 3
9191
Frequency of the element is :: 3
9292
93-
Input
93+
INPUT
9494
{1, 9, 1, 3, 2, 3, 10}
95-
Output
95+
OUTPUT
9696
Most Frequent element is :: 1
9797
Frequency of the element is :: 2
9898
99-
Input
99+
INPUT
100100
{2, 1, 2, 2, 1, 3}
101-
Output
101+
OUTPUT
102102
Most Frequent element is :: 2
103103
Frequency of the element is :: 3
104104
*/

InterviewPrograms/src/com/java/array/FindMostFrequentUsingSorting.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,21 +83,21 @@ public static void main(String[] args) {
8383
}
8484
}
8585
/*
86-
Input
86+
INPUT
8787
{3, 9, 1, 3, 6, 3, 8, 1, 6}
88-
Output
88+
OUTPUT
8989
Most Frequent element is :: 3
9090
Frequency of the element is :: 3
9191
92-
Input
92+
INPUT
9393
{1, 9, 1, 3, 2, 3, 10}
94-
Output
94+
OUTPUT
9595
Most Frequent element is :: 1
9696
Frequency of the element is :: 2
9797
98-
Input
98+
INPUT
9999
{2, 1, 2, 2, 1, 3}
100-
Output
100+
OUTPUT
101101
Most Frequent element is :: 2
102102
Frequency of the element is :: 3
103103
*/

InterviewPrograms/src/com/java/array/FindUniqueElt.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ public static void main(String[] args) {
4242
}
4343
/*
4444
OUTPUT
45-
4645
Given array is :
4746
1 2 3 4 5 6 1 2 3 4 5
4847
Unique element in the array is : 6
4948
49+
OUTPUT
5050
Given array is :
51-
51+
{5, 10, 33, 42, 5, 42, 10};
5252
Unique element in the array is : 33
5353
*/

InterviewPrograms/src/com/java/array/FindingAllSubsets.java

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,25 @@
11
package com.java.array;
22

3+
/*
4+
* Find All Possible Subsets of Given Array
5+
*
6+
* say Given array is
7+
* {a, b, c, d}
8+
*
9+
* Possible subsets are
10+
* {a} {b} {c} {d}
11+
* {a, b} {a, c} {a, d} {b, c} {b, d} {c, d}
12+
* {a, b, c} {a, b, d} {a, c, d} {b, c, d}
13+
* {a, b, c, d}
14+
*
15+
*/
316
public class FindingAllSubsets {
4-
517
public static void main(String[] args) {
618
//solution 1 follows bitwise approach
7-
// solution1();
19+
solution1();
820

921
//solution 2 follows recursion approach
10-
solution2();
22+
// solution2();
1123
}
1224

1325
public static void solution1() {
@@ -45,8 +57,22 @@ public static void traverse(int array[],int visited[],int curIndex){
4557
}
4658

4759
/*
48-
*
49-
* Input: S = {a, b, c, d} Output: {}, {a} , {b}, {c}, {d}, {a,b}, {a,c}, {a,d},
50-
* {b,c}, {b,d}, {c,d}, {a,b,c}, {a,b,d}, {a,c,d}, {b,c,d}, {a,b,c,d}
51-
*
52-
*/
60+
OUTPUT
61+
input array is :: {a, b, c, d}
62+
{ }
63+
{ a }
64+
{ b }
65+
{ a b }
66+
{ c }
67+
{ a c }
68+
{ b c }
69+
{ a b c }
70+
{ d }
71+
{ a d }
72+
{ b d }
73+
{ a b d }
74+
{ c d }
75+
{ a c d }
76+
{ b c d }
77+
{ a b c d }
78+
*/

InterviewPrograms/src/com/java/array/IntersectionOfTwoArrays.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,4 @@ public static void main(String[] args) {
5757
Given array 1 is : 44 49 30 25 67 69
5858
Given array 2 is : 88 44 69 93 30
5959
Intersection of the array 1 & 2 is : 44 30 69
60-
*/
61-
60+
*/

InterviewPrograms/src/com/java/array/UnionOfSortedArrays.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
package com.java.array;
23

34
import java.util.ArrayList;

0 commit comments

Comments
 (0)