This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Main { | |
public static void main(String[] args) { | |
TreeNode root = new TreeNode(5); | |
root.insert(1); | |
root.insert(3); | |
root.insert(7); | |
root.insert(9); | |
System.out.println(root.contains(2)); | |
System.out.println(root.contains(3)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Main { | |
public static void main(String[] args) { | |
Node head = new Node(5); | |
LinkedList linkedList = new LinkedList(head); | |
linkedList.append(6); | |
linkedList.append(7); | |
linkedList.prepend(4); | |
linkedList.deleteWithValue(7); | |
linkedList.printList(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.LinkedList; | |
class Main { | |
public static void main(String[] args) { | |
HashTable<String, String> hashTable = new HashTable<>(); | |
hashTable.put("Azam", "hello"); | |
hashTable.put("Shahani", "world"); | |
System.out.println(hashTable.get("Azam")); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BinarySearch { | |
public static void main(String[] args) { | |
int[] arr = new int[]{1, 2, 3, 4, 5}; | |
System.out.println(binarySearch(arr,4)); | |
} | |
public static boolean binarySearch(int[] arr, int num) { | |
int low = 0; | |
int high = arr.length-1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BinarySearch { | |
public static void main(String[] args) { | |
int[] arr = new int[]{1, 2, 3, 4, 5}; | |
System.out.println(binarySearch(arr, 0, arr.length-1, 5)); | |
} | |
public static boolean binarySearch(int[] arr, int left, int right, int num) { | |
if (left <= right) { | |
int mid = (left + right) / 2; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Quicksort { | |
public static void main(String[] args) { | |
int[] arr = new int[]{4, 6, 2, 3, 5, 8, 9, 1}; | |
quicksort(arr, 0, arr.length-1); | |
printArr(arr); | |
} | |
public static void quicksort(int[] arr, int left, int right) { | |
if (left < right) { | |
int pivot = arr[(left + right)/2]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MergeSort { | |
public static void main (String args[]) { | |
int[] arr = new int[]{5, 2, 3, 1, 4}; | |
int[] helperArr = new int[arr.length]; | |
mergeSort(arr, helperArr, 0, arr.length-1); | |
for (int i : arr) { | |
System.out.print(i + " "); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Knapsack { | |
public static void main(String[] args) { | |
int val[] = new int[]{0, 60, 100, 120}; | |
int wt[] = new int[]{0, 10, 20, 30}; | |
int W = 50; | |
int n = val.length-1; | |
int[][] memo = new int[n+1][W+1]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Knapsack { | |
public static void main(String[] args) { | |
int val[] = new int[]{0, 60, 100, 120}; | |
int wt[] = new int[]{0, 10, 20, 30}; | |
int W = 50; | |
int n = val.length-1; | |
System.out.println(Knapsack.knapsack(wt, val, W, n)); | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
class PermuteString { | |
public static void main(String[] args) { | |
String abc = "ABC"; | |
System.out.println(Solution.permutation(abc)); | |
} | |
} | |
class Solution { |
NewerOlder