Skip to content

Commit d6a5572

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents 5f8c0c8 + dcfde17 commit d6a5572

23 files changed

+128
-121
lines changed

Conversions/HexaDecimalToBinary.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import java.util.Scanner;
44
import javax.swing.*;
55

6-
public class HexaToBin {
6+
public class HexaDecimalToBinary {
77

88
private final int LONG_BITS = 8;
99

@@ -28,10 +28,10 @@ public static void main(String[] args) {
2828
//Testing Numbers:
2929
String[] hexNums = {"1", "A1", "ef", "BA", "AA", "BB",
3030
"19", "01", "02", "03", "04"};
31-
Convert objConvert = new Convert();
31+
HexaDecimalToBinary objConvert = new HexaDecimalToBinary();
3232

3333
for (String num : hexNums) {
3434
objConvert.convert(num);
3535
}
3636
}
37-
}
37+
}

Conversions/OctalToDecimal.java

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,42 +7,41 @@
77
*
88
*/
99
public class OctalToDecimal {
10-
10+
1111
/**
1212
* Main method
1313
*
14-
* @param args Command line arguments
14+
* @param args
15+
* Command line arguments
1516
*/
1617
public static void main(String args[]) {
1718
Scanner sc = new Scanner(System.in);
18-
int o = sc.nextInt();
19-
System.out.println("Decimal equivalent: " + convertOctalToDecimal(o));
19+
System.out.print("Octal Input: ");
20+
String inputOctal = sc.nextLine();
21+
int result = convertOctalToDecimal(inputOctal);
22+
if (result != -1)
23+
System.out.println("Result convertOctalToDecimal : " + result);
2024
sc.close();
2125
}
22-
26+
2327
/**
24-
* This method converts an octal number to
25-
* a decimal number.
28+
* This method converts an octal number to a decimal number.
2629
*
27-
* @param o The octal number
30+
* @param inputOctal
31+
* The octal number
2832
* @return The decimal number
2933
*/
30-
public static int convertOctalToDecimal(int o) {
31-
System.out.print("Octal Input: ");
32-
// Read the input from the console which we are expecting as an octal number:
33-
Scanner s = new Scanner(System.in);
34-
String inputHex = s.nextLine();
35-
try{
34+
public static int convertOctalToDecimal(String inputOctal) {
35+
36+
try {
3637
// Actual conversion of Octal to Decimal:
37-
Integer outputDecimal = Integer.parseInt(inputHex, 8);
38-
System.out.println("Decimal Equivalent : " + outputDecimal);
39-
}
40-
catch(NumberFormatException ne){
41-
// Printing a warning message if the input is not a valid octal number:
38+
Integer outputDecimal = Integer.parseInt(inputOctal, 8);
39+
return outputDecimal;
40+
} catch (NumberFormatException ne) {
41+
// Printing a warning message if the input is not a valid octal
42+
// number:
4243
System.out.println("Invalid Input, Expecting octal number 0-7");
43-
}
44-
finally{
45-
s.close();
44+
return -1;
4645
}
4746
}
4847
}

Data Structures/Graphs/BFS.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* @author Unknown
77
*
88
*/
9-
public class bfs{
9+
public class BFS{
1010

1111
/**
1212
* The BFS implemented in code to use.

Data Structures/Graphs/DFS.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*/
99

10-
public class dfs{
10+
public class DFS{
1111

1212
/**
1313
* Implementation in code of a DFS

Data Structures/Graphs/MatrixGraphs.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public boolean removeEdge(int from, int to) {
120120
}
121121

122122
/**
123-
* this gives a list of verticies in the graph and their adjacencies
123+
* this gives a list of vertices in the graph and their adjacencies
124124
*
125125
* @return returns a string describing this graph
126126
*/

Data Structures/Graphs/PrimMST.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public static void main (String[] args)
100100
| / \ |
101101
(3)-------(4)
102102
9 */
103-
MST t = new MST();
103+
PrimMST t = new PrimMST();
104104
int graph[][] = new int[][] {{0, 2, 0, 6, 0},
105105
{2, 0, 3, 8, 5},
106106
{0, 3, 0, 0, 7},

Data Structures/Trees/AVLTree.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
public class AVLtree {
1+
public class AVLTree {
22

33
private Node root;
44

@@ -200,7 +200,7 @@ private void reheight(Node node){
200200
}
201201

202202
public static void main(String[] args) {
203-
AVLtree tree = new AVLtree();
203+
AVLTree tree = new AVLTree();
204204

205205
System.out.println("Inserting values 1 to 10");
206206
for (int i = 1; i < 10; i++)

Data Structures/Trees/LevelOrderTraversal.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ public Node(int item)
99
}
1010
}
1111

12-
class BinaryTree
12+
public class LevelOrderTraversal
1313
{
1414
// Root of the Binary Tree
1515
Node root;
1616

17-
public BinaryTree()
17+
public LevelOrderTraversal()
1818
{
1919
root = null;
2020
}
@@ -65,7 +65,7 @@ else if (level > 1)
6565
/* Driver program to test above functions */
6666
public static void main(String args[])
6767
{
68-
BinaryTree tree = new BinaryTree();
68+
LevelOrderTraversal tree = new LevelOrderTraversal();
6969
tree.root= new Node(1);
7070
tree.root.left= new Node(2);
7171
tree.root.right= new Node(3);

Data Structures/Trees/LevelOrderTraversalQueue.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public Node(int item) {
1414
}
1515

1616
/* Class to print Level Order Traversal */
17-
class BinaryTree {
17+
public class LevelOrderTraversalQueue {
1818

1919
Node root;
2020

@@ -49,7 +49,7 @@ public static void main(String args[])
4949
{
5050
/* creating a binary tree and entering
5151
the nodes */
52-
BinaryTree tree_level = new BinaryTree();
52+
LevelOrderTraversalQueue tree_level = new LevelOrderTraversalQueue();
5353
tree_level.root = new Node(1);
5454
tree_level.root.left = new Node(2);
5555
tree_level.root.right = new Node(3);

Data Structures/Trees/PrintTopViewofTree.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public void printTopView()
7878
}
7979

8080
// Driver class to test above methods
81-
public class Main
81+
public class PrintTopViewofTree
8282
{
8383
public static void main(String[] args)
8484
{

Data Structures/Trees/ValidBSTOrNot.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public Node(int item)
1010
}
1111
}
1212

13-
public class BinaryTree
13+
public class ValidBSTOrNot
1414
{
1515
//Root of the Binary Tree
1616
Node root;
@@ -47,7 +47,7 @@ boolean isBSTUtil(Node node, int min, int max)
4747
/* Driver program to test above functions */
4848
public static void main(String args[])
4949
{
50-
BinaryTree tree = new BinaryTree();
50+
ValidBSTOrNot tree = new ValidBSTOrNot();
5151
tree.root = new Node(4);
5252
tree.root.left = new Node(2);
5353
tree.root.right = new Node(5);

Dynamic Programming/LevenshteinDistance.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
*/
88

9-
public class Levenshtein_distance{
9+
public class LevenshteinDistance{
1010
private static int minimum(int a, int b, int c){
1111
if(a < b && a < c){
1212
return a;

Misc/heap_sort.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
public class HeapSort
1+
public class heap_sort
22
{
33
public void sort(int arr[])
44
{
@@ -64,7 +64,7 @@ public static void main(String args[])
6464
int arr[] = {12, 11, 13, 5, 6, 7};
6565
int n = arr.length;
6666

67-
HeapSort ob = new HeapSort();
67+
heap_sort ob = new heap_sort();
6868
ob.sort(arr);
6969

7070
System.out.println("Sorted array is");

Others/BrianKernighanAlgorithm.java

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import java.util.Scanner;
2+
3+
/**
4+
*
5+
* @author Nishita Aggarwal
6+
*
7+
* Brian Kernighan’s Algorithm
8+
*
9+
* algorithm to count the number of set bits in a given number
10+
*
11+
* Subtraction of 1 from a number toggles all the bits (from right to left) till the rightmost set bit(including the
12+
* rightmost set bit).
13+
* So if we subtract a number by 1 and do bitwise & with itself i.e. (n & (n-1)), we unset the rightmost set bit.
14+
*
15+
* If we do n & (n-1) in a loop and count the no of times loop executes we get the set bit count.
16+
*
17+
*
18+
* Time Complexity: O(logn)
19+
*
20+
*/
21+
22+
23+
public class BrianKernighanAlgorithm {
24+
25+
/**
26+
* @param num: number in which we count the set bits
27+
*
28+
* @return int: Number of set bits
29+
* */
30+
static int countSetBits(int num)
31+
{
32+
int cnt = 0;
33+
while(num != 0)
34+
{
35+
num = num & (num-1);
36+
cnt++;
37+
}
38+
return cnt;
39+
}
40+
41+
42+
/**
43+
*
44+
* @param args : command line arguments
45+
*
46+
*/
47+
public static void main(String args[])
48+
{
49+
Scanner sc = new Scanner(System.in);
50+
int num = sc.nextInt();
51+
int setBitCount = countSetBits(num);
52+
System.out.println(setBitCount);
53+
sc.close();
54+
}
55+
}

Others/Dijkshtra.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import java.util.Scanner;
1010
import java.util.Stack;
1111

12-
public class Solution {
12+
public class Dijkshtra {
1313

1414
public static void main(String[] args) throws IOException {
1515
Scanner in =new Scanner(System.in);

Others/FibToN.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public static void main(String[] args) {
99
// print fibonacci sequence less than N
1010
int first = 0, second = 1;
1111
//first fibo and second fibonacci are 0 and 1 respectively
12-
12+
scn.close();
1313
while(first <= N){
1414
//print first fibo 0 then add second fibo into it while updating second as well
1515

Others/FindingPrimes.java

Lines changed: 0 additions & 45 deletions
This file was deleted.

Others/FloydTriangle.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ public static void main(String[] args) {
66
Scanner sc = new Scanner(System.in);
77
System.out.println("Enter the number of rows which you want in your Floyd Triangle: ");
88
int r = sc.nextInt(), n = 0;
9-
9+
sc.close();
1010
for(int i=0; i < r; i++) {
1111
for(int j=0; j <= i; j++) {
1212
System.out.print(++n + " ");

Others/InsertDeleteInArray.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import java.util.*;
2-
public class Array {
2+
public class InsertDeleteInArray {
33

44
public static void main(String[] args) {
55
Scanner s = new Scanner(System.in); // Input statement

Others/RootPrecision.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import java.math.*;
55
import java.util.regex.*;
66

7-
public class Solution {
7+
public class RootPrecision {
88

99
public static void main(String[] args) {
1010
//take input

Others/StackPostfixNotation.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import java.util.*;
22

3-
public class Postfix {
3+
public class StackPostfixNotation {
44
public static void main(String[] args) {
55
Scanner scanner = new Scanner(System.in);
66
String post = scanner.nextLine(); // Takes input with spaces in between eg. "1 21 +"

Others/countwords.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @author Marcus
88
*
99
*/
10-
class CountTheWords{
10+
public class countwords{
1111

1212
public static void main(String[] args){
1313
Scanner input = new Scanner(System.in);

0 commit comments

Comments
 (0)