├── .idea ├── description.html ├── encodings.xml ├── inspectionProfiles │ └── Project_Default.xml ├── misc.xml ├── modules.xml ├── project-template.xml ├── uiDesigner.xml ├── vcs.xml └── workspace.xml ├── Crux.iml ├── README.md ├── out ├── Doubts │ ├── DivisibleSubarrays.java │ ├── IsSorted.java │ ├── Random.java │ ├── Solution.java │ └── input.java └── production │ └── Crux │ └── com │ └── company │ ├── Lecture10 │ ├── Arrays_2D.class │ ├── Dictionary.class │ ├── Maze.class │ ├── MazeBoard.class │ └── NQueens.class │ ├── Lecture11 │ ├── MergeSort.class │ ├── QuickSort.class │ └── SumDivideArray.class │ ├── Lecture12 │ ├── CountPallindrome.class │ ├── DP_Intro.class │ ├── Dice.class │ ├── EditDistance.class │ ├── EggDrop.class │ ├── LongSubseq.class │ ├── MazeDP.class │ └── ZeroOneKnapsack.class │ ├── Lecture13 │ ├── CheckParanthesis.class │ ├── Client.class │ ├── DynamicStack.class │ ├── Human.class │ ├── Queue.class │ ├── QueueClient.class │ ├── Stack.class │ └── StackClient.class │ ├── Lecture14 │ ├── CircularQueue.class │ ├── DynamicCircularQueue.class │ └── inheritance │ │ ├── Car.class │ │ ├── Client.class │ │ ├── Maruti.class │ │ └── Vehicle.class │ ├── Lecture15 │ ├── CBStudent.class │ ├── CBTeacher.class │ ├── CB_TA.class │ ├── Car.class │ ├── CarChild.class │ ├── Client.class │ ├── Composition │ │ ├── Brake.class │ │ ├── Car.class │ │ ├── Client.class │ │ ├── Engine.class │ │ ├── GenericBrake.class │ │ ├── NitroEngine.class │ │ ├── PetrolEngine.class │ │ └── Steering.class │ ├── Main.class │ ├── Other │ │ ├── Sample.class │ │ └── SampleChild.class │ ├── StackQueue │ │ ├── QueueUsingStackInsert.class │ │ ├── QueueUsingStackRemove.class │ │ └── SampleStack.class │ ├── Students.class │ ├── TA.class │ └── Teacher.class │ ├── Lecture16 │ ├── Client.class │ ├── LinkedList$Node.class │ ├── LinkedList.class │ └── QueueStack │ │ ├── Client.class │ │ ├── StackUsingQueuePop.class │ │ └── StackUsingQueuePush.class │ ├── Lecture17 │ ├── BinaryTree$Node.class │ ├── BinaryTree.class │ ├── LinkedList$Node.class │ ├── LinkedList.class │ ├── LinkedListGeneric$Node.class │ ├── LinkedListGeneric.class │ ├── ListClient.class │ └── TreeClient.class │ ├── Lecture18 │ ├── BST$Node.class │ ├── BST.class │ ├── BSTClient.class │ ├── BSTClientNew.class │ ├── BinaryTree$Node.class │ ├── BinaryTree.class │ ├── BinaryTreeGeneric$Node.class │ ├── BinaryTreeGeneric.class │ ├── GenericClient.class │ └── TreeClient.class │ ├── Lecture19 │ ├── Greedy │ │ ├── KnapSack$Item.class │ │ └── KnapSack.class │ ├── Heap.class │ ├── HeapClient.class │ ├── Human.class │ ├── Main.class │ └── PQClient.class │ ├── Lecture2 │ ├── Leap.class │ ├── Loop.class │ └── Main.class │ ├── Lecture20 │ ├── CustomHashSet$Node.class │ ├── CustomHashSet.class │ ├── CustomHashTable$Node.class │ ├── CustomHashTable.class │ ├── Main.class │ ├── Questions.class │ ├── SetClient.class │ ├── TableUsingArray$Node.class │ ├── TableUsingArray.class │ ├── TableUsingList$Node.class │ └── TableUsingList.class │ ├── Lecture21 │ ├── AdjListGraph$Vertex.class │ ├── AdjListGraph.class │ ├── EdgeListGraph$Edge.class │ ├── EdgeListGraph$Vertex.class │ ├── EdgeListGraph.class │ └── GraphClient.class │ ├── Lecture22 │ ├── AdjMapGraph$Vertex.class │ ├── AdjMapGraph.class │ ├── AdjMapWeightGraph$DjPair.class │ ├── AdjMapWeightGraph$Edge.class │ ├── AdjMapWeightGraph$Vertex.class │ ├── AdjMapWeightGraph.class │ └── GraphClient.class │ ├── Lecture23 │ ├── CustomException.class │ ├── ExceptionClient.class │ ├── ScannerExmple.class │ ├── Sudoku.class │ └── ThreadExample.class │ ├── Lecture24 │ ├── JobSequence$Job.class │ ├── JobSequence.class │ └── LongPallindromeSubseq.class │ ├── Lecture3 │ ├── Converter.class │ ├── FnExample.class │ ├── Inverse.class │ └── Main.class │ ├── Lecture4 │ ├── BinToDec.class │ ├── Count.class │ ├── DecToBin.class │ ├── Diamond.class │ ├── HollowRhombus.class │ ├── Input.class │ ├── Main.class │ ├── OctToBin.class │ ├── Reverse.class │ └── Swastik.class │ ├── Lecture5 │ ├── ArrayIntro.class │ ├── Main.class │ ├── Searching.class │ └── Sorting.class │ ├── Lecture6 │ ├── ArrayExamples.class │ ├── ArrayListExamples.class │ ├── Sorting.class │ ├── StringBuilderExamples.class │ ├── StringIntro.class │ └── SubstringIntro.class │ ├── Lecture7 │ ├── Bitwise_Examples.class │ ├── BuilderExamples.class │ ├── NthMagic.class │ ├── Pattern_Practice.class │ ├── RecursionIntro.class │ ├── UniqueI.class │ └── UniqueII.class │ ├── Lecture8 │ ├── ArrayRecursion.class │ ├── PatternRecursion.class │ └── RecursionExamples.class │ └── Lecture9 │ ├── Board.class │ ├── CountSort.class │ └── SubSeq.class └── src └── com └── company ├── Lecture10 ├── Arrays_2D.java ├── Dictionary.java ├── Maze.java ├── MazeBoard.java └── NQueens.java ├── Lecture11 ├── MergeSort.java ├── QuickSort.java └── SumDivideArray.java ├── Lecture12 ├── CountPallindrome.java ├── DP_Intro.java ├── Dice.java ├── EditDistance.java ├── EggDrop.java ├── LongSubseq.java ├── MazeDP.java └── ZeroOneKnapsack.java ├── Lecture13 ├── CheckParanthesis.java ├── Client.java ├── DynamicStack.java ├── Human.java ├── Queue.java ├── QueueClient.java ├── Stack.java └── StackClient.java ├── Lecture14 ├── CircularQueue.java ├── DynamicCircularQueue.java └── inheritance │ ├── Car.java │ ├── Client.java │ ├── Maruti.java │ └── Vehicle.java ├── Lecture15 ├── CBStudent.java ├── CBTeacher.java ├── CB_TA.java ├── Car.java ├── CarChild.java ├── Client.java ├── Composition │ ├── Brake.java │ ├── Car.java │ ├── Client.java │ ├── Engine.java │ ├── GenericBrake.java │ ├── NitroEngine.java │ ├── PetrolEngine.java │ └── Steering.java ├── Main.java ├── Other │ ├── Sample.java │ └── SampleChild.java ├── StackQueue │ ├── QueueUsingStackInsert.java │ ├── QueueUsingStackRemove.java │ └── SampleStack.java ├── Students.java ├── TA.java └── Teacher.java ├── Lecture16 ├── Client.java ├── LinkedList.java └── QueueStack │ ├── Client.java │ ├── StackUsingQueuePop.java │ └── StackUsingQueuePush.java ├── Lecture17 ├── BinaryTree.java ├── LinkedList.java ├── LinkedListGeneric.java ├── ListClient.java └── TreeClient.java ├── Lecture18 ├── BST.java ├── BSTClient.java ├── BSTClientNew.java ├── BinaryTree.java ├── BinaryTreeGeneric.java ├── GenericClient.java └── TreeClient.java ├── Lecture19 ├── Greedy │ └── KnapSack.java ├── Heap.java ├── HeapClient.java ├── Human.java ├── Main.java └── PQClient.java ├── Lecture2 ├── Leap.java ├── Loop.java └── Main.java ├── Lecture20 ├── CustomHashSet.java ├── CustomHashTable.java ├── Main.java ├── Questions.java ├── SetClient.java ├── TableUsingArray.java └── TableUsingList.java ├── Lecture21 ├── AdjListGraph.java ├── EdgeListGraph.java └── GraphClient.java ├── Lecture22 ├── AdjMapGraph.java ├── AdjMapWeightGraph.java └── GraphClient.java ├── Lecture23 ├── CustomException.java ├── ExceptionClient.java ├── ScannerExmple.java ├── Sudoku.java └── ThreadExample.java ├── Lecture24 ├── JobSequence.java └── LongPallindromeSubseq.java ├── Lecture3 ├── Converter.java ├── FnExample.java ├── Inverse.java └── Main.java ├── Lecture4 ├── BinToDec.java ├── Count.java ├── DecToBin.java ├── Diamond.java ├── HollowRhombus.java ├── Input.java ├── Main.java ├── OctToBin.java ├── Reverse.java └── Swastik.java ├── Lecture5 ├── ArrayIntro.java ├── Main.java ├── Searching.java └── Sorting.java ├── Lecture6 ├── ArrayExamples.java ├── ArrayListExamples.java ├── Sorting.java ├── StringBuilderExamples.java ├── StringIntro.java └── SubstringIntro.java ├── Lecture7 ├── Bitwise_Examples.java ├── BuilderExamples.java ├── NthMagic.java ├── Pattern_Practice.java ├── RecursionIntro.java ├── UniqueI.java └── UniqueII.java ├── Lecture8 ├── ArrayRecursion.java ├── PatternRecursion.java └── RecursionExamples.java └── Lecture9 ├── Board.java ├── CountSort.java └── SubSeq.java /.idea/description.html: -------------------------------------------------------------------------------- 1 | Simple Java application that includes a class with main() method -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/Project_Default.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 11 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/project-template.xml: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Crux.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Crux-DS-Algo-in-Java 2 | This repository contains all the lectures source code including basic Java, OOPs concepts, Data Structures and Algorithms. 3 | 4 | ## Topics : ## 5 | ### 6 | * Input-Output 7 | * Data Types and Variables 8 | * Typecasting 9 | * Loops and Decision constructs 10 | * Functions and operators 11 | * Arrays, multi-dimensional arrays and dynamic arrays 12 | * String and StringBuilder 13 | * Introduction to Recursion 14 | * Classic Recursion Problems 15 | * Backtracking 16 | * Dynamic Programming 17 | * Time and Space Complexity 18 | * OOPs 19 | * Classes, interfaces and Objects 20 | * Exceptions 21 | * Data member modifiers 22 | * Abstraction 23 | * Encapsulation 24 | * Inheritance 25 | * Polymorphism 26 | * Stacks and Queues 27 | * Linked Lists 28 | * Generic Trees 29 | * Binary Trees 30 | * Binary Search Trees 31 | * Heaps 32 | * Hash Tables & Maps 33 | * Graphs 34 | * Traversals 35 | * Minimum Spanning trees 36 | * Shortest path algorithms 37 | ### 38 | 39 | -------------------------------------------------------------------------------- /out/Doubts/DivisibleSubarrays.java: -------------------------------------------------------------------------------- 1 | package com.company.Doubts; 2 | 3 | import java.util.Scanner; 4 | 5 | public class DivisibleSubarrays { 6 | public static void main(String[] args) { 7 | Scanner s = new Scanner(System.in); 8 | int t = s.nextInt(); 9 | while (t-- > 0) { 10 | int n = s.nextInt(); 11 | int[] nums = new int[n]; 12 | for (int i = 0; i < n; i++) { 13 | nums[i] = s.nextInt(); 14 | } 15 | 16 | System.out.println(countSubarray(nums)); 17 | } 18 | } 19 | 20 | public static long countSubarray(int[] nums) { 21 | long[] rem = new long[nums.length]; 22 | 23 | int sum = 0; 24 | for (int i = 0; i < nums.length; i++) { 25 | sum = (sum + nums[i]) % nums.length; 26 | while (sum < 0) { 27 | sum += nums.length; 28 | } 29 | rem[sum]++; //increment the respective remainder indices 30 | } 31 | 32 | long cnt = rem[0] * (rem[0] + 1) / 2; 33 | for (int i = 1; i < nums.length; i++) { 34 | cnt += (rem[i] * (rem[i] - 1)) / 2; 35 | } 36 | return cnt; 37 | } 38 | } -------------------------------------------------------------------------------- /out/Doubts/IsSorted.java: -------------------------------------------------------------------------------- 1 | package com.company.Doubts; 2 | 3 | import java.util.Scanner; 4 | import java.util.*; 5 | 6 | public class IsSorted { 7 | public static void main(String[] args) { 8 | Scanner s = new Scanner(System.in); 9 | int a = s.nextInt(); 10 | int b = s.nextInt(); 11 | int c = s.nextInt(); 12 | System.out.println(power(a,b,c)); 13 | } 14 | 15 | public static int power(int x, int y, int p) 16 | { 17 | int res = 1; // Initialize result 18 | x = x % p; 19 | while (y > 0) 20 | { 21 | if ((y & 1) == 1) { 22 | res = (res * x) % p; 23 | } 24 | y = y>>1; // y = y/2 25 | x = (x*x) % p; 26 | } 27 | return res; 28 | } 29 | 30 | } 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /out/Doubts/Random.java: -------------------------------------------------------------------------------- 1 | package com.company.Doubts; 2 | 3 | import java.util.Scanner; 4 | 5 | public class Random{ 6 | public static void main(String[] args) { 7 | Scanner s = new Scanner(System.in); 8 | int t = s.nextInt(); 9 | while (t-- > 0){ 10 | int n = s.nextInt(); 11 | int m = s.nextInt(); 12 | Integer[] mem = new Integer[n+1]; 13 | System.out.println(tillingDP(n,m,mem)); 14 | } 15 | } 16 | 17 | public static int tilling(int n, int m){ 18 | if(n < m){ 19 | return 1; 20 | } 21 | if(n == m){ 22 | return 2; 23 | } 24 | 25 | return tilling(n-1,m) + tilling(n-m,m); 26 | } 27 | 28 | public static int tillingDP(int n, int m, Integer[] mem){ 29 | for (int i = 1; i <= n; i++) { 30 | if(i < m){ 31 | mem[i] = 1; 32 | } else if (i == m){ 33 | mem[i] = 2; 34 | } else { 35 | mem[i] = mem[i-1] + mem[i-m]; 36 | mem[i] %= 1000000007; 37 | } 38 | } 39 | return mem[n]; 40 | } 41 | } 42 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /out/Doubts/Solution.java: -------------------------------------------------------------------------------- 1 | package com.company.Doubts; 2 | 3 | import java.util.*; 4 | 5 | public class Solution{ 6 | public static void main(String[] args) { 7 | Scanner s = new Scanner(System.in); 8 | int row = s.nextInt(); 9 | int col = s.nextInt(); 10 | 11 | boolean[][] maze = new boolean[row][col]; //By default all the value are false. 12 | for (int i = 0; i < row; i++) { 13 | for (int j = 0; j < col; j++) { 14 | int n = s.nextInt(); 15 | if(n == 1){ 16 | maze[i][j] = true; 17 | } 18 | } 19 | } 20 | 21 | maze("", 0,0,row-1,col-1,maze); 22 | } 23 | 24 | public static void maze(String path, int c_row, int c_col,int row,int col, boolean[][] maze){ 25 | if(c_row == row && c_col == col){ 26 | System.out.println(path); 27 | return; 28 | } 29 | 30 | if(c_row> row || c_col > col){ 31 | return; 32 | } 33 | 34 | if(!maze[c_row][c_col]){ 35 | return; 36 | } 37 | maze[c_row][c_col] = false; 38 | 39 | maze(path + "R",c_row,c_col+1,row,col,maze); 40 | maze(path + "D",c_row+1,c_col,row,col,maze); 41 | 42 | maze[c_row][c_col] = true; 43 | 44 | } 45 | 46 | 47 | } 48 | 49 | -------------------------------------------------------------------------------- /out/Doubts/input.java: -------------------------------------------------------------------------------- 1 | package com.company.Doubts; 2 | 3 | import java.util.Scanner; 4 | 5 | public class input { 6 | public static void main(String[] args) { 7 | Scanner sc=new Scanner(System.in); 8 | System.out.println(-1%6); 9 | 10 | } 11 | } 12 | 13 | 14 | -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture10/Arrays_2D.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture10/Arrays_2D.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture10/Dictionary.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture10/Dictionary.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture10/Maze.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture10/Maze.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture10/MazeBoard.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture10/MazeBoard.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture10/NQueens.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture10/NQueens.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture11/MergeSort.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture11/MergeSort.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture11/QuickSort.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture11/QuickSort.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture11/SumDivideArray.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture11/SumDivideArray.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture12/CountPallindrome.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture12/CountPallindrome.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture12/DP_Intro.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture12/DP_Intro.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture12/Dice.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture12/Dice.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture12/EditDistance.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture12/EditDistance.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture12/EggDrop.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture12/EggDrop.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture12/LongSubseq.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture12/LongSubseq.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture12/MazeDP.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture12/MazeDP.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture12/ZeroOneKnapsack.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture12/ZeroOneKnapsack.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture13/CheckParanthesis.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture13/CheckParanthesis.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture13/Client.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture13/Client.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture13/DynamicStack.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture13/DynamicStack.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture13/Human.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture13/Human.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture13/Queue.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture13/Queue.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture13/QueueClient.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture13/QueueClient.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture13/Stack.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture13/Stack.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture13/StackClient.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture13/StackClient.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture14/CircularQueue.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture14/CircularQueue.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture14/DynamicCircularQueue.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture14/DynamicCircularQueue.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture14/inheritance/Car.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture14/inheritance/Car.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture14/inheritance/Client.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture14/inheritance/Client.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture14/inheritance/Maruti.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture14/inheritance/Maruti.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture14/inheritance/Vehicle.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture14/inheritance/Vehicle.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture15/CBStudent.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture15/CBStudent.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture15/CBTeacher.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture15/CBTeacher.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture15/CB_TA.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture15/CB_TA.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture15/Car.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture15/Car.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture15/CarChild.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture15/CarChild.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture15/Client.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture15/Client.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture15/Composition/Brake.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture15/Composition/Brake.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture15/Composition/Car.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture15/Composition/Car.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture15/Composition/Client.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture15/Composition/Client.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture15/Composition/Engine.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture15/Composition/Engine.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture15/Composition/GenericBrake.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture15/Composition/GenericBrake.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture15/Composition/NitroEngine.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture15/Composition/NitroEngine.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture15/Composition/PetrolEngine.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture15/Composition/PetrolEngine.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture15/Composition/Steering.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture15/Composition/Steering.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture15/Main.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture15/Main.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture15/Other/Sample.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture15/Other/Sample.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture15/Other/SampleChild.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture15/Other/SampleChild.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture15/StackQueue/QueueUsingStackInsert.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture15/StackQueue/QueueUsingStackInsert.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture15/StackQueue/QueueUsingStackRemove.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture15/StackQueue/QueueUsingStackRemove.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture15/StackQueue/SampleStack.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture15/StackQueue/SampleStack.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture15/Students.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture15/Students.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture15/TA.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture15/TA.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture15/Teacher.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture15/Teacher.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture16/Client.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture16/Client.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture16/LinkedList$Node.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture16/LinkedList$Node.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture16/LinkedList.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture16/LinkedList.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture16/QueueStack/Client.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture16/QueueStack/Client.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture16/QueueStack/StackUsingQueuePop.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture16/QueueStack/StackUsingQueuePop.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture16/QueueStack/StackUsingQueuePush.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture16/QueueStack/StackUsingQueuePush.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture17/BinaryTree$Node.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture17/BinaryTree$Node.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture17/BinaryTree.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture17/BinaryTree.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture17/LinkedList$Node.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture17/LinkedList$Node.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture17/LinkedList.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture17/LinkedList.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture17/LinkedListGeneric$Node.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture17/LinkedListGeneric$Node.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture17/LinkedListGeneric.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture17/LinkedListGeneric.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture17/ListClient.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture17/ListClient.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture17/TreeClient.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture17/TreeClient.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture18/BST$Node.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture18/BST$Node.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture18/BST.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture18/BST.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture18/BSTClient.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture18/BSTClient.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture18/BSTClientNew.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture18/BSTClientNew.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture18/BinaryTree$Node.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture18/BinaryTree$Node.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture18/BinaryTree.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture18/BinaryTree.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture18/BinaryTreeGeneric$Node.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture18/BinaryTreeGeneric$Node.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture18/BinaryTreeGeneric.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture18/BinaryTreeGeneric.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture18/GenericClient.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture18/GenericClient.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture18/TreeClient.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture18/TreeClient.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture19/Greedy/KnapSack$Item.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture19/Greedy/KnapSack$Item.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture19/Greedy/KnapSack.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture19/Greedy/KnapSack.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture19/Heap.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture19/Heap.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture19/HeapClient.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture19/HeapClient.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture19/Human.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture19/Human.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture19/Main.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture19/Main.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture19/PQClient.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture19/PQClient.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture2/Leap.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture2/Leap.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture2/Loop.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture2/Loop.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture2/Main.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture2/Main.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture20/CustomHashSet$Node.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture20/CustomHashSet$Node.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture20/CustomHashSet.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture20/CustomHashSet.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture20/CustomHashTable$Node.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture20/CustomHashTable$Node.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture20/CustomHashTable.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture20/CustomHashTable.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture20/Main.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture20/Main.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture20/Questions.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture20/Questions.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture20/SetClient.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture20/SetClient.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture20/TableUsingArray$Node.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture20/TableUsingArray$Node.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture20/TableUsingArray.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture20/TableUsingArray.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture20/TableUsingList$Node.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture20/TableUsingList$Node.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture20/TableUsingList.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture20/TableUsingList.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture21/AdjListGraph$Vertex.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture21/AdjListGraph$Vertex.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture21/AdjListGraph.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture21/AdjListGraph.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture21/EdgeListGraph$Edge.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture21/EdgeListGraph$Edge.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture21/EdgeListGraph$Vertex.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture21/EdgeListGraph$Vertex.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture21/EdgeListGraph.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture21/EdgeListGraph.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture21/GraphClient.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture21/GraphClient.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture22/AdjMapGraph$Vertex.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture22/AdjMapGraph$Vertex.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture22/AdjMapGraph.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture22/AdjMapGraph.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture22/AdjMapWeightGraph$DjPair.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture22/AdjMapWeightGraph$DjPair.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture22/AdjMapWeightGraph$Edge.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture22/AdjMapWeightGraph$Edge.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture22/AdjMapWeightGraph$Vertex.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture22/AdjMapWeightGraph$Vertex.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture22/AdjMapWeightGraph.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture22/AdjMapWeightGraph.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture22/GraphClient.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture22/GraphClient.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture23/CustomException.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture23/CustomException.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture23/ExceptionClient.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture23/ExceptionClient.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture23/ScannerExmple.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture23/ScannerExmple.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture23/Sudoku.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture23/Sudoku.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture23/ThreadExample.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture23/ThreadExample.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture24/JobSequence$Job.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture24/JobSequence$Job.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture24/JobSequence.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture24/JobSequence.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture24/LongPallindromeSubseq.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture24/LongPallindromeSubseq.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture3/Converter.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture3/Converter.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture3/FnExample.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture3/FnExample.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture3/Inverse.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture3/Inverse.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture3/Main.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture3/Main.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture4/BinToDec.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture4/BinToDec.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture4/Count.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture4/Count.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture4/DecToBin.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture4/DecToBin.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture4/Diamond.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture4/Diamond.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture4/HollowRhombus.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture4/HollowRhombus.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture4/Input.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture4/Input.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture4/Main.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture4/Main.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture4/OctToBin.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture4/OctToBin.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture4/Reverse.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture4/Reverse.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture4/Swastik.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture4/Swastik.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture5/ArrayIntro.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture5/ArrayIntro.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture5/Main.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture5/Main.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture5/Searching.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture5/Searching.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture5/Sorting.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture5/Sorting.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture6/ArrayExamples.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture6/ArrayExamples.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture6/ArrayListExamples.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture6/ArrayListExamples.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture6/Sorting.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture6/Sorting.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture6/StringBuilderExamples.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture6/StringBuilderExamples.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture6/StringIntro.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture6/StringIntro.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture6/SubstringIntro.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture6/SubstringIntro.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture7/Bitwise_Examples.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture7/Bitwise_Examples.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture7/BuilderExamples.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture7/BuilderExamples.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture7/NthMagic.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture7/NthMagic.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture7/Pattern_Practice.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture7/Pattern_Practice.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture7/RecursionIntro.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture7/RecursionIntro.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture7/UniqueI.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture7/UniqueI.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture7/UniqueII.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture7/UniqueII.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture8/ArrayRecursion.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture8/ArrayRecursion.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture8/PatternRecursion.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture8/PatternRecursion.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture8/RecursionExamples.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture8/RecursionExamples.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture9/Board.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture9/Board.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture9/CountSort.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture9/CountSort.class -------------------------------------------------------------------------------- /out/production/Crux/com/company/Lecture9/SubSeq.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darecoder/Crux-DS-Algo-In-Java/cbdf92eaf52cdfc369147c147c637e98e1173389/out/production/Crux/com/company/Lecture9/SubSeq.class -------------------------------------------------------------------------------- /src/com/company/Lecture10/Arrays_2D.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture10; 2 | 3 | public class Arrays_2D { 4 | public static void main(String[] args) { 5 | int[][] nums = new int[6][5]; 6 | 7 | for (int i = 0; i < nums.length; i++) { 8 | for (int j = 0; j < nums[i].length ; j++) { 9 | System.out.print(nums[i][j]); 10 | } 11 | System.out.println(); 12 | } 13 | 14 | int[][] nums2 = new int[4][]; 15 | 16 | // for (int i = 0; i < nums2.length ; i++) { 17 | // System.out.println(nums2[i]); 18 | // } 19 | 20 | for (int i = 0; i < nums2.length ; i++) { 21 | nums2[i] = new int[i+1]; 22 | } 23 | // int[][] nums = new int[6][5]; 24 | 25 | // for (int i = 0; i < nums.length; i++) { 26 | // for (int j = 0; j < nums[i].length ; j++) { 27 | // System.out.print(nums[i][j]); 28 | // } 29 | // System.out.println(); 30 | // } 31 | 32 | // int[][] nums2 = new int[4][]; 33 | // 34 | //// for (int i = 0; i < nums2.length ; i++) { 35 | //// System.out.println(nums2[i]); 36 | //// } 37 | // 38 | // for (int i = 0; i < nums2.length ; i++) { 39 | // nums2[i] = new int[i+1]; 40 | // } 41 | // 42 | // for (int i = 0; i < nums2.length; i++) { 43 | // System.out.println(nums2[i].length); 44 | // } 45 | for (int i = 0; i < nums2.length; i++) { 46 | System.out.println(nums2[i].length); 47 | } 48 | 49 | // long r = 100000; 50 | // long n = (long)(r*(r+1)/2.0); 51 | // System.out.println(n); 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/com/company/Lecture10/Dictionary.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture10; 2 | 3 | import com.company.Lecture5.ArrayIntro; 4 | 5 | import java.util.ArrayList; 6 | import java.util.Arrays; 7 | 8 | public class Dictionary { 9 | public static void main(String[] args) { 10 | String line = "aab"; 11 | int[] nums = freq(line); 12 | // System.out.println(Arrays.toString(nums)); 13 | 14 | // lexo("",nums,line.length()); 15 | lexoNum(0,11); 16 | } 17 | 18 | public static int[] freq(String chars){ 19 | int[] nums = new int[26]; 20 | for (int i = 0; i < chars.length() ; i++) { 21 | if(chars.charAt(i) >=97 || chars.charAt(i) <=122){ 22 | nums[chars.charAt(i) - 'a']++; 23 | } 24 | } 25 | return nums; 26 | } 27 | 28 | public static void lexo(String proc, int[] f, int length){ 29 | if(length == 0){ 30 | System.out.println(proc); 31 | return; 32 | } 33 | 34 | for (int i = 0; i < f.length; i++) { 35 | if(f[i] > 0){ 36 | f[i]--; 37 | lexo(proc + (char)(i + 'a'), f,length-1); 38 | f[i]++; 39 | } 40 | } 41 | } 42 | 43 | public static void lexoNum(int val, int target){ 44 | if(val > target){ 45 | return; 46 | } 47 | for(int i = 0; i < 10; i++){ 48 | if (val == 0 && i == 0){ 49 | continue; 50 | } 51 | int v = val * 10 + i; 52 | if(v <= target){ 53 | System.out.println(v); 54 | lexoNum(v, target); 55 | } 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/com/company/Lecture10/Maze.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture10; 2 | 3 | public class Maze { 4 | public static void main(String[] args) { 5 | // System.out.println(mazeCount(3,4)); 6 | // mazePath("", 3,4); 7 | // System.out.println(mazeDiagCount(3,4)); 8 | mazeDiagMajor("",3,4); 9 | 10 | } 11 | 12 | public static int mazeCount(int row, int col){ 13 | if(row == 1 && col == 1){ 14 | return 1; 15 | } 16 | 17 | else if(row ==1 || col == 1){ 18 | return 1; 19 | } 20 | 21 | int cnt = 0; 22 | 23 | cnt += mazeCount(row-1,col); 24 | cnt += mazeCount(row,col-1); 25 | return cnt; 26 | } 27 | 28 | public static void mazePath(String path,int row, int col){ 29 | if(row == 1 && col == 1){ 30 | System.out.println(path); 31 | return; 32 | } 33 | 34 | if(row > 1){ 35 | mazePath(path + "H",row-1,col); 36 | } 37 | 38 | if(col > 1){ 39 | mazePath(path + "V",row,col-1); 40 | } 41 | } 42 | 43 | public static int mazeDiagCount(int row, int col){ 44 | if(row == 1 && col == 1){ 45 | return 1; 46 | } 47 | 48 | int cnt = 0; 49 | 50 | if(row > 1){ 51 | cnt +=mazeDiagCount(row-1,col); 52 | } 53 | 54 | if(col > 1){ 55 | cnt +=mazeDiagCount(row,col-1); 56 | } 57 | 58 | if(row > 1 && col > 1){ 59 | cnt +=mazeDiagCount(row-1,col-1); 60 | } 61 | return cnt; 62 | } 63 | 64 | public static void mazeDiagPath(String path,int row, int col){ 65 | if(row == 1 && col == 1){ 66 | System.out.println(path); 67 | return; 68 | } 69 | 70 | if(row > 1){ 71 | mazeDiagPath(path + "H",row-1,col); 72 | } 73 | 74 | if(col > 1){ 75 | mazeDiagPath(path + "V",row,col-1); 76 | } 77 | 78 | if(row > 1 && col > 1){ 79 | mazeDiagPath(path + "D",row-1,col-1); 80 | } 81 | } 82 | 83 | public static void mazeDiagMajor(String path,int row, int col){ 84 | if(row == 1 && col == 1){ 85 | System.out.println(path); 86 | return; 87 | } 88 | 89 | if(row > 1){ 90 | mazeDiagMajor(path + "H",row-1,col); 91 | } 92 | 93 | if(col > 1){ 94 | mazeDiagMajor(path + "V",row,col-1); 95 | } 96 | 97 | if(row > 1 && col > 1 && row == col){ 98 | mazeDiagMajor(path + "D",row-1,col-1); 99 | } 100 | } 101 | 102 | } 103 | -------------------------------------------------------------------------------- /src/com/company/Lecture10/MazeBoard.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture10; 2 | 3 | public class MazeBoard { 4 | public static void main(String[] args) { 5 | int row = 3; 6 | int col = 3; 7 | 8 | boolean[][] maze = new boolean[row+1][col+1]; //By default all the value are false. 9 | 10 | maze("", 1,0,row,col,maze); 11 | 12 | 13 | } 14 | 15 | public static void maze(String path, int c_row, int c_col,int row,int col, boolean[][] maze){ 16 | if(c_row == row && c_col == col){ 17 | System.out.println(path); 18 | return; 19 | } 20 | 21 | if(c_col < 0 ||c_row< 0 || c_row> row || c_col > col){ 22 | return; 23 | } 24 | 25 | if(maze[c_row][c_col]){ 26 | return; 27 | } 28 | maze[c_row][c_col] = true; 29 | 30 | maze(path + "U",c_row-1,c_col,row,col,maze); 31 | maze(path + "R",c_row,c_col+1,row,col,maze); 32 | maze(path + "D",c_row+1,c_col,row,col,maze); 33 | maze(path + "L",c_row,c_col-1,row,col,maze); 34 | 35 | maze[c_row][c_col] = false; 36 | 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/com/company/Lecture10/NQueens.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture10; 2 | 3 | public class NQueens { 4 | public static void main(String[] args) { 5 | int n = 4; 6 | boolean[][] board = new boolean[n][n]; 7 | nqueens(board,0); 8 | 9 | } 10 | 11 | public static void nqueens(boolean[][] board, int row){ 12 | if(row == board.length){ 13 | display(board,row); 14 | return; 15 | } 16 | 17 | for(int col = 0; col < board.length; col++){ 18 | if(isSafe(board, row, col)){ 19 | board[row][col] = true; 20 | nqueens(board, row+1); 21 | board[row][col] = false; 22 | } 23 | } 24 | } 25 | 26 | public static void display(boolean[][] board, int row){ 27 | for (int i = 0; i < board.length ; i++) { 28 | for (int j = 0; j < board.length ; j++) { 29 | System.out.print(board[i][j] + " "); 30 | } 31 | System.out.println(); 32 | } 33 | System.out.println(); 34 | } 35 | 36 | public static boolean isSafe(boolean[][] board, int row, int col){ 37 | for (int i = 0; i < row; i++) { 38 | if(board[i][col]){ 39 | return false; 40 | } 41 | } 42 | 43 | int left_step = Math.min(row,col); 44 | for (int i = 1; i <= left_step; i++) { 45 | if(board[row-i][col-i]){ 46 | return false; 47 | } 48 | } 49 | 50 | int right_step = Math.min(row, board.length-1-col); 51 | for (int i = 1; i <= right_step; i++) { 52 | if(board[row-i][col+i]){ 53 | return false; 54 | } 55 | } 56 | 57 | return true; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/com/company/Lecture11/MergeSort.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture11; 2 | 3 | import java.util.Arrays; 4 | 5 | public class MergeSort { 6 | public static void main(String[] args) { 7 | int[] nums = {3,8,1,9,2}; 8 | nums = mergeSort(nums); 9 | System.out.println(Arrays.toString(nums)); 10 | } 11 | 12 | public static int[] mergeSort(int[] nums){ 13 | if(nums.length < 2) return nums; 14 | int mid = nums.length/2; 15 | 16 | int[] first = Arrays.copyOfRange(nums,0,mid); 17 | int[] second = Arrays.copyOfRange(nums,mid,nums.length); 18 | 19 | first = mergeSort(first); 20 | second = mergeSort(second); 21 | 22 | return merge(first, second); 23 | } 24 | 25 | public static int[] merge(int[] first, int[] second){ 26 | int i=0,j=0,k=0; 27 | int[] res = new int[first.length+second.length]; 28 | 29 | while(i < first.length && j < second.length){ 30 | if(first[i] < second[j]){ 31 | res[k++] = first[i++]; 32 | }else{ 33 | res[k++] = second[j++]; 34 | } 35 | } 36 | while(i < first.length){ 37 | res[k++] = first[i++]; 38 | } 39 | while(j < second.length){ 40 | res[k++] = second[j++]; 41 | } 42 | return res; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/com/company/Lecture11/QuickSort.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture11; 2 | 3 | import com.company.Lecture5.ArrayIntro; 4 | import java.util.Arrays; 5 | 6 | public class QuickSort { 7 | public static void main(String[] args) { 8 | int[] nums = {4,8,1,7,2,0,3}; 9 | quicksort(nums,0,nums.length-1); 10 | System.out.println(Arrays.toString(nums)); 11 | } 12 | 13 | public static void quicksort(int[] nums,int start, int end){ 14 | if(start >= end){ 15 | return; 16 | } 17 | int p = pivot(nums,start,end); 18 | quicksort(nums,start,p-1); 19 | quicksort(nums,p+1,end); 20 | } 21 | 22 | public static int pivot(int[] nums,int start,int end){ 23 | int j=start; 24 | for (int i = start; i <= end; i++) { 25 | if(nums[i] < nums[end]) { 26 | ArrayIntro.swap(nums, i, j); 27 | j++; 28 | } 29 | } 30 | ArrayIntro.swap(nums, end,j); 31 | return j; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/com/company/Lecture11/SumDivideArray.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture11; 2 | 3 | import com.company.Lecture5.ArrayIntro; 4 | 5 | import java.lang.reflect.Array; 6 | import java.util.ArrayList; 7 | import java.util.Collections; 8 | 9 | public class SumDivideArray { 10 | public static void main(String[] args) { 11 | int[] nums ={-1,3,7,4,2,1}; 12 | divide(nums, 0,0,0,new ArrayList<>(),new ArrayList<>()); 13 | // sumTarget(nums,0,10,0,new ArrayList<>()); 14 | } 15 | 16 | public static void divide(int[] nums, int index, int sum1, int sum2, 17 | ArrayList list1,ArrayList list2){ 18 | if( index == nums.length){ 19 | if(sum1 == sum2){ 20 | System.out.println(list1 + " : " + list2); 21 | } 22 | return; 23 | } 24 | 25 | int value = nums[index]; 26 | 27 | list1.add(value); 28 | divide(nums,index+1,sum1 + value,sum2,list1,list2); 29 | list1.remove(list1.size() -1); 30 | 31 | list2.add(value); 32 | divide(nums,index+1,sum1,sum2 + value,list1,list2); 33 | list2.remove(list2.size() - 1); 34 | 35 | } 36 | 37 | public static void sumTarget(int[] nums, int index, int target, 38 | int sum, ArrayList list){ 39 | if(index == nums.length){ 40 | if(sum == target && list.size() == 3){ 41 | System.out.println(list); 42 | } 43 | return; 44 | } 45 | 46 | list.add(nums[index]); 47 | sumTarget(nums,index+1,target,sum + nums[index],list); 48 | list.remove(list.size() - 1); 49 | 50 | sumTarget(nums, index+1,target,sum,list); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/com/company/Lecture12/CountPallindrome.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture12; 2 | 3 | public class CountPallindrome { 4 | public static void main(String[] args) { 5 | String line = "aabbaa"; 6 | System.out.println(count(line)); 7 | } 8 | 9 | public static int count(String line){ 10 | int count = 0; 11 | for(int i = 0; i < line.length();i++){ 12 | //Check for odd length 13 | int left = i; 14 | int right = i; 15 | while(left >= 0 && right < line.length()){ 16 | if(line.charAt(left--) == line.charAt(right++)){ 17 | count++; 18 | }else{ 19 | break; 20 | } 21 | } 22 | //Check for even length 23 | left = i; 24 | right = i+1; 25 | while(left >= 0 && right < line.length()){ 26 | if(line.charAt(left--) == line.charAt(right++)){ 27 | count++; 28 | }else{ 29 | break; 30 | } 31 | } 32 | } 33 | return count; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/com/company/Lecture12/DP_Intro.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture12; 2 | 3 | import java.math.BigInteger; 4 | 5 | public class DP_Intro { 6 | public static void main(String[] args) { 7 | int n = 10; 8 | BigInteger[] mem = new BigInteger[n+1]; 9 | BigInteger res = DP_fibo2(n,mem); 10 | System.out.println(res); 11 | 12 | Integer[] memory = new Integer[n+1]; //Wrapper Class -> Integer 13 | System.out.println(DP_fibo(n,memory)); 14 | 15 | System.out.println(fiboDPitr(n,memory)); //Dynamic Programming using Iterative approach 16 | } 17 | 18 | public static int fibo(int n){ 19 | if( n < 2){ 20 | return n; 21 | } 22 | 23 | return (fibo(n-1) + fibo(n-2)); 24 | } 25 | 26 | public static int DP_fibo(int n,Integer[] memory){ //Dynamic Programming 27 | if( n < 2){ 28 | return n; 29 | } 30 | 31 | if(memory[n] != null){ 32 | return memory[n]; 33 | } 34 | 35 | memory[n] = (DP_fibo(n-1,memory) + DP_fibo(n-2,memory)); 36 | return memory[n]; 37 | } 38 | 39 | public static BigInteger DP_fibo2(int n,BigInteger[] memory){ 40 | if( n < 2){ 41 | return new BigInteger(Integer.toString(n)); 42 | } 43 | 44 | if(memory[n] != null){ 45 | return memory[n]; 46 | } 47 | 48 | memory[n] = (DP_fibo2(n-1,memory).add(DP_fibo2(n-2,memory))); 49 | return memory[n]; 50 | } 51 | 52 | public static int fiboDPitr(int n,Integer[] memory){ //Dynamic Programming using Iterative approach 53 | for (int i = 0; i <= n ; i++) { 54 | if(i < 2){ 55 | memory[i] = i; 56 | }else{ 57 | memory[i] = memory[i-1] + memory[i-2]; 58 | } 59 | } 60 | return memory[n]; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/com/company/Lecture12/Dice.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture12; 2 | 3 | public class Dice { 4 | public static void main(String[] args) { 5 | int n = 4; 6 | Integer[] mem = new Integer[n + 1]; 7 | Integer[] memory = new Integer[n + 1]; 8 | System.out.println(board(n, 3)); 9 | System.out.println(boardDP(n, 3, mem)); 10 | System.out.println(boardDPitr(n,3,memory)); 11 | 12 | } 13 | 14 | public static int board(int target, int dice) { 15 | if (target == 0) { 16 | return 1; 17 | } 18 | 19 | int count = 0; 20 | for (int i = 1; i <= dice && i <= target; i++) { 21 | count += board(target - i, dice); 22 | } 23 | return count; 24 | } 25 | 26 | public static int boardDP(int target, int dice, Integer[] mem) { 27 | if (target == 0) { 28 | return 1; 29 | } 30 | 31 | if (mem[target] != null) { 32 | return mem[target]; 33 | } 34 | 35 | int count = 0; 36 | for (int i = 1; i <= dice && i <= target; i++) { 37 | count += boardDP(target - i, dice,mem); 38 | } 39 | mem[target] = count; 40 | 41 | 42 | return count; 43 | } 44 | 45 | public static int boardDPitr(int target, int dice,Integer[] mem){ 46 | for(int t = 0; t <= target;t++){ 47 | if(t==0){ 48 | mem[t] = 1; 49 | }else { 50 | int count = 0; 51 | for (int i = 1; i <= dice && i <= t; i++) { 52 | count += mem[t - i]; 53 | } 54 | mem[t] = count; 55 | } 56 | } 57 | 58 | return mem[target]; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/com/company/Lecture12/EditDistance.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture12; 2 | 3 | public class EditDistance { 4 | public static void main(String[] args) { 5 | String f = "dog"; 6 | String s = "don"; 7 | Integer[][] mem = new Integer[f.length()+1][s.length()+1]; 8 | System.out.println(editDist(f,s,f.length(),s.length())); 9 | System.out.println(editDistDP(f,s,f.length(),s.length(),mem)); 10 | System.out.println(editDistDPitr(f,s,mem)); 11 | } 12 | 13 | public static int editDist(String f,String s,int flen,int slen){ 14 | if(flen == 0){ 15 | return slen; 16 | } 17 | if(slen == 0){ 18 | return flen; 19 | } 20 | int count = 0; 21 | if(f.charAt(flen - 1) == s.charAt(slen - 1)){ 22 | count = editDist(f,s,flen-1,slen-1); 23 | }else { 24 | int right = 1 + editDist(f,s,flen-1,slen); 25 | int left = 1 + editDist(f,s,flen,slen-1); 26 | int both = 1 + editDist(f,s,flen-1,slen-1); 27 | count = Math.min(right,Math.min(left,both)); 28 | } 29 | return count; 30 | } 31 | 32 | public static int editDistDP(String f,String s,int flen,int slen,Integer[][] mem){ 33 | if(flen == 0){ 34 | return slen; 35 | } 36 | if(slen == 0){ 37 | return flen; 38 | } 39 | 40 | if(mem[flen][slen] != null) { 41 | return mem[flen][slen]; 42 | }else{ 43 | if(f.charAt(flen - 1) == s.charAt(slen - 1)){ 44 | mem[flen][slen] = editDistDP(f,s,flen-1,slen-1,mem); 45 | }else{ 46 | int right = 1 + editDistDP(f,s,flen-1,slen,mem); 47 | int left = 1 + editDistDP(f,s,flen,slen-1,mem); 48 | int both = 1 + editDistDP(f,s,flen-1,slen-1,mem); 49 | mem[flen][slen] = Math.min(right,Math.min(left,both)); 50 | } 51 | } 52 | return mem[flen][slen]; 53 | } 54 | 55 | public static int editDistDPitr(String f,String s,Integer[][] mem){ 56 | int flen,slen = 0; 57 | for (flen = 0; flen <= f.length(); flen++) { 58 | for (slen = 0; slen <= s.length(); slen++) { 59 | if(flen == 0){ 60 | mem[flen][slen] = slen; 61 | }else if(slen == 0){ 62 | mem[flen][slen] = flen; 63 | } 64 | else{ 65 | if(f.charAt(flen-1) == s.charAt(slen-1)){ 66 | mem[flen][slen] = mem[flen-1][slen-1]; 67 | }else{ 68 | mem[flen][slen] = 1+ Math.min(mem[flen-1][slen], 69 | Math.min(mem[flen][slen-1],mem[flen-1][slen-1])); 70 | } 71 | } 72 | } 73 | } 74 | return mem[flen][slen]; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/com/company/Lecture12/EggDrop.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture12; 2 | 3 | public class EggDrop { 4 | public static void main(String[] args) { 5 | int floors = 100; 6 | int eggs = 2; 7 | Integer[][] mem = new Integer[floors+1][eggs+1]; 8 | // System.out.println(eggDrop(floors,eggs)); 9 | // System.out.println(eggDropDP(floors,eggs,mem)); 10 | System.out.println(eggDropDPitr(floors,eggs,mem)); 11 | 12 | } 13 | 14 | public static int eggDrop(int floors,int eggs){ 15 | if(floors == 0){ 16 | return 0; 17 | } 18 | if(eggs == 1){ 19 | return floors; 20 | } 21 | int minimum = floors; 22 | for (int f = 1; f <= floors; f++) { 23 | int down = eggDrop(f - 1,eggs -1); 24 | int up = eggDrop(floors - f,eggs); 25 | 26 | int max = 1 + Math.max(down,up); 27 | if(max < minimum){ 28 | minimum = max; 29 | } 30 | } 31 | return minimum; 32 | } 33 | 34 | public static int eggDropDP(int floors,int eggs, Integer[][] mem){ 35 | if(floors == 0){ 36 | return 0; 37 | } 38 | if(eggs == 1){ 39 | return floors; 40 | } 41 | int minimum = floors; 42 | for (int f = 1; f <= floors; f++) { 43 | int down = eggDropDP(f - 1,eggs -1, mem); 44 | int up = eggDropDP(floors - f,eggs, mem); 45 | 46 | int max = 1 + Math.max(down,up); 47 | if(max < minimum){ 48 | minimum = max; 49 | } 50 | } 51 | mem[floors][eggs] = minimum; 52 | return mem[floors][eggs]; 53 | } 54 | 55 | //HOMEWORK 56 | public static int eggDropDPitr(int floors,int eggs,Integer[][] mem){ 57 | for (int f = 0; f <= floors; f++) { 58 | for (int e = 1; e <= eggs; e++) { 59 | if(e == 1){ 60 | mem[f][e] = f; 61 | }else if(f == 0){ 62 | mem[f][e] = 0; 63 | }else{ 64 | mem[f][e] = floors; 65 | for (int i = 1; i <= f; i++) { 66 | int max = 1 + Math.max(mem[i-1][e-1],mem[f-i][e]); 67 | if(max < mem[f][e]){ 68 | mem[f][e] = max; 69 | } 70 | } 71 | } 72 | } 73 | } 74 | 75 | return mem[floors][eggs]; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/com/company/Lecture12/LongSubseq.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture12; 2 | 3 | public class LongSubseq { 4 | public static void main(String[] args) { 5 | String f ="aman"; 6 | String s ="naman"; 7 | Integer[][] mem = new Integer[f.length()+1][s.length()+1]; 8 | System.out.println(lcs(f,s,f.length(),s.length())); 9 | System.out.println(lcsDP(f,s,f.length(),s.length(),mem)); 10 | System.out.println(lcsDPitr(f,s,f.length(),s.length(),mem)); 11 | 12 | } 13 | 14 | public static int lcs(String f,String s,int flen,int slen){ 15 | if(flen == 0 || slen == 0){ 16 | return 0; 17 | } 18 | int count; 19 | if(f.charAt(flen-1) == s.charAt(slen-1)){ 20 | count = 1 + lcs(f,s,flen-1,slen-1); 21 | }else{ 22 | int right = lcs(f,s,flen-1,slen); 23 | int left = lcs(f,s,flen,slen-1); 24 | count = Math.max(right,left); 25 | } 26 | return count; 27 | } 28 | 29 | public static int lcsDP(String f,String s,int flen,int slen,Integer[][] mem){ 30 | if(flen == 0 || slen == 0){ 31 | return 0; 32 | } 33 | 34 | if(mem[flen][slen] != null) { 35 | return mem[flen][slen]; 36 | }else{ 37 | if(f.charAt(flen-1) == s.charAt(slen-1)){ 38 | mem[flen][slen]= 1 + lcsDP(f,s,flen-1,slen-1,mem); 39 | }else{ 40 | int right = lcsDP(f,s,flen-1,slen,mem); 41 | int left = lcsDP(f,s,flen,slen-1,mem); 42 | mem[flen][slen] = Math.max(right,left); 43 | } 44 | } 45 | return mem[flen][slen]; 46 | } 47 | 48 | public static int lcsDPitr(String f,String s,int flen,int slen,Integer[][] mem){ 49 | for (int i = 0; i <= flen ; i++) { 50 | for (int j = 0; j <= slen; j++) { 51 | if(i == 0 || j == 0){ 52 | mem[i][j] = 0; 53 | }else { 54 | if(f.charAt(i - 1) == s.charAt(j - 1)){ 55 | mem[i][j] = 1 + mem[i-1][j-1]; 56 | }else{ 57 | mem[i][j] = Math.max(mem[i-1][j], mem[i][j-1]); 58 | } 59 | } 60 | } 61 | } 62 | return mem[flen][slen]; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/com/company/Lecture12/MazeDP.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture12; 2 | 3 | public class MazeDP { 4 | public static void main(String[] args) { 5 | int row = 4,col = 4; 6 | Integer[][] mem = new Integer[row+1][col+1]; 7 | Integer[][] memory = new Integer[row+1][col+1]; 8 | 9 | System.out.println(maze2(3,3)); 10 | System.out.println(mazeDP(3,3,mem)); 11 | System.out.println(mazeDPitr(3,3,memory)); 12 | 13 | } 14 | 15 | 16 | public static int maze2(int row,int col){ //Reach (1,1) 17 | if(row == 1 || col == 1){ 18 | return 1; 19 | } 20 | 21 | return maze2(row-1,col) + maze2(row,col-1); 22 | } 23 | 24 | public static int mazeDP(int row, int col,Integer[][] mem){ 25 | if(row == 1 || col == 1){ 26 | return 1; 27 | } 28 | 29 | if(mem[row][col] != null){ 30 | return mem[row][col]; 31 | } 32 | 33 | mem[row][col] = mazeDP(row-1,col,mem) + mazeDP(row,col-1,mem); 34 | 35 | return mem[row][col]; 36 | } 37 | 38 | public static int mazeDPitr(int row,int col,Integer[][] mem){ 39 | for (int i = 1; i <= row ; i++) { 40 | for (int j = 1; j <= col; j++) { 41 | if(i == 1 || j == 1){ 42 | mem[i][j] = 1; 43 | }else{ 44 | mem[i][j] = mem[i - 1][j] + mem[i][j-1]; 45 | } 46 | } 47 | } 48 | 49 | return mem[row][col]; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/com/company/Lecture12/ZeroOneKnapsack.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture12; 2 | 3 | public class ZeroOneKnapsack { 4 | public static void main(String[] args) { 5 | int[] p = {5, 10, 7, 5}; 6 | int[] w = {2, 1, 2, 2}; 7 | int cap = 3; 8 | Integer[][] mem = new Integer[cap + 1][p.length + 1]; 9 | System.out.println(zeroOneDPitr(w,p,cap,p.length,mem)); 10 | 11 | } 12 | 13 | public static int zeroOne(int[] wts, int[] prs, int cap, int size){ 14 | if(size == 0){ 15 | return 0; 16 | } 17 | int acc = 0; 18 | if(wts[size - 1] <= cap){ 19 | acc = prs[size-1] + 20 | zeroOne(wts, prs, cap-wts[size-1], size-1); 21 | } 22 | int reject = zeroOne(wts, prs, cap, size-1); 23 | return Math.max(acc, reject); 24 | } 25 | 26 | public static int zeroOneDP(int[] wts, int[] prs, int cap, int size, Integer[][] mem){ 27 | if(size == 0){ 28 | return 0; 29 | } 30 | if(mem[cap][size] != null){ 31 | return mem[cap][size]; 32 | } 33 | int acc = 0; 34 | if(wts[size - 1] <= cap){ 35 | acc = prs[size-1] + 36 | zeroOneDP(wts, prs, cap-wts[size-1], size-1, mem); 37 | } 38 | int reject = zeroOneDP(wts, prs, cap, size-1, mem); 39 | mem[cap][size] = Math.max(acc, reject); 40 | return mem[cap][size]; 41 | } 42 | 43 | public static int zeroOneDPitr(int[] wts, int[] prs, int cap, int size, Integer[][] mem){ 44 | for (int c = 0; c <= cap; c++) { 45 | for (int s = 0; s <= size; s++) { 46 | if(s == 0){ 47 | mem[c][s] = 0; 48 | }else { 49 | int acc = 0; 50 | if(wts[s - 1] <= c){ 51 | acc = prs[s-1] + mem[c-wts[s-1]][s-1]; 52 | } 53 | int reject = mem[c][s-1]; 54 | mem[c][s] = Math.max(acc,reject); 55 | } 56 | } 57 | } 58 | return mem[cap][size]; 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /src/com/company/Lecture13/CheckParanthesis.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture13; 2 | 3 | import java.util.Stack; 4 | 5 | public class CheckParanthesis { 6 | public static void main(String[] args) { 7 | String str = "{(){}[((])]}"; 8 | System.out.println(isBalanced(str)); 9 | } 10 | 11 | public static boolean isBalanced(String str) { 12 | Stack stack = new Stack<>(); 13 | for (int i = 0; i < str.length(); i++) { 14 | if (str.charAt(i) == '{' || str.charAt(i) == '[' || str.charAt(i) =='(') { 15 | stack.push(str.charAt(i)); 16 | }else { 17 | char close = findOpen(str.charAt(i)); 18 | if (stack.peek() == close) { 19 | stack.pop(); 20 | } else { 21 | return false; 22 | } 23 | } 24 | } 25 | 26 | if (stack.empty()) { 27 | return true; 28 | } 29 | return false; 30 | } 31 | 32 | private static char findOpen(char ch) { 33 | if (ch == ')') { 34 | return '('; 35 | }else if(ch == '}') { 36 | return '{'; 37 | } else { 38 | return '['; 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/com/company/Lecture13/Client.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture13; 2 | 3 | public class Client { 4 | public static void main(String[] args) { 5 | Human ekta = new Human("Ekta" ,19,1000); 6 | Human ankit = new Human(ekta); //copy constructor 7 | 8 | System.out.println(ankit.name); 9 | // System.out.println(ekta.name); 10 | // System.out.println(ekta.age); 11 | 12 | // ekta.name = "Ekta Mishra"; 13 | // ekta.age = 19; 14 | 15 | System.out.println(ekta.name); 16 | System.out.println(ekta.age); 17 | 18 | // for (int i = 0; i < 11 ; i++) { 19 | // ekta.udhaar(); 20 | // System.out.println(ekta.balance); 21 | // } 22 | // 23 | // System.out.println(ekta.population); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/com/company/Lecture13/DynamicStack.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture13; 2 | public class DynamicStack extends Stack { 3 | @Override 4 | public void push(int item) { 5 | if(isFull()){ 6 | int[] temp = new int[data.length * 2]; 7 | 8 | for (int i = 0; i < data.length; i++) { 9 | temp[i] = data[i]; 10 | } 11 | 12 | data = temp; 13 | } 14 | 15 | super.push(item); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/com/company/Lecture13/Human.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture13; 2 | 3 | public class Human { 4 | public String name; //instance variable 5 | public int age; 6 | public int balance = 1000; 7 | public static int population = 0; 8 | 9 | public Human(){ 10 | population++; 11 | } 12 | 13 | public Human(Human another){ 14 | this.name =another.name; 15 | this.age = another.age; 16 | this.balance = another.balance; 17 | } 18 | 19 | public Human(String name, int age, int balance){ //local variable inside () 20 | this.name = name; 21 | this.age = age; 22 | this.balance = balance; 23 | population++; 24 | } 25 | 26 | public void udhaar(){ 27 | if(balance >= 100){ 28 | balance = balance - 100; 29 | }else{ 30 | System.out.println("Bhai kangaal ho rakha hun :/"); 31 | } 32 | } 33 | 34 | @Override 35 | protected void finalize() throws Throwable { 36 | population--; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/com/company/Lecture13/Queue.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture13; 2 | 3 | 4 | public class Queue { 5 | private int[] data; 6 | private static final int DEFAULT_SIZE = 10; 7 | public int end; 8 | 9 | public Queue(){ 10 | // data = new int[DEFAULT_SIZE]; 11 | this(DEFAULT_SIZE); 12 | } 13 | 14 | public Queue(int size){ 15 | data = new int[size]; 16 | end = -1; 17 | } 18 | 19 | public boolean isFull(){ 20 | return this.end == data.length-1; 21 | } 22 | 23 | public boolean isEmpty(){ 24 | return this.end == -1; 25 | } 26 | 27 | public void enqueue(int item){ 28 | if(!isFull()){ 29 | data[++end] = item; 30 | return; 31 | } 32 | System.out.println("Queue is overflow!!"); 33 | } 34 | 35 | public Integer dequeue(){ 36 | if(isEmpty()){ 37 | return null; 38 | } 39 | int temp = data[0]; 40 | for (int i = 0; i < end ; i++) { 41 | data[i] = data[i+1]; 42 | } 43 | end--; 44 | return temp; 45 | } 46 | 47 | public void display(){ 48 | for (int i = 0; i < end ; i++) { 49 | System.out.print(this.data[i] + ", "); 50 | } 51 | System.out.println(this.data[end]); 52 | } 53 | 54 | public int peek(){ 55 | return end; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/com/company/Lecture13/QueueClient.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture13; 2 | 3 | import com.company.Lecture14.CircularQueue; 4 | 5 | public class QueueClient { 6 | public static void main(String[] args) { 7 | // Queue q = new Queue(); 8 | // 9 | // q.enqueue(2); 10 | // q.enqueue(8); 11 | // q.enqueue(3); 12 | // q.enqueue(7); 13 | // 14 | // q.display(); 15 | // 16 | // q.dequeue(); 17 | // q.dequeue(); 18 | // 19 | // q.display(); 20 | 21 | CircularQueue c = new CircularQueue(3); 22 | 23 | c.enqueue(4); 24 | c.enqueue(6); 25 | c.enqueue(7); 26 | 27 | System.out.println(c.dequeue()); 28 | System.out.println(c.dequeue()); 29 | System.out.println(c.dequeue()); 30 | System.out.println(c.dequeue()); 31 | 32 | 33 | c.enqueue(8); 34 | c.enqueue(4); 35 | c.enqueue(9); 36 | c.enqueue(2); 37 | c.display(); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/com/company/Lecture13/Stack.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture13; 2 | 3 | public class Stack { 4 | protected int[] data; 5 | private static final int DEFAULT_SIZE = 10; 6 | private int top = -1; 7 | 8 | public Stack(){ 9 | data = new int[DEFAULT_SIZE]; 10 | } 11 | 12 | public Stack(int size){ 13 | data = new int[size]; 14 | } 15 | 16 | public boolean isFull(){ 17 | return this.top == data.length-1; 18 | } 19 | 20 | public boolean isEmpty(){ 21 | return this.top == -1; 22 | } 23 | 24 | public void push(int item){ 25 | if(!isFull()){ 26 | data[++top] = item; 27 | } 28 | } 29 | 30 | public Integer pop(){ 31 | if(isEmpty()){ 32 | return null; 33 | } 34 | 35 | return data[top--]; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/com/company/Lecture13/StackClient.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture13; 2 | 3 | public class StackClient { 4 | public static void main(String[] args) { 5 | Stack s = new Stack(); 6 | s.push(65); 7 | s.push(58); 8 | s.push(37); 9 | 10 | System.out.println(s.pop()); 11 | System.out.println(s.pop()); 12 | System.out.println(s.pop()); 13 | System.out.println(s.pop()); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/com/company/Lecture14/CircularQueue.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture14; 2 | 3 | public class CircularQueue { 4 | protected int[] data; 5 | private static final int DEFAULT_SIZE = 10; 6 | protected int front; 7 | protected int end; 8 | private int size; 9 | 10 | public CircularQueue(){ 11 | this(DEFAULT_SIZE); 12 | } 13 | 14 | public CircularQueue(int size){ 15 | this.data = new int[size]; 16 | this.front = 0; 17 | this.end = -1; 18 | this.size = 0; 19 | } 20 | 21 | // public boolean isFull(){ 22 | // return ((front == 0 && end == data.length-1) || (front == end + 1)); 23 | // } 24 | // 25 | // public boolean isEmpty(){ 26 | // return (front == end); 27 | // } 28 | 29 | public boolean isFull(){ 30 | return this.size == this.data.length; 31 | } 32 | 33 | public boolean isEmpty(){ 34 | return this.size == 0; 35 | } 36 | 37 | public void enqueue(int item){ 38 | if(!isFull()){ 39 | this.end = (this.end + 1) % data.length; 40 | data[end] = item; 41 | size++; 42 | return; 43 | } 44 | System.out.println("Queue overflow!!"); 45 | } 46 | 47 | public Integer dequeue(){ 48 | if(!isEmpty()){ 49 | int temp = this.data[front]; 50 | this.front = (this.front + 1) % data.length; 51 | size--; 52 | return temp; 53 | } 54 | return null; 55 | } 56 | 57 | public void display(){ 58 | for (int i = 0; i < size - 1; i++) { 59 | System.out.print(data[(front + i) % data.length ] + ", "); 60 | } 61 | System.out.println(data[end]); 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /src/com/company/Lecture14/DynamicCircularQueue.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture14; 2 | 3 | public class DynamicCircularQueue extends CircularQueue{ 4 | @Override 5 | public void enqueue(int item) { 6 | if(isFull()){ 7 | int[] temp = new int[data.length * 2]; 8 | for (int i = 0; i < data.length; i++) { 9 | temp[i] = data[(i + this.front) % data.length]; 10 | } 11 | this.data = temp; 12 | } 13 | 14 | super.enqueue(item); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/com/company/Lecture14/inheritance/Car.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture14.inheritance; 2 | 3 | public class Car extends Vehicle{ 4 | public int doors = 4; 5 | public int wheels = 4; 6 | 7 | public Car(String license){ 8 | super(license); 9 | } 10 | 11 | public void start(){ 12 | System.out.println("Start like a generic Car"); 13 | } 14 | 15 | public void start(int speed){ 16 | System.out.println("Start like a generic Car " + speed); 17 | } 18 | 19 | @Override 20 | public void pollution() { 21 | System.out.println("This os how you check pollution"); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/com/company/Lecture14/inheritance/Client.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture14.inheritance; 2 | 3 | import java.util.Arrays; 4 | 5 | public class Client { 6 | public static void main(String[] args) { 7 | Car myCar = new Car("45678"); 8 | System.out.println(myCar.doors); 9 | 10 | Maruti myMaruti = new Maruti("56789"); 11 | System.out.println(myMaruti.doors); 12 | 13 | myCar.start(); 14 | myMaruti.start(); 15 | 16 | Car c = new Maruti("46789"); 17 | c.start(); 18 | 19 | Vehicle v = new Car("45678"); 20 | 21 | System.out.println(v.getLicense()); 22 | // int m = max( 7, 23, 765, 75, 435); 23 | 24 | Car car = new Car("5678654"); 25 | } 26 | 27 | // public static int max(int... items){ 28 | // System.out.println(Arrays.toString(items)); 29 | // } 30 | } 31 | -------------------------------------------------------------------------------- /src/com/company/Lecture14/inheritance/Maruti.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture14.inheritance; 2 | 3 | public class Maruti extends Car { 4 | public Maruti(String license){ 5 | super(license); 6 | } 7 | 8 | public int doors = 5; 9 | 10 | @Override 11 | public void start() { 12 | System.out.println("Start like all new Maruti benz"); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/com/company/Lecture14/inheritance/Vehicle.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture14.inheritance; 2 | 3 | public abstract class Vehicle { 4 | 5 | 6 | private String license; 7 | 8 | public Vehicle(){} 9 | 10 | public Vehicle(String license){ 11 | this.license = license; 12 | } 13 | 14 | public String getLicense(){ 15 | return license; 16 | } 17 | 18 | public abstract void pollution(); 19 | } 20 | -------------------------------------------------------------------------------- /src/com/company/Lecture15/CBStudent.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture15; 2 | 3 | public class CBStudent implements Students { 4 | 5 | public void study(){ 6 | System.out.println("Study like student"); 7 | } 8 | 9 | public void play(){ 10 | System.out.println("Play like student"); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/com/company/Lecture15/CBTeacher.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture15; 2 | 3 | public class CBTeacher implements Teacher { 4 | public void teach(){ 5 | System.out.println("Teach like a teacher"); 6 | } 7 | 8 | public void study(){ 9 | System.out.println("Study like a teacher"); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/com/company/Lecture15/CB_TA.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture15; 2 | 3 | public class CB_TA implements TA { 4 | 5 | public void study(){ 6 | System.out.println("Study like TA"); 7 | } 8 | 9 | public void play(){ 10 | System.out.println("Play like TA"); 11 | } 12 | 13 | public void teach(){ 14 | System.out.println("Teach like TA"); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/com/company/Lecture15/Car.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture15; 2 | 3 | public class Car { 4 | 5 | public int a; 6 | private int b; 7 | protected int c; 8 | int d; 9 | public void run(){ 10 | System.out.println("Bhaago!!"); 11 | } 12 | 13 | protected void run_protected(){ 14 | System.out.println("Bhaago!!"); 15 | } 16 | 17 | private void run_private(){ 18 | System.out.println("Bhaago!!"); 19 | } 20 | 21 | void run_default(){ 22 | System.out.println("Bhaago!!"); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/com/company/Lecture15/CarChild.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture15; 2 | 3 | public class CarChild extends Car{ 4 | public void check(){ 5 | a = 1; 6 | // b = 2; 7 | c = 3; 8 | d = 4; 9 | run(); 10 | run_protected(); 11 | run_default(); 12 | // run_private(); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /src/com/company/Lecture15/Client.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture15; 2 | 3 | public class Client { 4 | public static void main(String[] args) { 5 | 6 | Teacher t = new CBTeacher(); 7 | t.study(); 8 | t.teach(); 9 | 10 | Students s = new CBStudent(); 11 | s.study(); 12 | s.play(); 13 | 14 | Teacher ta = new CB_TA(); 15 | ta.teach(); 16 | ta.study(); 17 | 18 | Students sta = new CB_TA(); 19 | sta.play(); 20 | sta.study(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/com/company/Lecture15/Composition/Brake.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture15.Composition; 2 | 3 | public interface Brake { 4 | void apply(); 5 | } 6 | -------------------------------------------------------------------------------- /src/com/company/Lecture15/Composition/Car.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture15.Composition; 2 | 3 | public class Car { 4 | private Engine engine; 5 | private Brake brake; 6 | 7 | public Car(){ 8 | engine = new PetrolEngine(); 9 | brake = new GenericBrake(); 10 | } 11 | 12 | public void start(){ 13 | engine.start(); 14 | } 15 | 16 | public void stop(){ 17 | brake.apply(); 18 | engine.stop(); 19 | } 20 | 21 | public void upgrade(Engine engine){ 22 | this.engine = engine; 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/com/company/Lecture15/Composition/Client.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture15.Composition; 2 | 3 | public class Client { 4 | public static void main(String[] args) { 5 | Car car = new Car(); 6 | 7 | car.start(); 8 | car.stop(); 9 | 10 | //Upgarde the engine 11 | 12 | NitroEngine e = new NitroEngine(); 13 | car.upgrade(e); 14 | 15 | car.start(); 16 | car.stop(); 17 | 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/com/company/Lecture15/Composition/Engine.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture15.Composition; 2 | 3 | public interface Engine { 4 | void start(); 5 | void stop(); 6 | } 7 | -------------------------------------------------------------------------------- /src/com/company/Lecture15/Composition/GenericBrake.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture15.Composition; 2 | 3 | public class GenericBrake implements Brake { 4 | @Override 5 | public void apply() { 6 | System.out.println("Brake like a Generic Car"); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /src/com/company/Lecture15/Composition/NitroEngine.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture15.Composition; 2 | 3 | public class NitroEngine implements Engine{ 4 | @Override 5 | public void start() { 6 | System.out.println("Start like nito SuperCar"); 7 | } 8 | 9 | @Override 10 | public void stop() { 11 | System.out.println("Stop like nitro SuperCar"); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/com/company/Lecture15/Composition/PetrolEngine.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture15.Composition; 2 | 3 | public class PetrolEngine implements Engine { 4 | @Override 5 | public void start() { 6 | System.out.println("Start like a petrol Car"); 7 | } 8 | 9 | @Override 10 | public void stop() { 11 | System.out.println("Stop like a petrol Car"); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/com/company/Lecture15/Composition/Steering.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture15.Composition; 2 | 3 | public interface Steering { 4 | void left(); 5 | void right(); 6 | } 7 | -------------------------------------------------------------------------------- /src/com/company/Lecture15/Main.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture15; 2 | 3 | public class Main { 4 | public static void main(String[] args) { 5 | Car c = new Car(); 6 | 7 | c.a = 1; 8 | // c.b = 2; 9 | c.c = 3; 10 | c.d = 4; 11 | 12 | c.run(); 13 | c.run_protected(); 14 | // c.run_private(); 15 | c.run_default(); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/com/company/Lecture15/Other/Sample.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture15.Other; 2 | 3 | import com.company.Lecture15.Car; 4 | 5 | public class Sample extends Car { 6 | public static void main(String[] args) { 7 | Car c = new Car(); 8 | 9 | c.a = 1; 10 | // c.b = 2; 11 | // c.c = 3; 12 | // c.d = 4; 13 | 14 | c.run(); 15 | // c.run_protected(); 16 | // run_default(); 17 | // run_private(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/com/company/Lecture15/Other/SampleChild.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture15.Other; 2 | 3 | import com.company.Lecture15.Car; 4 | 5 | public class SampleChild extends Car { 6 | public void check(){ 7 | 8 | } 9 | 10 | public static void main(String[] args) { 11 | Car c = new Car(); 12 | 13 | c.a = 1; 14 | // c.b = 2; 15 | // c.c = 3; 16 | // c.d = 4; 17 | // 18 | c.run(); 19 | // c.run_protected(); 20 | // c.run_default(); 21 | // c.run_private(); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/com/company/Lecture15/StackQueue/QueueUsingStackInsert.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture15.StackQueue; 2 | 3 | import java.util.Stack; 4 | 5 | public class QueueUsingStackInsert { 6 | private Stack stack = new Stack(); 7 | 8 | public void add(int item){ 9 | stack.push(item); 10 | } 11 | 12 | public Integer remove(){ 13 | Stack temp = new Stack(); 14 | while(!stack.isEmpty()){ 15 | temp.push(stack.pop()); 16 | } 17 | int val = temp.pop(); 18 | while(!temp.isEmpty()){ 19 | stack.push(temp.pop()); 20 | } 21 | return val; 22 | } 23 | 24 | public boolean isEmpty(){ 25 | return stack.empty(); 26 | } 27 | 28 | public Integer front(){ 29 | Stack temp = new Stack(); 30 | while(!stack.isEmpty()){ 31 | temp.push(stack.pop()); 32 | } 33 | 34 | int val = temp.peek(); 35 | 36 | while(!temp.isEmpty()){ 37 | stack.push(temp.pop()); 38 | } 39 | return val; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/com/company/Lecture15/StackQueue/QueueUsingStackRemove.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture15.StackQueue; 2 | 3 | import java.util.Stack; 4 | 5 | public class QueueUsingStackRemove { 6 | private Stack stack = new Stack(); 7 | 8 | public int dequeue(){ 9 | return stack.pop(); 10 | } 11 | 12 | public void add(int item){ 13 | if(stack.isEmpty()){ 14 | stack.push(item); 15 | }else{ 16 | Stack temp = new Stack(); 17 | while(!stack.isEmpty()){ 18 | temp.push(stack.pop()); 19 | } 20 | stack.push(item); 21 | while (!temp.isEmpty()){ 22 | stack.push(temp.pop()); 23 | } 24 | } 25 | } 26 | 27 | public boolean isEmpty(){ 28 | return stack.empty(); 29 | } 30 | 31 | public Integer front(){ 32 | return stack.peek(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/com/company/Lecture15/StackQueue/SampleStack.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture15.StackQueue; 2 | 3 | import java.util.LinkedList; 4 | import java.util.Queue; 5 | import java.util.Stack; 6 | 7 | public class SampleStack { 8 | public static void main(String[] args) { 9 | Queue queue = new LinkedList(); 10 | 11 | queue.add(12); 12 | queue.add(65); 13 | 14 | System.out.println(queue.remove()); 15 | System.out.println(queue.remove()); 16 | 17 | Stack stack1 = new Stack(); 18 | Stack stack2 = new Stack(); 19 | 20 | stack1.push(72); 21 | stack1.push(61); 22 | 23 | } 24 | 25 | // public static void enque(int item){ 26 | // 27 | // } 28 | 29 | // public static int deque(sta){ 30 | // while(!stack1.empty()){ 31 | // stack2.push(stack1.pop()); 32 | // } 33 | // 34 | // System.out.println(stack2.pop()); 35 | // 36 | // while(!stack2.empty()){ 37 | // stack1.push(stack2.pop()); 38 | // } 39 | // } 40 | } 41 | -------------------------------------------------------------------------------- /src/com/company/Lecture15/Students.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture15; 2 | 3 | public interface Students { 4 | void study(); 5 | void play(); 6 | } 7 | -------------------------------------------------------------------------------- /src/com/company/Lecture15/TA.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture15; 2 | 3 | public interface TA extends Teacher,Students { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /src/com/company/Lecture15/Teacher.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture15; 2 | 3 | public interface Teacher { 4 | void teach(); 5 | void study(); 6 | } 7 | 8 | -------------------------------------------------------------------------------- /src/com/company/Lecture16/Client.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture16; 2 | 3 | public class Client { 4 | public static void main(String[] args) { 5 | LinkedList list = new LinkedList(); 6 | 7 | list.display(); 8 | 9 | list.insertFirst("Mohini"); 10 | list.insertLast("Suyash"); 11 | list.insertLast("Preksha"); 12 | list.display(); 13 | 14 | // list.deleteFirst(); 15 | // list.display(); 16 | // 17 | // list.deleteLast(); 18 | // list.display(); 19 | // 20 | // list.insert(1,"Preksha"); 21 | // list.display(); 22 | // 23 | // list.delete(1); 24 | // list.display(); 25 | // System.out.println(list.findMid()); 26 | // list.reverseList(); 27 | // list.display(); 28 | LinkedList first = new LinkedList(); 29 | LinkedList second; 30 | 31 | first.insertLast("Mona"); 32 | first.insertLast("Sona"); 33 | second = first.copy(); 34 | 35 | second.insertLast("rona"); 36 | 37 | first.display(); 38 | second.display(); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/com/company/Lecture16/QueueStack/Client.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture16.QueueStack; 2 | 3 | import com.company.Lecture14.CircularQueue; 4 | import com.company.Lecture14.DynamicCircularQueue; 5 | import com.company.Lecture15.StackQueue.QueueUsingStackRemove; 6 | import com.company.Lecture16.QueueStack.StackUsingQueuePop; 7 | import com.company.Lecture16.QueueStack.StackUsingQueuePush; 8 | 9 | public class Client { 10 | public static void main(String[] args) { 11 | QueueUsingStackRemove q = new QueueUsingStackRemove(); 12 | 13 | q.add(2); 14 | q.add(6); 15 | 16 | System.out.println(q.front()); 17 | 18 | StackUsingQueuePush s1 = new StackUsingQueuePush(); 19 | 20 | s1.push(7); 21 | s1.push(5); 22 | s1.push(6); 23 | 24 | System.out.println(s1.pop()); 25 | 26 | StackUsingQueuePop s2 = new StackUsingQueuePop(); 27 | 28 | s2.push(5); 29 | s2.push(8); 30 | s2.push(1); 31 | 32 | System.out.println(s2.pop()); 33 | 34 | CircularQueue c = new DynamicCircularQueue(); 35 | 36 | for (int i = 0; i < 10; i++) { 37 | c.enqueue(i); 38 | } 39 | 40 | c.dequeue(); 41 | c.dequeue(); 42 | 43 | for (int i = 0; i < 5; i++) { 44 | c.enqueue(i); 45 | } 46 | 47 | System.out.println(c.dequeue()); 48 | System.out.println(); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/com/company/Lecture16/QueueStack/StackUsingQueuePop.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture16.QueueStack; 2 | 3 | import com.company.Lecture13.Queue; 4 | 5 | public class StackUsingQueuePop { 6 | 7 | private Queue queue = new Queue(); 8 | 9 | public Integer pop(){ 10 | return queue.dequeue(); 11 | } 12 | 13 | public void push(int item){ 14 | Queue temp = new Queue(); 15 | temp.enqueue(item); 16 | while(!queue.isEmpty()){ 17 | temp.enqueue(queue.dequeue()); 18 | } 19 | queue = temp; 20 | } 21 | 22 | public Integer peek(){ 23 | return queue.end; 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/com/company/Lecture16/QueueStack/StackUsingQueuePush.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture16.QueueStack; 2 | 3 | import java.util.LinkedList; 4 | import java.util.Queue; 5 | 6 | public class StackUsingQueuePush { 7 | private Queue queue = new LinkedList(); 8 | 9 | public void push(int item){ 10 | queue.add(item); 11 | } 12 | 13 | public Integer pop(){ 14 | Queue temp = new LinkedList(); 15 | Integer t; 16 | while(true){ 17 | t = queue.remove(); 18 | if(queue.isEmpty()){ 19 | break; 20 | } 21 | temp.add(t); 22 | } 23 | 24 | queue = temp; 25 | return t; 26 | } 27 | 28 | public boolean isEmpty(){ 29 | return queue.isEmpty(); 30 | } 31 | 32 | public Integer peek(){ 33 | return queue.peek(); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/com/company/Lecture17/BinaryTree.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture17; 2 | 3 | import java.util.Scanner; 4 | 5 | public class BinaryTree { 6 | 7 | private Node root; 8 | 9 | public void add(String value, char... dirs){ 10 | this.root = add(root,value,dirs, 0); 11 | } 12 | 13 | private Node add(Node node, String value, char[] dirs, int index) { 14 | if(node == null){ 15 | node = new Node(value); 16 | return node; 17 | } 18 | 19 | if(dirs[index] == 'l'){ 20 | node.left = add(node.left, value, dirs,index+1); 21 | }else{ 22 | node.right = add(node.right, value, dirs, index + 1); 23 | } 24 | 25 | return node; 26 | } 27 | 28 | public String max(){ 29 | return max(root); 30 | } 31 | 32 | private String max(Node node) { 33 | if(node == null){ 34 | return null; 35 | } 36 | 37 | String max = node.value; 38 | 39 | String left = max(node.left); 40 | String right = max(node.right); 41 | 42 | if(left != null && max.compareTo(left) < 0) { 43 | max = left; 44 | } 45 | if(right != null && max.compareTo(right) < 0) { 46 | max = right; 47 | } 48 | 49 | return max; 50 | } 51 | 52 | public boolean find(String value){ 53 | return find(this.root,value); 54 | } 55 | 56 | private boolean find(Node node, String value) { 57 | if(node == null){ 58 | return false; 59 | } 60 | if(node.value.compareTo(value) == 0){ 61 | return true; 62 | } 63 | 64 | if(find(node.left,value)){ 65 | return true; 66 | } 67 | 68 | if(find(node.right,value)){ 69 | return true; 70 | } 71 | 72 | return false; 73 | } 74 | 75 | public void mirror(){ 76 | mirror(root); 77 | } 78 | 79 | private void mirror(Node node) { 80 | Node temp = node.left; 81 | node.left = node.right; 82 | node.right = temp; 83 | 84 | if(node.left != null){ 85 | mirror(node.left); 86 | } 87 | if(node.right != null) { 88 | mirror(node.right); 89 | } 90 | } 91 | 92 | public BinaryTree mirrorNew(){ 93 | BinaryTree newTree = new BinaryTree(); 94 | newTree.root = this.root; 95 | return mirrorNew(this.root,newTree); 96 | } 97 | 98 | private BinaryTree mirrorNew(Node node, BinaryTree newTree) { 99 | newTree.add(node.left.value,'r'); 100 | newTree.add(node.right.value,'l'); 101 | mirrorNew(node.left,newTree); 102 | mirrorNew(node.right,newTree); 103 | 104 | return newTree; 105 | } 106 | 107 | public void display(){ 108 | display(root, "","root"); 109 | } 110 | 111 | private void display(Node node, String indent, String type) { 112 | if(node == null){ 113 | return; 114 | } 115 | 116 | System.out.println(indent + node.value + " " + type); 117 | display(node.left,indent + "\t", "left"); 118 | display(node.right,indent + "\t", "right"); 119 | } 120 | 121 | private class Node{ 122 | String value; 123 | Node left; 124 | Node right; 125 | 126 | public Node(String value) { 127 | this.value = value; 128 | } 129 | } 130 | 131 | 132 | } 133 | -------------------------------------------------------------------------------- /src/com/company/Lecture17/LinkedList.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture17; 2 | 3 | public class LinkedList { 4 | 5 | private Node head; 6 | private Node tail; 7 | private int size; 8 | 9 | private class Node{ 10 | String value; 11 | Node next; 12 | 13 | public Node(String value) { 14 | this.value = value; 15 | } 16 | 17 | public Node(String value, Node next){ 18 | this.value = value; 19 | this.next = next; 20 | } 21 | } 22 | 23 | public void insertFirst(String vlaue){ 24 | Node node = new Node(vlaue, head); 25 | head = node; 26 | 27 | if(size == 0){ 28 | tail = head; 29 | } 30 | 31 | size++; 32 | } 33 | 34 | public void insertLast(String value){ 35 | if(size == 0){ 36 | insertFirst(value); 37 | return; 38 | } 39 | 40 | Node node = new Node(value); 41 | tail.next = node; 42 | tail = node; 43 | 44 | size++; 45 | } 46 | 47 | public String deleteFirst(){ 48 | if(size == 0){ 49 | return null; 50 | } 51 | String temp = head.value; 52 | head = head.next; 53 | size--; 54 | 55 | if(size == 0){ 56 | tail = null; 57 | } 58 | 59 | return temp; 60 | } 61 | 62 | public String deleteLast(){ 63 | if(size < 2){ 64 | return deleteFirst(); 65 | } 66 | 67 | Node prev = get(size - 2); 68 | String value = tail.value; 69 | prev.next = null; 70 | tail = prev; 71 | 72 | size--; 73 | 74 | return value; 75 | } 76 | 77 | public void insert(int index, String value){ 78 | if(index == 0){ 79 | insertFirst(value); 80 | return; 81 | }else if(index == size){ 82 | insertLast(value); 83 | return; 84 | } 85 | 86 | Node prev = get(index - 1); 87 | Node node = new Node(value,prev.next); 88 | prev.next = node; 89 | 90 | size++; 91 | } 92 | 93 | public String delete(int index){ 94 | if(index == 0){ 95 | return deleteFirst(); 96 | }else if(index == size-1){ 97 | return deleteLast(); 98 | } 99 | 100 | Node prev = get(index - 1); 101 | String value = prev.next.value; 102 | prev.next = prev.next.next; 103 | 104 | size--; 105 | 106 | return value; 107 | } 108 | 109 | public static LinkedList merge(LinkedList first,LinkedList second){ 110 | Node h1 = first.head; 111 | Node h2 = second.head; 112 | 113 | LinkedList list = new LinkedList(); 114 | 115 | while(h1 != null && h2 != null){ 116 | if(h1.value.compareTo(h2.value) < 0){ 117 | list.insertLast(h1.value); 118 | h1 = h1.next; 119 | }else{ 120 | list.insertLast(h2.value); 121 | h2 = h2.next; 122 | } 123 | } 124 | 125 | while (h1 != null){ 126 | list.insertLast(h1.value); 127 | h1 = h1.next; 128 | } 129 | 130 | while (h2 != null){ 131 | list.insertLast(h2.value); 132 | h2 = h2.next; 133 | } 134 | 135 | return list; 136 | } 137 | 138 | public Node get(int index){ 139 | Node node = head; 140 | for (int i = 1; i <= index; i++) { 141 | node = node.next; 142 | } 143 | 144 | return node; 145 | } 146 | 147 | public void display(){ 148 | Node node = head; 149 | 150 | while(node != null){ 151 | System.out.print(node.value + " -> "); 152 | node = node.next; 153 | } 154 | System.out.println("null"); 155 | } 156 | 157 | } 158 | -------------------------------------------------------------------------------- /src/com/company/Lecture17/LinkedListGeneric.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture17; 2 | 3 | public class LinkedListGeneric > { //Comparable interface should be implemented by T 4 | //Else it will not work for compareTo function 5 | private Node head; 6 | private Node tail; 7 | private int size; 8 | 9 | private class Node{ 10 | T value; 11 | Node next; 12 | 13 | public Node(T value) { 14 | this.value = value; 15 | } 16 | 17 | public Node(T value, Node next){ 18 | this.value = value; 19 | this.next = next; 20 | } 21 | } 22 | 23 | public void insertFirst(T value){ 24 | head = new Node(value, head); 25 | 26 | if(size == 0){ 27 | tail = head; 28 | } 29 | 30 | size++; 31 | } 32 | 33 | public void insertLast(T value){ 34 | if(size == 0){ 35 | insertFirst(value); 36 | return; 37 | } 38 | 39 | Node node = new Node(value); 40 | tail.next = node; 41 | tail = node; 42 | 43 | size++; 44 | } 45 | 46 | public T deleteFirst(){ 47 | if(size == 0){ 48 | return null; 49 | } 50 | T temp = head.value; 51 | head = head.next; 52 | size--; 53 | 54 | if(size == 0){ 55 | tail = null; 56 | } 57 | 58 | return temp; 59 | } 60 | 61 | public T deleteLast(){ 62 | if(size < 2){ 63 | return deleteFirst(); 64 | } 65 | 66 | Node prev = get(size - 2); 67 | T value = tail.value; 68 | prev.next = null; 69 | tail = prev; 70 | 71 | size--; 72 | 73 | return value; 74 | } 75 | 76 | public void insert(int index, T value){ 77 | if(index == 0){ 78 | insertFirst(value); 79 | return; 80 | }else if(index == size){ 81 | insertLast(value); 82 | return; 83 | } 84 | 85 | Node prev = get(index - 1); 86 | Node node = new Node(value,prev.next); 87 | prev.next = node; 88 | 89 | size++; 90 | } 91 | 92 | public T delete(int index){ 93 | if(index == 0){ 94 | return deleteFirst(); 95 | }else if(index == size-1){ 96 | return deleteLast(); 97 | } 98 | 99 | Node prev = get(index - 1); 100 | T value = prev.next.value; 101 | prev.next = prev.next.next; 102 | 103 | size--; 104 | 105 | return value; 106 | } 107 | 108 | public LinkedListGeneric merge(LinkedListGeneric first, LinkedListGeneric second){ 109 | Node h1 = first.head; 110 | Node h2 = second.head; 111 | 112 | LinkedListGeneric list = new LinkedListGeneric<>(); 113 | 114 | while(h1 != null && h2 != null){ 115 | if(h1.value.compareTo(h2.value) < 0){ 116 | list.insertLast(h1.value); 117 | h1 = h1.next; 118 | }else{ 119 | list.insertLast(h2.value); 120 | h2 = h2.next; 121 | } 122 | } 123 | 124 | while (h1 != null){ 125 | list.insertLast(h1.value); 126 | h1 = h1.next; 127 | } 128 | 129 | while (h2 != null){ 130 | list.insertLast(h2.value); 131 | h2 = h2.next; 132 | } 133 | 134 | return list; 135 | } 136 | 137 | public Node get(int index){ 138 | Node node = head; 139 | for (int i = 1; i <= index; i++) { 140 | node = node.next; 141 | } 142 | 143 | return node; 144 | } 145 | 146 | public void display(){ 147 | Node node = head; 148 | 149 | while(node != null){ 150 | System.out.print(node.value + " -> "); 151 | node = node.next; 152 | } 153 | System.out.println("null"); 154 | } 155 | 156 | } 157 | -------------------------------------------------------------------------------- /src/com/company/Lecture17/ListClient.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture17; 2 | 3 | public class ListClient { 4 | public static void main(String[] args) { 5 | LinkedList list = new LinkedList(); 6 | 7 | list.insertFirst("Mohita"); 8 | list.insertFirst("Mohan"); 9 | list.insertLast("Ravi"); 10 | list.display(); 11 | 12 | // list.deleteFirst(); 13 | 14 | // list.insert(1,"Priyanka"); 15 | // list.insert(2,"Gagan"); 16 | // 17 | // list.display(); 18 | // 19 | // list.delete(1); 20 | 21 | list.display(); 22 | 23 | LinkedListGeneric num = new LinkedListGeneric(); 24 | 25 | num.insertLast(1); 26 | num.insert(0,5); 27 | 28 | num.display(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/com/company/Lecture17/TreeClient.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture17; 2 | 3 | public class TreeClient { 4 | public static void main(String[] args) { 5 | BinaryTree tree = new BinaryTree(); 6 | 7 | tree.add("10"); 8 | tree.add("20",'l'); 9 | tree.add("25",'r'); 10 | tree.add("30",'l','r'); 11 | tree.add("40",'r','r'); 12 | 13 | tree.add("35",'l','r','r'); 14 | 15 | // tree.display(); 16 | // 17 | // System.out.println(tree.max()); 18 | // 19 | System.out.println(tree.find("30")); 20 | 21 | tree.mirror(); 22 | 23 | tree.display(); 24 | 25 | BinaryTree treeNew = tree.mirrorNew(); 26 | 27 | treeNew.display(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/com/company/Lecture18/BSTClient.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture18; 2 | 3 | public class BSTClient { 4 | public static void main(String[] args) { 5 | BST tree = new BST(); 6 | 7 | // for (int i = 0; i < 10; i++) { 8 | // tree.add((int)(Math.random() * 10)); 9 | // } 10 | 11 | tree.add(14); 12 | tree.add(20); 13 | tree.add(8); 14 | tree.add(10); 15 | tree.add(15); 16 | tree.add(6); 17 | tree.add(22); 18 | // System.out.println(tree.heightOfTree()); 19 | 20 | // tree.display(); 21 | // 22 | // System.out.println(tree.max()); 23 | // System.out.println(tree.min()); 24 | 25 | // tree.range(4,15); 26 | Integer[] nums = {1,2,3,4,5}; 27 | BST t = new BST(); 28 | t.populateFromSorted(nums); 29 | 30 | t.display(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/com/company/Lecture18/BSTClientNew.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture18; 2 | 3 | import com.company.Lecture17.LinkedList; 4 | import com.company.Lecture17.LinkedListGeneric; 5 | 6 | public class BSTClientNew { 7 | public static void main(String[] args) { 8 | BST tree = new BST(); 9 | tree.add(14); 10 | tree.add(20); 11 | tree.add(8); 12 | tree.add(10); 13 | tree.add(15); 14 | tree.add(6); 15 | tree.add(22); 16 | 17 | tree.display(); 18 | 19 | System.out.println("Successor of 14 : " + tree.nodeSuccessor(14)); 20 | 21 | LinkedListGeneric list = tree.makeSortedList(); 22 | 23 | System.out.print("Sorted Linked List : "); 24 | list.display(); 25 | 26 | // for (int i = 0; i < 10000; i++) { // after balancing 27 | // tree.add(i); 28 | // } 29 | // 30 | // System.out.println(tree.heightOfTree()); 31 | 32 | // tree.add(5); 33 | // tree.add(10); 34 | // tree.add(15); 35 | // 36 | // tree.display(); 37 | // 38 | // tree.leftRotate(); 39 | // 40 | // tree.display(); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/com/company/Lecture18/GenericClient.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture18; 2 | 3 | public class GenericClient { 4 | public static void main(String[] args) { 5 | BinaryTreeGeneric tree = new BinaryTreeGeneric(); 6 | 7 | tree.add(10); 8 | tree.add(5,'l'); 9 | tree.add(6,'r'); 10 | tree.add(9,'r','r'); 11 | tree.add(7,'l','r'); 12 | tree.add(3,'l','l'); 13 | 14 | tree.display(); 15 | 16 | BinaryTreeGeneric t = new BinaryTreeGeneric(); 17 | Integer[] pre = {10,5,3,7,6,9}; 18 | Integer[] in = {3,5,7,10,6,9}; 19 | 20 | t.fromPreIn(pre,in); 21 | 22 | t.display(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/com/company/Lecture18/TreeClient.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture18; 2 | 3 | public class TreeClient { 4 | public static void main(String[] args) { 5 | BinaryTree tree = new BinaryTree(); 6 | 7 | tree.add("10"); 8 | tree.add("20",'l'); 9 | tree.add("25",'r'); 10 | tree.add("30",'l','r'); 11 | tree.add("40",'r','r'); 12 | tree.add("35",'l','r','r'); 13 | 14 | tree.orders(); 15 | 16 | System.out.println(tree.diameter()); 17 | 18 | // System.out.println(tree.find("30")); 19 | // 20 | // tree.mirror(); 21 | // 22 | // tree.display(); 23 | // 24 | // BinaryTree treeNew = tree.mirrorNew(); 25 | // 26 | // treeNew.display(); 27 | // 28 | 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/com/company/Lecture19/Greedy/KnapSack.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture19.Greedy; 2 | 3 | import java.util.Arrays; 4 | 5 | public class KnapSack{ 6 | public static void main(String[] args) { 7 | double[] price = {5,10,15,5,10}; 8 | double[] weight = {1, 2, 3, 4, 1}; 9 | double cap = 5; 10 | Item[] items = new Item[price.length]; 11 | for (int i = 0; i < price.length; i++) { 12 | items[i] = new Item(price[i], weight[i]); 13 | } 14 | 15 | Arrays.sort(items); 16 | System.out.println(Arrays.toString(items)); 17 | 18 | double reward = 0; 19 | 20 | for (int i = 0; i < items.length && cap > 0; i++) { 21 | if(cap > items[i].weight){ 22 | cap -= items[i].weight; 23 | reward += items[i].price; 24 | }else{ 25 | reward += cap * items[i].density; 26 | cap = 0; 27 | } 28 | } 29 | 30 | System.out.println(reward); 31 | } 32 | public static class Item implements Comparable{ 33 | public double weight; 34 | public double price; 35 | public double density; 36 | 37 | public Item(double price, double weight) { 38 | this.price = price; 39 | this.weight = weight; 40 | this.density = price/weight; 41 | } 42 | 43 | 44 | @Override 45 | public int compareTo(Item other) { 46 | if(other.density > this.density){ 47 | return 1; 48 | }else if(other.density < this.density){ 49 | return -1; 50 | }else{ 51 | return 0; 52 | } 53 | } 54 | 55 | @Override 56 | public String toString() { 57 | return String.format("{%.2f, %.2f, %.2f}",price,weight,density); 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/com/company/Lecture19/Heap.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture19; 2 | 3 | import java.util.ArrayList; 4 | 5 | public class Heap> { 6 | ArrayList list = new ArrayList(); 7 | 8 | private int left(int index){ 9 | return index*2 + 1; 10 | } 11 | 12 | private int right(int index){ 13 | return index*2 + 2; 14 | } 15 | 16 | private int parent(int index){ 17 | return (index - 1)/2; 18 | } 19 | 20 | public void add(T value){ 21 | list.add(value); 22 | upHeap(list.size() - 1); 23 | } 24 | 25 | private void upHeap(int index){ 26 | if(index == 0){ 27 | return; 28 | } 29 | int parent = parent(index); 30 | if(list.get(parent).compareTo(list.get(index)) <= 0){ 31 | return; 32 | } 33 | T temp = list.get(index); 34 | list.set(index,list.get(parent)); 35 | list.set(parent,temp); 36 | upHeap(parent); 37 | } 38 | 39 | private void downHeap(int index){ 40 | int min = index; 41 | int left = left(index); 42 | int right = right(index); 43 | if(left < list.size() && list.get(left).compareTo(list.get(min)) < 0){ 44 | min = left; 45 | } 46 | if(right < list.size() && list.get(right).compareTo(list.get(min)) < 0 ){ 47 | min = right; 48 | } 49 | if(min != index){ 50 | T temp = list.get(index); 51 | list.set(index,list.get(min)); 52 | list.set(min,temp); 53 | downHeap(min); 54 | } 55 | } 56 | 57 | public T remove(){ 58 | if (list.isEmpty()) { 59 | return null; 60 | } 61 | if (list.size() == 1) { 62 | return list.remove(0); 63 | } 64 | T value = list.get(0); 65 | list.set(0,list.remove(list.size()-1)); 66 | downHeap(0); 67 | return value; 68 | } 69 | 70 | @Override 71 | public String toString() { 72 | return list.toString(); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/com/company/Lecture19/HeapClient.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture19; 2 | 3 | public class HeapClient { 4 | public static void main(String[] args) { 5 | Heap heap = new Heap<>(); 6 | 7 | heap.add(4); 8 | heap.add(8); 9 | heap.add(1); 10 | heap.add(9); 11 | 12 | System.out.println(heap.remove()); 13 | System.out.println(heap.remove()); 14 | System.out.println(heap); 15 | System.out.println(heap.remove()); 16 | System.out.println(heap.remove()); 17 | System.out.println(heap); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/com/company/Lecture19/Human.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture19; 2 | 3 | public class Human implements Comparable{ 4 | private String name; 5 | private int age; 6 | 7 | public Human(String name, int age){ 8 | this.name =name; 9 | this.age = age; 10 | } 11 | 12 | @Override 13 | public int compareTo(Human other) { 14 | return this.age - other.age; 15 | } 16 | 17 | public String toString(){ 18 | return "{" + name + " : " + age + "}"; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/com/company/Lecture19/Main.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture19; 2 | 3 | import java.util.Arrays; 4 | 5 | public class Main { 6 | public static void main(String[] args) { 7 | Human Ekta = new Human("Ekta",19); 8 | Human Suyash = new Human("Suyash", 20); 9 | Human Anu = new Human("Anu",21); 10 | 11 | Human[] humans = {Ekta,Suyash,Anu}; 12 | Arrays.sort(humans); 13 | 14 | System.out.println(Arrays.toString(humans)); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/com/company/Lecture19/PQClient.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture19; 2 | 3 | import java.util.PriorityQueue; 4 | 5 | public class PQClient { 6 | public static void main(String[] args) { 7 | PriorityQueue queue = new PriorityQueue(); 8 | queue.add(3); 9 | queue.add(4); 10 | queue.add(1); 11 | queue.add(2); 12 | 13 | System.out.println(queue.remove()); 14 | System.out.println(queue.remove()); 15 | System.out.println(queue.remove()); 16 | 17 | queue.add(1); 18 | queue.add(2); 19 | 20 | System.out.println(queue.remove()); 21 | System.out.println(queue.remove()); 22 | System.out.println(queue.remove()); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/com/company/Lecture2/Leap.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture2; 2 | 3 | public class Leap { 4 | public static void main(String[] args) { 5 | int year = 2015; 6 | 7 | if (year % 4 == 0) { 8 | System.out.println("Leap Year"); 9 | } 10 | else { 11 | System.out.println("Not leap Year"); 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/com/company/Lecture2/Loop.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture2; 2 | 3 | public class Loop { 4 | public static void main(String[] args) { 5 | int n = 4; 6 | int row =0; 7 | 8 | while (row < n) { 9 | int col = 0; 10 | while( col < n){ 11 | System.out.print("* "); 12 | col++; 13 | } 14 | System.out.println(); 15 | 16 | row++; 17 | } 18 | 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/com/company/Lecture2/Main.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture2; 2 | 3 | public class Main { 4 | 5 | public static void main(String[] args) { 6 | // write your code here 7 | System.out.println("Welcome to Coding Blocks"); 8 | 9 | int p = 1000; 10 | int r = 8; 11 | int t = 4; 12 | 13 | int si = (p*r*t)/100; 14 | 15 | System.out.println(si); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/com/company/Lecture20/CustomHashSet.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture20; 2 | 3 | import java.util.ArrayList; 4 | import java.util.LinkedList; 5 | 6 | public class CustomHashSet { 7 | 8 | private ArrayList> array; //using arraylist because working in generic mode 9 | 10 | private static final int DEFAULT_SIZE = 20; 11 | 12 | private Integer size = 0; 13 | 14 | public CustomHashSet(){ 15 | array = new ArrayList>(); 16 | for (int i = 0; i < DEFAULT_SIZE; i++) { 17 | array.add(new LinkedList()); 18 | } 19 | } 20 | 21 | public void add(K key){ 22 | int index = Math.abs(key.hashCode() % array.size()); 23 | LinkedList list = array.get(index); 24 | for (Node node : list){ 25 | if(node.key.equals(key)){ 26 | return; 27 | } 28 | } 29 | size++; 30 | list.add(new Node(key)); 31 | if((((float)size)/array.size()) > .5){ 32 | rehash(); 33 | } 34 | } 35 | 36 | private void rehash() { 37 | ArrayList> old = array; 38 | 39 | array = new ArrayList>(); 40 | for (int i = 0; i < old.size() * 2; i++) { 41 | array.add(new LinkedList()); 42 | } 43 | size = 0; 44 | for(LinkedList list : old){ 45 | for(Node node : list){ 46 | add(node.key); 47 | } 48 | } 49 | } 50 | 51 | public boolean contains(K key){ 52 | int index = Math.abs(key.hashCode() % array.size()); 53 | 54 | LinkedList list = array.get(index); 55 | 56 | for (Node node : list){ 57 | if(node.key.equals(key)){ 58 | return true; 59 | } 60 | } 61 | 62 | return false; 63 | } 64 | 65 | public boolean remove(K key){ 66 | int index = Math.abs(key.hashCode() % array.size()); 67 | LinkedList list = array.get(index); 68 | Node target = null; 69 | for (Node node : list){ 70 | if(node.key.equals(key)){ 71 | target = node; 72 | break; 73 | } 74 | } 75 | if(target == null){ 76 | return false; 77 | } 78 | list.remove(target); 79 | size--; 80 | return true; 81 | } 82 | 83 | private class Node{ 84 | K key; 85 | 86 | public Node(K key) { 87 | this.key = key; 88 | } 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /src/com/company/Lecture20/CustomHashTable.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture20; 2 | 3 | import java.util.ArrayList; 4 | import java.util.LinkedList; 5 | 6 | public class CustomHashTable { 7 | private class Node{ 8 | K key; 9 | V value; 10 | 11 | 12 | public Node(K key, V value) { 13 | this.key = key; 14 | this.value = value; 15 | } 16 | } 17 | 18 | private ArrayList> array; //using arraylist because working in generic mode 19 | private static final int DEFAULT_SIZE = 20; 20 | private Integer size = 0; 21 | 22 | public CustomHashTable(){ 23 | array = new ArrayList>(); 24 | for (int i = 0; i < DEFAULT_SIZE; i++) { 25 | array.add(new LinkedList()); 26 | } 27 | } 28 | 29 | public void put(K key, V value){ 30 | int index = Math.abs(key.hashCode() % array.size()); 31 | LinkedList list = array.get(index); 32 | for (Node node : list){ 33 | if(node.key.equals(key)){ 34 | node.value = value; 35 | return; 36 | } 37 | } 38 | size++; 39 | list.add(new Node(key,value)); 40 | if((((float)size)/array.size()) > .5){ 41 | rehash(); 42 | } 43 | } 44 | 45 | private void rehash() { 46 | ArrayList> old = array; 47 | array = new ArrayList<>(); 48 | for (int i = 0; i < old.size() * 2; i++) { 49 | array.add(new LinkedList<>()); 50 | } 51 | size = 0; 52 | for(LinkedList list : old){ 53 | for(Node node : list){ 54 | put(node.key, node.value); 55 | } 56 | } 57 | } 58 | 59 | public V get(K key){ 60 | int index = Math.abs(key.hashCode() % array.size()); 61 | LinkedList list = array.get(index); 62 | 63 | for (Node node : list){ 64 | if(node.key.equals(key)){ 65 | return node.value; 66 | } 67 | } 68 | return null; 69 | } 70 | 71 | public V remove(K key){ 72 | int index = Math.abs(key.hashCode() % array.size()); 73 | LinkedList list = array.get(index); 74 | Node target = null; 75 | for (Node node : list){ 76 | if(node.key.equals(key)){ 77 | target = node; 78 | break; 79 | } 80 | } 81 | if(target == null){ 82 | return null; 83 | } 84 | list.remove(target); 85 | size--; 86 | return target.value; 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /src/com/company/Lecture20/Main.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture20; 2 | 3 | import java.util.HashMap; 4 | 5 | public class Main { 6 | public static void main(String[] args) { 7 | // CustomHashTable dict = new CustomHashTable(); 8 | // 9 | // dict.put("apple","a sweet red fruit"); 10 | // dict.put("mango","king of fruits"); 11 | String s1 ="apple"; 12 | String s2 = "mango"; 13 | System.out.println(s1.hashCode() + " " + s2.hashCode()); 14 | // System.out.println(dict.get("apple")); 15 | // 16 | // dict.put("apple","a sour red fruit"); 17 | // 18 | // System.out.println(dict.get("apple")); 19 | // 20 | // dict.remove("apple"); 21 | // 22 | // System.out.println(dict.get("apple")); 23 | // System.out.println(dict.get("lichi")); 24 | 25 | // System.out.println(dict.hashCode()); 26 | 27 | CustomHashTable dict = new CustomHashTable(); 28 | 29 | for (int i = 0; i < 10000; i++) { 30 | dict.put(i,i); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/com/company/Lecture20/Questions.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture20; 2 | 3 | import java.util.*; 4 | 5 | public class Questions { 6 | public static void main(String[] args) { 7 | // Q1("Ekta Mishra"); 8 | Integer[] arr1 = {1,2,3,4,5}; 9 | Integer[] arr2 = {3,3,3,3,3,3,2,9,1}; 10 | Q2(arr1,arr2); 11 | Q3(arr1,arr2); 12 | } 13 | public static void Q1(String line) { 14 | // print occ count for each other 15 | 16 | HashMap map = new HashMap(); 17 | 18 | for (int i = 0; i < line.length(); i++) { 19 | char ch = line.charAt(i); 20 | 21 | if(map.containsKey(ch)){ 22 | map.put(ch,map.get(ch)+1); 23 | }else { 24 | map.put(ch, 1); 25 | } 26 | } 27 | 28 | System.out.println(map); 29 | } 30 | 31 | public static void Q2(Integer[] arr1, Integer[] arr2){ 32 | HashMap map = new HashMap(); 33 | 34 | List list = new ArrayList(0); 35 | for (Integer integer : arr1) { 36 | if (map.containsKey(integer)) { 37 | map.put(integer, map.get(integer) + 1); 38 | } else { 39 | map.put(integer, 1); 40 | } 41 | } 42 | 43 | for (Integer integer : arr2) { 44 | if (map.containsKey(integer) && map.get(integer) > 0) { 45 | map.put(integer, map.get(integer) - 1); 46 | list.add(integer); 47 | } 48 | } 49 | 50 | Collections.sort(list); 51 | System.out.println(list); 52 | } 53 | 54 | public static void Q3(Integer arr1[], Integer arr2[]){ 55 | Set set = new HashSet(); 56 | Set inter = new HashSet(); 57 | 58 | ArrayList list = new ArrayList(); 59 | 60 | for(int item : arr1){ 61 | set.add(item); 62 | } 63 | 64 | for(int item : arr2){ 65 | if(set.contains(item)){ 66 | inter.add(item); 67 | } 68 | } 69 | 70 | for(int item : inter){ 71 | list.add(item); 72 | } 73 | 74 | Collections.sort(list); 75 | System.out.println(list); 76 | 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/com/company/Lecture20/SetClient.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture20; 2 | 3 | import java.util.HashSet; 4 | 5 | public class SetClient { 6 | public static void main(String[] args) { 7 | HashSet set = new HashSet(); 8 | 9 | CustomHashSet set1 = new CustomHashSet(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/com/company/Lecture20/TableUsingArray.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture20; 2 | 3 | import java.util.ArrayList; 4 | 5 | public class TableUsingArray { 6 | 7 | private ArrayList array; //using Arraylist because working in generic mode 8 | 9 | private static final int DEFAULT_SIZE = 20; 10 | 11 | public TableUsingArray(){ 12 | array = new ArrayList(); 13 | for (int i = 0; i < DEFAULT_SIZE; i++) { 14 | array.add(null); 15 | } 16 | } 17 | 18 | public void put(K key, V value){ 19 | int index = Math.abs(key.hashCode() % array.size()); 20 | 21 | array.set(index, new Node(key, value)); 22 | } 23 | 24 | public V get(K key){ 25 | int index = Math.abs(key.hashCode() % array.size()); 26 | 27 | Node node = array.get(index); 28 | 29 | if(node == null || !node.key.equals(key)){ 30 | return null; 31 | } 32 | 33 | return node.value; 34 | } 35 | 36 | public V remove(K key){ 37 | int index = Math.abs(key.hashCode() % array.size()); 38 | 39 | Node node = array.get(index); 40 | 41 | if(node == null || !node.key.equals(key)){ 42 | return null; 43 | } 44 | 45 | array.set(index, null); 46 | return node.value; 47 | } 48 | 49 | private class Node{ 50 | K key; 51 | V value; 52 | 53 | 54 | public Node(K key, V value) { 55 | this.key = key; 56 | this.value = value; 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/com/company/Lecture20/TableUsingList.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture20; 2 | 3 | import java.util.LinkedList; 4 | 5 | public class TableUsingList { 6 | 7 | private LinkedList list = new LinkedList(); 8 | 9 | public void put(K key, V value){ 10 | for (Node node : list){ 11 | if(node.key.equals(key)){ 12 | node.value = value; 13 | return; 14 | } 15 | } 16 | 17 | list.add(new Node(key,value)); 18 | } 19 | 20 | public V get(K key){ 21 | for (Node node : list){ 22 | if(node.key.equals(key)){ 23 | return node.value; 24 | } 25 | } 26 | 27 | return null; 28 | } 29 | 30 | public V remove(K key){ 31 | Node target = null; 32 | for (Node node : list){ 33 | if(node.key.equals(key)){ 34 | target = node; 35 | break; 36 | } 37 | } 38 | 39 | if(target == null){ 40 | return null; 41 | } 42 | 43 | list.remove(target); 44 | return target.value; 45 | } 46 | 47 | private class Node{ 48 | K key; 49 | V value; 50 | 51 | 52 | public Node(K key, V value) { 53 | this.key = key; 54 | this.value = value; 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/com/company/Lecture21/EdgeListGraph.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture21; 2 | 3 | import java.util.LinkedList; 4 | 5 | public class EdgeListGraph { 6 | public LinkedList vertices = new LinkedList(); 7 | public LinkedList edges = new LinkedList(); 8 | 9 | private class Vertex{ 10 | private E value; 11 | public Vertex(E value){ 12 | this.value = value; 13 | } 14 | } 15 | 16 | private class Edge{ 17 | private Vertex start; 18 | private Vertex end; 19 | 20 | public Edge(Vertex start, Vertex end){ 21 | this.start = start; 22 | this.end = end; 23 | } 24 | } 25 | 26 | //We need to traverse all edges to find neighbours of a particular vertex 27 | // for adding a vertex we need to traverse whole vertex list 28 | // for adding edge we have to traverse both vertices and edge list 29 | public void addVertex(E value){ 30 | if(find(value) == null){ 31 | vertices.add(new Vertex(value)); 32 | } 33 | 34 | } 35 | 36 | private Vertex find(E value){ 37 | for (Vertex vertex : vertices) { 38 | if(vertex.value.equals(value)){ 39 | return vertex; 40 | } 41 | } 42 | 43 | return null; 44 | } 45 | 46 | public void addEdge(E value1, E value2){ 47 | Vertex A = find(value1); 48 | Vertex B = find(value2); 49 | if(A != null && B != null){ 50 | edges.add(new Edge(A,B)); 51 | } 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/com/company/Lecture21/GraphClient.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture21; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Arrays; 5 | import java.util.LinkedList; 6 | import java.util.List; 7 | 8 | public class GraphClient { 9 | public static void main(String[] args) { 10 | AdjListGraph graph = new AdjListGraph(); 11 | 12 | List> list; 13 | 14 | graph.addVertex(1); 15 | graph.addVertex(2); 16 | graph.addVertex(3); 17 | graph.addVertex(4); 18 | graph.addVertex(5); 19 | graph.addVertex(6); 20 | 21 | // graph.addEdge(1,2); 22 | // graph.addEdge(1,3); 23 | // graph.addEdge(1,5); 24 | // 25 | // graph.addEdge(4,5); 26 | // graph.addEdge(4,3); 27 | 28 | // graph.DFT(1); 29 | // System.out.println(); 30 | // graph.BFT(1); 31 | 32 | // System.out.println(graph.BFS(1,4)); 33 | // System.out.println(graph.BFS(1,7)); 34 | 35 | // list = graph.connectedComponent(); 36 | // System.out.println(list); 37 | // 38 | // graph.addEdge(1,5); 39 | // graph.addEdge(3,5); 40 | // graph.addEdge(2,4); 41 | // graph.addEdge(2,6); 42 | // graph.addEdge(4,6); 43 | // graph.addEdge(2,1); 44 | // 45 | // System.out.println(graph.bipartiteGraph()); 46 | 47 | graph.addEdge(1,2); 48 | graph.addEdge(2,3); 49 | graph.addEdge(3,1); 50 | graph.addEdge(4,1); 51 | graph.addEdge(6,3); 52 | 53 | System.out.println(graph.isCyclic(1)); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/com/company/Lecture22/AdjMapGraph.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture22; 2 | 3 | import java.util.*; 4 | 5 | public class AdjMapGraph { 6 | private Map vertices = new HashMap(); 7 | 8 | public void addVertex(E value){ 9 | if(!vertices.containsKey(value)){ 10 | vertices.put(value,new Vertex(value)); 11 | } 12 | } 13 | 14 | public void addEdge(E first, E second){ 15 | Vertex f = vertices.get(first); 16 | Vertex s = vertices.get(second); 17 | if(f != null && s != null && f != s){ //f comparing to s to deny self loops 18 | f.neighbours.put(second, s); 19 | s.neighbours.put(first, f); 20 | } 21 | } 22 | 23 | public void removeEdge(E first, E second){ 24 | Vertex f = vertices.get(first); 25 | Vertex s = vertices.get(second); 26 | if(f != null && s != null && f != s){ //f comparing to s to deny self loops 27 | f.neighbours.remove(second); 28 | s.neighbours.remove(first); 29 | } 30 | } 31 | 32 | private Map generateParents(){ 33 | Map parents = new HashMap(); 34 | for(Vertex vertex : vertices.values()){ 35 | parents.put(vertex, null); 36 | } 37 | return parents; 38 | } 39 | 40 | private Vertex find(Vertex vertex, Map parents){ 41 | while (parents.get(vertex) != null){ 42 | vertex = parents.get(vertex); 43 | } 44 | return vertex; 45 | } 46 | 47 | private boolean Union(Vertex first,Vertex second, Map parents){ 48 | first = find(first, parents); 49 | second = find(second, parents); 50 | if(first != second){ 51 | parents.put(first, second); 52 | return true; 53 | } 54 | return false; 55 | } 56 | 57 | private class Vertex{ 58 | E value; 59 | Map neighbours = new HashMap(); 60 | public Vertex(E value) { 61 | this.value = value; 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/com/company/Lecture22/GraphClient.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture22; 2 | 3 | public class GraphClient { 4 | public static void main(String[] args) { 5 | AdjMapWeightGraph graph = new AdjMapWeightGraph(); 6 | 7 | graph.addVertex(1); 8 | graph.addVertex(2); 9 | graph.addVertex(3); 10 | graph.addVertex(4); 11 | 12 | graph.addEdge(1,2,5); 13 | graph.addEdge(1,3,10); 14 | graph.addEdge(1,4,8); 15 | graph.addEdge(2,4,12); 16 | graph.addEdge(3,4,15); 17 | 18 | // graph.DFT(1); 19 | System.out.println(graph.kruskal()); 20 | // System.out.println(graph.prims()); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/com/company/Lecture23/CustomException.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture23; 2 | 3 | public class CustomException extends Exception { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /src/com/company/Lecture23/ExceptionClient.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture23; 2 | 3 | public class ExceptionClient { 4 | public static void main(String[] args) { 5 | // Exception exception = new Exception("Hey! I'm Exception"); 6 | // 7 | // throw exception; 8 | // try { 9 | // danger(); 10 | // }catch (Exception e){ 11 | // System.out.println("Koi nhi yrr"); 12 | // } 13 | 14 | ThreadExample one = new ThreadExample(); 15 | ThreadExample two = new ThreadExample(); 16 | // For Parallel process 17 | one.start(); 18 | two.start(); 19 | // For Multi Process 20 | one.run(); 21 | two.run(); 22 | 23 | } 24 | 25 | public static void danger() throws Exception{ 26 | Exception exception = new Exception("Hey! I'm Exception"); 27 | throw exception; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/com/company/Lecture23/ScannerExmple.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture23; 2 | 3 | import java.util.Scanner; 4 | 5 | public class ScannerExmple { 6 | public static void main(String[] args) { 7 | Scanner s = new Scanner(System.in); 8 | 9 | } 10 | 11 | public static void input(){ 12 | Scanner s = new Scanner(System.in); 13 | 14 | String line = s.nextLine(); 15 | 16 | Scanner temp = new Scanner(line); 17 | 18 | int[] nums = new int[10]; 19 | 20 | for (int i = 0; i < nums.length; i++) { 21 | nums[i] = temp.nextInt(); //Reading from String line 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/com/company/Lecture23/Sudoku.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture23; 2 | 3 | import java.util.Scanner; 4 | 5 | public class Sudoku { 6 | public static void main(String[] args) { 7 | Scanner s = new Scanner(System.in); 8 | 9 | int[][] board = { 10 | {5,3,0,0,7,0,0,0,0}, 11 | {6,0,0,1,9,5,0,0,0}, 12 | {0,9,8,0,0,0,0,6,0}, 13 | {8,0,0,0,6,0,0,0,3}, 14 | {4,0,0,8,0,3,0,0,1}, 15 | {7,0,0,0,2,0,0,0,6}, 16 | {0,6,0,0,0,0,2,8,0}, 17 | {0,0,0,4,1,9,0,0,5}, 18 | {0,0,0,0,8,0,0,7,9}}; 19 | 20 | sudoku(board, 0,0); 21 | 22 | } 23 | 24 | public static void sudoku(int[][] board, int row, int col){ 25 | if(row == board.length){ 26 | display(board); 27 | return; 28 | } 29 | if(col == board.length){ 30 | sudoku(board,row+1, 0); 31 | return; 32 | } 33 | if(board[row][col] == 0){ 34 | for (int i = 1; i <= 9; i++) { 35 | if(isSafe(board, row, col, i)){ 36 | board[row][col] = i; 37 | sudoku(board, row, col+1); 38 | board[row][col] = 0; 39 | } 40 | } 41 | }else { 42 | sudoku(board, row, col+1); 43 | } 44 | } 45 | 46 | public static void display(int[][] board) { 47 | for (int i = 0; i < board.length; i++) { 48 | for (int j = 0; j < board.length; j++) { 49 | System.out.print(board[i][j] + " "); 50 | } 51 | System.out.println(); 52 | } 53 | } 54 | 55 | public static boolean isSafe(int[][] board, int row, int col, int n) { 56 | for (int i = 0; i < board.length; i++) { 57 | if(board[row][i] == n){ 58 | return false; 59 | } 60 | } 61 | for (int i = 0; i < board.length; i++) { 62 | if(board[i][col] == n){ 63 | return false; 64 | } 65 | } 66 | int r_block = row/3; 67 | int c_block = col/3; 68 | for (int r = r_block*3; r < (r_block+1)*3; r++) { 69 | for (int c = c_block*3; c < (c_block+1)*3; c++) { 70 | if (board[r][c] == n){ 71 | return false; 72 | } 73 | } 74 | } 75 | return true; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/com/company/Lecture23/ThreadExample.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture23; 2 | 3 | public class ThreadExample extends Thread { 4 | @Override 5 | public void run() { 6 | for (int i = 0; i < 5; i++) { 7 | try{ 8 | Thread.sleep(500); 9 | }catch (InterruptedException e){ 10 | e.printStackTrace(); 11 | } 12 | 13 | System.out.println("printing" + i); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/com/company/Lecture24/JobSequence.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture24; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Comparator; 5 | 6 | public class JobSequence { 7 | 8 | private static class Job{ 9 | private String name; 10 | private int deadline; 11 | private int value; 12 | 13 | public Job(String name, int deadline, int value) { 14 | this.name = name; 15 | this.deadline = deadline; 16 | this.value = value; 17 | } 18 | } 19 | 20 | 21 | public static void main(String[] args) { 22 | ArrayList jobs = new ArrayList<>(); 23 | 24 | String[] job_names = {"a","b","c","d","e"}; 25 | int[] deadlines = {1,3,2,1,2}; 26 | int[] values = {10,80,50,20,40}; 27 | 28 | for (int i = 0; i < job_names.length; i++) { 29 | jobs.add(new Job(job_names[i], deadlines[i], values[i])); 30 | } 31 | 32 | jobs.sort((o1, o2) -> { 33 | if(o1.deadline != o2.deadline){ 34 | return o1.deadline - o2.deadline; 35 | }else { 36 | return o2.value - o1.value; 37 | } 38 | }); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/com/company/Lecture24/LongPallindromeSubseq.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture24; 2 | 3 | public class LongPallindromeSubseq { 4 | public static void main(String[] args) { 5 | System.out.println(lps("aaceaa",0,5)); 6 | } 7 | 8 | public static int lps(String line, int start, int end){ 9 | if(start > end){ 10 | return 0; 11 | } 12 | if(start == end){ 13 | return 1; 14 | } 15 | int res; 16 | if(line.charAt(start) == line.charAt(end)){ 17 | res = 2 + lps(line, start+1,end-1); 18 | }else { 19 | res = Math.max(lps(line,start,end-1), lps(line,start+1,end)); 20 | } 21 | return res; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/com/company/Lecture3/Converter.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture3; 2 | 3 | import java.util.Scanner; 4 | 5 | public class Converter { 6 | public static void main(String[] args) { 7 | 8 | Scanner s = new Scanner(System.in); 9 | 10 | int n = s.nextInt(); 11 | int r1 = s.nextInt(); 12 | int r2 = s.nextInt(); 13 | int res = AnyToAny(n,r1,r2); 14 | System.out.println(res); 15 | 16 | } 17 | 18 | public static int DecToAny ( int dec, int base){ 19 | int any = 0, place = 1; 20 | while( dec > 0){ 21 | int r = dec % base; 22 | any = any + r * place; 23 | place *= 10; 24 | dec /= base; 25 | } 26 | 27 | return any; 28 | } 29 | 30 | public static int AnyToDec ( int any, int base ){ 31 | int val = 0, place = 1; 32 | while( any > 0){ 33 | int r = any % 10; 34 | val = val + r * place; 35 | place *= base; 36 | any /= 10; 37 | } 38 | 39 | return val; 40 | } 41 | 42 | public static int AnyToAny( int n, int r1, int r2){ 43 | int val1 = AnyToDec( n, r1); 44 | int val2 = DecToAny( val1, r2); 45 | 46 | return val2; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/com/company/Lecture3/FnExample.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture3; 2 | 3 | import java.util.Scanner; 4 | 5 | public class FnExample { 6 | public static void main(String[] args) { 7 | Scanner s = new Scanner(System.in); 8 | 9 | int start = s.nextInt(); 10 | int end = s.nextInt(); 11 | int step = s.nextInt(); 12 | 13 | converter(start,end,step); 14 | 15 | } 16 | 17 | public static void converter( int s, int e, int step) 18 | { 19 | while (s <= e){ 20 | float c = (5f/9)* (s - 32); 21 | System.out.println(c); 22 | s += step; 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/com/company/Lecture3/Inverse.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture3; 2 | 3 | import java.util.Scanner; 4 | 5 | public class Inverse { 6 | public static void main(String[] args) { 7 | Scanner s = new Scanner(System.in); 8 | 9 | int n = s.nextInt(); 10 | System.out.println(inverse(n)); 11 | } 12 | 13 | public static int power( int x, int n){ 14 | int res = 1; 15 | 16 | while ( n > 0){ 17 | res *= x; 18 | n--; 19 | } 20 | return res; 21 | } 22 | 23 | public static int inverse ( int n){ 24 | int pos = 1, val, res = 0; 25 | while( n > 0){ 26 | val = n % 10; 27 | res = res + (pos * power( 10, val-1)); 28 | n /= 10; 29 | pos++; 30 | } 31 | return res; 32 | } 33 | 34 | public static boolean mirror ( int num){ 35 | return num ==inverse(num); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/com/company/Lecture3/Main.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture3; 2 | 3 | import javax.sound.midi.Soundbank; 4 | 5 | public class Main { 6 | public static void main(String[] args) { 7 | eat(); 8 | } 9 | 10 | public static void eat(){ 11 | int i = 9; 12 | 13 | System.out.println("Line One"); 14 | System.out.println("Line Two"); 15 | 16 | return; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/com/company/Lecture4/BinToDec.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture4; 2 | 3 | import java.util.Scanner; 4 | 5 | public class BinToDec { 6 | public static void main(String args[]) { 7 | Scanner s = new Scanner(System.in); 8 | 9 | int n = s.nextInt(); 10 | int place = 1; 11 | int r, res = 0; 12 | while (n > 0) { 13 | r = n % 10; 14 | res += r * place; 15 | place *= 2; 16 | n /= 10; 17 | } 18 | System.out.println(res); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/com/company/Lecture4/Count.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture4; 2 | 3 | import java.util.Scanner; 4 | 5 | public class Count { 6 | public static void main(String[] args) { 7 | Scanner s = new Scanner(System.in); 8 | 9 | int n = s.nextInt(); 10 | 11 | int cnt = 0; 12 | while(n > 0){ 13 | int r = n % 10; 14 | if( r == 5){ 15 | cnt++; 16 | } 17 | n/= 10; 18 | } 19 | System.out.println(cnt); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/com/company/Lecture4/DecToBin.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture4; 2 | 3 | import java.util.Scanner; 4 | 5 | public class DecToBin { 6 | public static void main(String[] args) { 7 | Scanner s = new Scanner(System.in); 8 | 9 | int n = s.nextInt(); 10 | int place = 1,res = 0; 11 | 12 | while(n > 0){ 13 | int r = n % 2; 14 | res = res + r*place; 15 | place*=10; 16 | n/= 2; 17 | } 18 | System.out.println(res); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/com/company/Lecture4/Diamond.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture4; 2 | 3 | public class Diamond { 4 | public static void main(String[] args) { 5 | int n = 4; 6 | int r = 1; 7 | int h_mirror = 1; 8 | while(h_mirror <= 2 * n - 1){ 9 | int c = 1; 10 | while(c <= n - r){ 11 | System.out.print(" "); 12 | c++; 13 | } 14 | int v_mirror = 1; 15 | while (v_mirror <= 2 * r - 1){ 16 | System.out.print("* "); 17 | v_mirror++; 18 | } 19 | System.out.println(); 20 | 21 | if(h_mirror < n){ 22 | r++; 23 | }else{ 24 | r--; 25 | } 26 | h_mirror++; 27 | } 28 | } 29 | 30 | } 31 | 32 | -------------------------------------------------------------------------------- /src/com/company/Lecture4/HollowRhombus.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture4; 2 | 3 | import java.util.Scanner; 4 | 5 | public class HollowRhombus { 6 | public static void main(String[] args) { 7 | int n = 4; 8 | int row = 1; 9 | while ( row <= n){ 10 | int sp = 1; 11 | while ( sp <= n-row){ 12 | System.out.print(" "); 13 | sp++; 14 | } 15 | int col = 1; 16 | while ( col <= n){ 17 | if( row == 1 || row == n || col == 1 || col == n) 18 | System.out.print("* "); 19 | else 20 | System.out.print(" "); 21 | col++; 22 | } 23 | System.out.println(); 24 | row++; 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/com/company/Lecture4/Input.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture4; 2 | 3 | import java.util.Scanner; 4 | 5 | public class Input { 6 | public static void main(String[] args) { 7 | Scanner s = new Scanner(System.in); 8 | 9 | int a = s.nextInt(); 10 | 11 | int b = s.nextInt(); 12 | 13 | System.out.println(a); 14 | System.out.println(b); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/com/company/Lecture4/Main.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture4; 2 | 3 | public class Main { 4 | 5 | public static void main(String[] args) { 6 | // write your code here 7 | int n = 4; 8 | int r = 0; 9 | 10 | while(r < n){ 11 | int c = 0; 12 | while(c < n - r){ 13 | System.out.print("*"); 14 | c++; 15 | } 16 | System.out.println(); 17 | r++; 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /src/com/company/Lecture4/OctToBin.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture4; 2 | 3 | import java.util.Scanner; 4 | 5 | public class OctToBin { 6 | public static void main(String[] args) { 7 | Scanner s = new Scanner(System.in); 8 | 9 | int n = s.nextInt(); 10 | int place = 1, val ,res = 0; 11 | 12 | while (n > 0){ 13 | int r = n % 10; 14 | System.out.println(r); 15 | if( r == 0){ 16 | val = 0; 17 | } else if( r == 1){ 18 | val = 1; 19 | } else if( r == 2){ 20 | val = 10; 21 | } else if( r == 3){ 22 | val = 11; 23 | } else if( r == 4){ 24 | val = 100; 25 | } else if( r == 5){ 26 | val = 101; 27 | } else if( r == 6){ 28 | val = 110; 29 | } else{ 30 | val = 111; 31 | } 32 | System.out.println(val); 33 | res = res + val*place; 34 | System.out.println(res); 35 | place *= 1000; 36 | n /= 10; 37 | } 38 | 39 | System.out.println(res); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/com/company/Lecture4/Reverse.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture4; 2 | 3 | import java.util.Scanner; 4 | 5 | public class Reverse { 6 | public static void main(String[] args) { 7 | Scanner s = new Scanner(System.in); 8 | 9 | int n = s.nextInt(); 10 | int num = 0,r; 11 | while (n > 0){ 12 | r = n % 10; 13 | num = num*10 + r; 14 | n /=10; 15 | } 16 | System.out.println(num); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/com/company/Lecture4/Swastik.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture4; 2 | 3 | public class Swastik { 4 | public static void main(String[] args) { 5 | int n = 5; 6 | int r = 0; 7 | while(r < n){ 8 | int c = 0; 9 | while(c < n){ 10 | if ((r == 0 && c >= n/2) || (r == n-1 && c <= n/2) 11 | || (c == 0 && r <= n/2) || (c == n-1 && r >= n/2) 12 | || r == n/2 || c == n/2 ) { 13 | System.out.print("* "); 14 | } else { 15 | System.out.print(" "); 16 | } 17 | c++; 18 | } 19 | System.out.println(); 20 | r++; 21 | } 22 | } 23 | } 24 | 25 | 26 | -------------------------------------------------------------------------------- /src/com/company/Lecture5/ArrayIntro.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture5; 2 | 3 | import java.util.Scanner; 4 | 5 | public class ArrayIntro { 6 | public static void main(String[] args) { 7 | Scanner s = new Scanner(System.in); 8 | // int[] n = new int[10]; 9 | int n = s.nextInt(); 10 | int[] nums = input(n, s); 11 | 12 | int max = maxIndex(nums, 0, 5); 13 | System.out.println(max); 14 | // swap(nums,3,0); 15 | // display(nums); 16 | 17 | } 18 | 19 | 20 | public static void display (int[] nums){ 21 | for (int i = 0; i < nums.length; i++) { 22 | System.out.print(nums[i] + " "); 23 | } 24 | System.out.println(); 25 | } 26 | 27 | public static int[] input (int n, Scanner s){ 28 | int[] nums = new int[n]; 29 | 30 | for (int i = 0; i < n ; i++) { 31 | nums[i] = s.nextInt(); 32 | } 33 | 34 | return nums; 35 | } 36 | 37 | public static void swap(int[] nums, int ind1, int ind2 ){ 38 | int t; 39 | t = nums[ind1]; 40 | nums[ind1] = nums[ind2]; 41 | nums[ind2] = t; 42 | } 43 | 44 | public static int maxIndex (int[] nums, int start, int end){ 45 | int max = start; 46 | for (int i = start; i <= end ; i++) { 47 | if( nums[i] > nums[max]){ 48 | max = i; 49 | } 50 | } 51 | return max; 52 | } 53 | 54 | public static void shift(int[] nums,int end){ 55 | for (int i = 0; i < end ; i++) { 56 | nums[i] = nums[i+1]; 57 | } 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /src/com/company/Lecture5/Main.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture5; 2 | 3 | import java.util.Scanner; 4 | 5 | public class Main { 6 | public static void main(String[] args) { 7 | Scanner s = new Scanner(System.in); 8 | int[] nums = new int[10]; 9 | 10 | System.out.println(); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/com/company/Lecture5/Searching.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture5; 2 | 3 | import java.util.Scanner; 4 | 5 | public class Searching { 6 | public static void main(String[] args) { 7 | Scanner s = new Scanner(System.in); 8 | int[] nums = {23, 54, 78, 34}; 9 | int n = s.nextInt(); 10 | // int ind = linear(nums, n); 11 | int ind = binary(nums, n); 12 | if( ind != -1){ 13 | System.out.println("Number found at Index : " + ind); 14 | } 15 | else{ 16 | System.out.println("Number not found!!"); 17 | } 18 | } 19 | 20 | public static int linear( int[] nums, int target){ 21 | for (int i = 0; i < nums.length; i++) { 22 | if ( nums[i] == target) 23 | return i; 24 | } 25 | return -1; 26 | } 27 | 28 | public static int binary ( int[] nums, int target){ 29 | int start = 0; 30 | int end = nums.length-1; 31 | while ( start <= end ){ 32 | int mid = (start + end)/2; 33 | if ( target == nums[mid]){ 34 | return mid; 35 | } 36 | else if( target < nums[mid]){ 37 | end = mid-1; 38 | } 39 | else { 40 | start = mid+1; 41 | } 42 | } 43 | return -1; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/com/company/Lecture5/Sorting.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture5; 2 | 3 | public class Sorting { 4 | public static void main(String[] args) { 5 | int[] nums = {23,45,56,12,8,73}; 6 | 7 | bubble(nums); 8 | selection(nums); 9 | 10 | ArrayIntro.display(nums); 11 | 12 | } 13 | 14 | public static void bubble( int[] nums ){ 15 | for (int i = 0; i < nums.length; i++) { 16 | for (int j = 0; j < nums.length - 1 - i; j++) { 17 | if( nums[j] > nums[j+1]){ 18 | ArrayIntro.swap(nums, j, j+1); 19 | } 20 | } 21 | } 22 | } 23 | 24 | public static void selection( int[] nums){ 25 | for (int i = 0; i < nums.length ; i++) { 26 | for (int j = 0; j < nums.length - 1 - i; j++) { 27 | int m = ArrayIntro.maxIndex(nums, 0, nums.length-1-i); 28 | 29 | ArrayIntro.swap(nums,m, nums.length-1-i); 30 | } 31 | } 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/com/company/Lecture6/ArrayExamples.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture6; 2 | 3 | import com.company.Lecture5.ArrayIntro; 4 | 5 | import java.util.Arrays; 6 | 7 | public class ArrayExamples { 8 | public static void main(String[] args) { 9 | int[] nums = {4,5,1,3,2,0}; 10 | 11 | // reverse(nums); 12 | nums = inverse(nums); 13 | System.out.println(Arrays.toString(nums)); 14 | } 15 | 16 | public static void reverse ( int[] nums){ 17 | for (int i = 0; i < nums.length/2 ; i++) { 18 | ArrayIntro.swap(nums, i, nums.length - 1 - i); 19 | } 20 | } 21 | 22 | public static int[] inverse ( int[] nums){ 23 | int[] num2 = new int[nums.length]; 24 | for (int i = 0; i < nums.length; i++) { 25 | num2[nums[i]] = i; 26 | } 27 | return num2; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/com/company/Lecture6/ArrayListExamples.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture6; 2 | 3 | import java.util.ArrayList; 4 | 5 | public class ArrayListExamples { 6 | public static void main(String[] args) { 7 | ArrayList list = new ArrayList(); 8 | 9 | list.add(3); 10 | list.add(6); 11 | 12 | System.out.println(list); 13 | 14 | list.set(1, 5); 15 | 16 | System.out.println(list); 17 | 18 | System.out.println(list.get(0)); 19 | 20 | // for (int i = 0; i < list.size(); i++) { 21 | // System.out.println(list.get(i)); 22 | // } 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/com/company/Lecture6/Sorting.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture6; 2 | 3 | import com.company.Lecture5.ArrayIntro; 4 | 5 | public class Sorting { 6 | 7 | public static void main(String[] args) { 8 | int[] nums ={32, 76,12,98,29,20,56}; 9 | insertion(nums); 10 | 11 | ArrayIntro.display(nums); 12 | } 13 | 14 | public static void insertion ( int[] nums){ 15 | for (int i = 0; i < nums.length ; i++) { 16 | for (int j = i; j >=1 ; j--) { 17 | if ( nums[j] < nums[j-1]) { 18 | ArrayIntro.swap(nums, j, j - 1); 19 | }else { 20 | break; 21 | } 22 | } 23 | } 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/com/company/Lecture6/StringBuilderExamples.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture6; 2 | 3 | public class StringBuilderExamples { 4 | public static void main(String[] args) { 5 | 6 | String line = "EktaMishra"; 7 | 8 | System.out.println(toggle(line)); 9 | 10 | // StringBuilder h = new StringBuilder("Hello"); 11 | // 12 | // System.out.println(h); 13 | // for (int i = 0; i < 10000; i++) { 14 | // h .append("a"); 15 | // } 16 | } 17 | 18 | public static String toggle (String line){ 19 | StringBuilder builder = new StringBuilder(); 20 | 21 | for (int i = 0; i < line.length() ; i++) { 22 | int ch = line.charAt(i); 23 | if( ch >= 'a' && ch <= 'z'){ 24 | // ch = ch - 32; 25 | ch = (ch - 'a') + 'A'; 26 | } 27 | else if( ch >= 'A' && ch <= 'Z'){ 28 | // ch = ch + 32; 29 | ch = (ch - 'A') + 'a'; 30 | } 31 | builder.append((char)ch); 32 | } 33 | return builder.toString(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/com/company/Lecture6/StringIntro.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture6; 2 | 3 | public class StringIntro { 4 | public static void main(String[] args) { 5 | String greet = "Welcome"; 6 | String second = "to Coding Blocks"; 7 | String my = "naman"; 8 | String you = "naman"; 9 | String total = greet + 1; 10 | 11 | // System.out.println(my == you); We shouldn't use this 12 | System.out.println(my.equals(you)); 13 | pallindrome(my); 14 | // System.out.println(greet.indexOf("lc")); 15 | System.out.println(second.indexOf("o", 2)); //returns starting index 16 | System.out.println(greet.startsWith("I")); //returns boolean 17 | System.out.println(greet.startsWith("c", 3)); 18 | // String total = greet.concat(second); 19 | 20 | print(total); 21 | 22 | for (int i = 0; i < 5; i++) { 23 | greet = greet.concat(Integer.toString(i)); 24 | } 25 | print(greet); 26 | 27 | // char[] chars = greet.toCharArray(); 28 | // for (int i = 0; i < chars.length; i++) { 29 | // System.out.println(chars[i]); 30 | // } 31 | 32 | // for (int i = 0; i < greet.length(); i++) { 33 | // System.out.println(greet.charAt(i)); 34 | // } 35 | 36 | // System.out.println(greet); 37 | } 38 | 39 | public static void print(String line){ 40 | for (int i = 0; i < line.length(); i++) { 41 | System.out.print(line.charAt(i)); 42 | } 43 | System.out.println(); 44 | } 45 | 46 | public static int pallindrome ( String line){ 47 | for (int i = 0; i < line.length()/2 ; i++) { 48 | if( line.charAt(i) != line.charAt(line.length()-1-i)) { 49 | System.out.println("Not a Pallindrome"); 50 | return 0; 51 | } 52 | } 53 | System.out.println("Pallindrome"); 54 | return 0; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/com/company/Lecture6/SubstringIntro.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture6; 2 | 3 | public class SubstringIntro { 4 | public static void main(String[] args) { 5 | String greet = "Hello"; 6 | // System.out.println(greet.substring(5, 5)); Gives Empty String 7 | 8 | subStrings(greet); 9 | } 10 | 11 | public static void subStrings(String line){ 12 | for (int i = 0; i < line.length(); i++) { 13 | for (int j = i; j < line.length() ; j++) { 14 | System.out.println(line.substring(i,j+1)); 15 | } 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/com/company/Lecture7/Bitwise_Examples.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture7; 2 | 3 | import java.lang.reflect.Array; 4 | import java.util.Arrays; 5 | import java.util.Scanner; 6 | 7 | public class Bitwise_Examples { 8 | public static void main(String[] args) { 9 | Scanner s = new Scanner(System.in); 10 | 11 | String[] any = s.nextLine().trim().split(" "); 12 | int[] nums = new int[any.length]; 13 | for (int i = 0; i < any.length ; i++) { 14 | nums[i] = Integer.parseInt(any[i]); 15 | } 16 | System.out.println(Arrays.toString(nums)); 17 | System.out.println(5 & 11); 18 | System.out.println(5 | 11); 19 | 20 | int[] num2 = {2,1,8,1,8,2}; 21 | int res = oddOcc(num2); 22 | System.out.println(res); 23 | 24 | System.out.println(countOne(15)); 25 | toggle_basic(14); 26 | toggle(14); 27 | System.out.println(power(3,2)); 28 | } 29 | 30 | public static int oddOcc(int[] nums){ 31 | int res = 0; 32 | for (int num : nums) { 33 | res = res ^ num; 34 | } 35 | return res; 36 | } 37 | 38 | public static boolean isOdd( int n){ 39 | return (n & 1) == 1; 40 | //If returns 1 : odd else even. 41 | } 42 | 43 | public static int countOne(int n){ 44 | int cnt = 0; 45 | while(n > 0){ 46 | if((n & 1) == 1) { 47 | cnt++; 48 | } 49 | n = n >>1; 50 | 51 | } 52 | return cnt; 53 | } 54 | 55 | public static void toggle_basic (int n){ 56 | int num = 0,place=1; 57 | while(n>0){ 58 | if((n & 1)==0){ 59 | num = num + place; 60 | } 61 | place *= 2; 62 | n = n >> 1; 63 | } 64 | System.out.println(num); 65 | } 66 | 67 | public static void mul7(int[] nums){ 68 | for (int i = 0; i < nums.length; i++) { 69 | nums[i] = (nums[i] << 3) - nums[i]; 70 | } 71 | } 72 | 73 | public static void toggle(int num){ 74 | int index = 0, t = 0; 75 | while(num > 0){ 76 | int d = (num & 1) ^ 1; 77 | t = t + (d << index); 78 | index++; 79 | num = num >> 1; 80 | } 81 | System.out.println(t); 82 | } 83 | 84 | public static int power(int x, int n){ 85 | int res = 1; 86 | 87 | while ( n > 0){ 88 | if((n&1) == 1){ 89 | res = res * x; 90 | } 91 | x = x*x; 92 | n = n >> 1; 93 | } 94 | return res; 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /src/com/company/Lecture7/BuilderExamples.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture7; 2 | 3 | public class BuilderExamples { 4 | public static void main(String[] args) { 5 | StringBuilder builder = new StringBuilder(); 6 | int[] nums = {1,5,2,9,4}; 7 | builder.append("["); 8 | 9 | for (int i = 0; i < nums.length ; i++) { 10 | builder.append(nums[i]); 11 | if(i < nums.length-1){ 12 | builder.append(", "); 13 | } 14 | } 15 | 16 | builder.append("]"); 17 | 18 | // builder.replace(1, 2,"ab"); 19 | // builder.delete(1,2); 20 | // builder.insert(1, "oo"); 21 | 22 | System.out.println(builder); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/com/company/Lecture7/NthMagic.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture7; 2 | 3 | import java.util.Scanner; 4 | 5 | public class NthMagic { 6 | public static void main(String[] args) { 7 | Scanner s = new Scanner(System.in); 8 | int n = s.nextInt(); 9 | 10 | System.out.println(nthMagical(n)); 11 | } 12 | 13 | public static int nthMagical(int n) { 14 | int res = 0; 15 | int place = 1; 16 | while (n > 0){ 17 | if ((n & 1 ) == 1){ 18 | res = res + (int) Math.pow(5, place); 19 | } 20 | 21 | n = n >> 1; 22 | place++; 23 | } 24 | 25 | return res; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/com/company/Lecture7/Pattern_Practice.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture7; 2 | 3 | import java.util.Scanner; 4 | 5 | public class Pattern_Practice { 6 | public static void main(String[] args) { 7 | Scanner s = new Scanner(System.in); 8 | int n = s.nextInt(); 9 | // diamond(n); 10 | // diamond_out(n); 11 | pascal(n); 12 | } 13 | 14 | public static void diamond(int n){ 15 | int space = n-1; 16 | int star = 1; 17 | for (int i = 0; i < 2*n-1 ; i++) { 18 | for (int j = 0; j <= space; j++) { 19 | System.out.print(" "); 20 | } 21 | 22 | for (int j = 0; j < star; j++) { 23 | System.out.print("* "); 24 | } 25 | if (i < n - 1) { 26 | star -= 1; 27 | space += 2; 28 | } else { 29 | star += 1; 30 | space -= 2; 31 | } 32 | 33 | System.out.println(); 34 | } 35 | } 36 | 37 | public static void diamond_out( int n){ 38 | int space = 0; 39 | int star = n-1; 40 | for (int i = 0; i < 2*n-3 ; i++) { 41 | for (int j = 0; j < star; j++) { 42 | System.out.print("* "); 43 | } 44 | 45 | for (int j = 0; j < space; j++) { 46 | System.out.print(" "); 47 | } 48 | 49 | for (int j = 0; j < star; j++) { 50 | System.out.print("* "); 51 | } 52 | if (i < n - 2) { 53 | star -= 1; 54 | space += 2; 55 | } else { 56 | star += 1; 57 | space -= 2; 58 | } 59 | 60 | System.out.println(); 61 | } 62 | } 63 | 64 | public static void pascal(int num){ 65 | for (int n = 0; n < num ; n++) { 66 | int val = 1; 67 | for (int r = 0; r <= n ; r++) { 68 | System.out.print(val + " "); 69 | val = val * (n-r) / (r+1); 70 | // val = fact(n)/ (fact(r)* fact(n-r)); 71 | } 72 | System.out.println(); 73 | } 74 | } 75 | 76 | public static int fact(int n){ 77 | int acc = 1; 78 | 79 | for (int i = 1; i <= n ; i++) { 80 | acc = acc * i; 81 | } 82 | return acc; 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /src/com/company/Lecture7/RecursionIntro.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture7; 2 | 3 | public class RecursionIntro { 4 | public static void main(String[] args) { 5 | 6 | pd(5); 7 | System.out.println(); 8 | pi(5); 9 | 10 | } 11 | 12 | public static void pd(int n){ 13 | if(n==0){ 14 | return; 15 | } 16 | 17 | System.out.print(n + " "); 18 | pd(n-1); 19 | 20 | } 21 | 22 | public static void pi(int n){ 23 | if(n==0){ 24 | return; 25 | } 26 | 27 | pi(n-1); 28 | System.out.print(n + " "); 29 | 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/com/company/Lecture7/UniqueI.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture7; 2 | 3 | public class UniqueI { 4 | public static void main(String[] args) { 5 | int[] nums = {1,2,5,3,1,5,2}; 6 | 7 | System.out.println(getSingle(nums)); 8 | } 9 | 10 | 11 | private static int getSingle(int[] nums) { 12 | int res = 0; 13 | for (int num : nums) { 14 | res = res ^ num; 15 | } 16 | 17 | return res; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/com/company/Lecture7/UniqueII.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture7; 2 | 3 | import java.util.Scanner; 4 | 5 | public class UniqueII { 6 | public static void main(String[] args) 7 | { 8 | Scanner s = new Scanner(System.in); 9 | int n = s.nextInt(); 10 | int[] arr = new int[n]; 11 | for (int i = 0; i < n; i++) { 12 | arr[i] = s.nextInt(); 13 | } 14 | get2NonRepeatingNos(arr); 15 | } 16 | 17 | public static void get2NonRepeatingNos(int[] arr) 18 | { 19 | int Xor = arr[0], res, i, x = 0, y; 20 | for(i = 1; i < arr.length; i++) { 21 | Xor ^= arr[i]; 22 | } 23 | 24 | res = Xor; 25 | int pos = 0; 26 | while ((Xor & 1) != 1){ 27 | pos++; 28 | Xor = Xor >> 1; 29 | } 30 | 31 | int mask = (1 << pos); 32 | for(int num : arr) { 33 | if ((num & mask) == 1) { 34 | x = x ^ num; 35 | } 36 | } 37 | 38 | y = res ^ x; 39 | System.out.println(x + " " + y); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/com/company/Lecture8/ArrayRecursion.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture8; 2 | 3 | import java.util.Arrays; 4 | 5 | public class ArrayRecursion { 6 | public static void main(String[] args) { 7 | int[] nums = {2,3,7,9,2,8,4,2,0}; 8 | // System.out.println(find(nums, 7,0)); 9 | // int res = findIndex(nums, 7,0); 10 | // if (res != -1){ 11 | // System.out.println(res); 12 | // } 13 | // System.out.println(findSorted(nums,0 )); 14 | // System.out.println(Arrays.toString(allIndex(nums,2,0,0))); 15 | // pattern1(6); 16 | pattern2(5,0,0); 17 | } 18 | public static boolean find(int[] nums, int target, int index){ 19 | if(index == nums.length){ 20 | return false; 21 | } 22 | if(nums[index] == target){ 23 | return true; 24 | } 25 | 26 | return find(nums, target, index+1); 27 | } 28 | 29 | public static int findIndex(int[] nums, int target, int index){ 30 | if(index == nums.length){ 31 | System.out.println("Element not found!!"); 32 | return -1; 33 | } 34 | if(nums[index] == target){ 35 | return index; 36 | } 37 | 38 | return findIndex(nums, target, index+1); 39 | } 40 | 41 | public static boolean findSorted(int[] nums, int index){ 42 | if(index == nums.length - 1){ 43 | return true; 44 | } 45 | if(nums[index] > nums[index+1]){ 46 | return false; 47 | } 48 | 49 | return findSorted(nums,index+1); 50 | } 51 | 52 | public static int[] allIndex(int[] nums, int target, int index, int cnt){ 53 | if(index == nums.length){ 54 | int[] sol = new int[cnt]; 55 | return sol; 56 | } 57 | 58 | if(nums[index] == target){ 59 | int[] sol = allIndex(nums,target,index+1, cnt+1); 60 | sol[cnt] = index; 61 | return sol; 62 | } 63 | 64 | return allIndex(nums,target,index+1,cnt); 65 | } 66 | 67 | public static void pattern1(int n){ 68 | if(n==0){ 69 | return; 70 | } 71 | 72 | linestar(n-1); 73 | System.out.println(); 74 | pattern1(n-1); 75 | 76 | } 77 | 78 | public static void linestar(int n){ 79 | if(n==0){ 80 | return; 81 | } 82 | System.out.print("*"); 83 | linestar(n-1); 84 | } 85 | 86 | public static void pattern2(int n, int row, int col){ 87 | if(n == row){ 88 | return; 89 | } 90 | 91 | if(row == col){ 92 | System.out.println("* "); 93 | pattern2(n,row+1,0); 94 | return; 95 | } 96 | 97 | System.out.print("* "); 98 | pattern2(n,row,col+1); 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /src/com/company/Lecture8/PatternRecursion.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture8; 2 | 3 | import com.company.Lecture5.ArrayIntro; 4 | 5 | import java.lang.reflect.Array; 6 | import java.util.Arrays; 7 | 8 | public class PatternRecursion { 9 | public static void main(String[] args) { 10 | // pattern1(5,0); 11 | pattern2(5,0); 12 | // int[] nums = {2,7,1,0,4,8,3}; 13 | // bubbleSort(nums,nums.length-1,0); 14 | // System.out.println(Arrays.toString(nums)); 15 | } 16 | 17 | public static void pattern1(int row, int col){ 18 | if(row == 0){ 19 | return; 20 | } 21 | if(row == col){ 22 | System.out.println(); 23 | pattern1(row-1,0); 24 | return; 25 | } 26 | System.out.print("*"); 27 | pattern1(row, col+1); 28 | 29 | } 30 | 31 | public static void pattern2(int row, int col){ 32 | if(row == 0){ 33 | return; 34 | } 35 | if(row == col){ 36 | pattern2(row-1,0); 37 | System.out.println(); 38 | return; 39 | } 40 | pattern2(row, col+1); 41 | System.out.print("*"); 42 | } 43 | 44 | public static void bubbleSort(int[] nums, int row, int col){ 45 | if(row == 0){ 46 | return; 47 | } 48 | 49 | if(row == col){ 50 | bubbleSort(nums, row-1, 0); 51 | return; 52 | } 53 | 54 | if(nums[col] > nums[col+1]){ 55 | ArrayIntro.swap(nums, col, col+1); 56 | } 57 | 58 | bubbleSort(nums, row, col+1); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/com/company/Lecture8/RecursionExamples.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture8; 2 | 3 | public class RecursionExamples { 4 | public static void main(String[] args) { 5 | System.out.println("Power : "+ power(3,3)); 6 | System.out.println("factorial : " + factorial(4)); 7 | System.out.println("Fibonacci : " + fibo(7)); 8 | System.out.println("Sum of n numbers : " + sum(3)); 9 | } 10 | 11 | public static int power(int x,int n){ 12 | if(x == 0){ 13 | return 0; 14 | }else if(x == 1){ 15 | return 1; 16 | } 17 | if(n == 0){ 18 | return 1; 19 | } 20 | int res; 21 | res = x * power(x, n-1); 22 | return res; 23 | } 24 | 25 | public static int factorial(int n){ 26 | if(n == 0){ 27 | return 1; 28 | } 29 | 30 | return n * factorial(n-1); 31 | } 32 | 33 | public static int fibo(int n){ 34 | if (n < 2){ 35 | return n; 36 | } 37 | 38 | return fibo(n-1) + fibo(n-2); 39 | } 40 | 41 | public static int sum(int n){ 42 | if (n == 0){ 43 | return 0; 44 | } 45 | return(n + sum(n-1)); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/com/company/Lecture9/Board.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture9; 2 | 3 | import java.util.ArrayList; 4 | 5 | public class Board { 6 | public static void main(String[] args) { 7 | ArrayList list = new ArrayList(); 8 | // board("", 4, 3); 9 | //// System.out.println(countboard("", 4, 3)); 10 | boardList("", 4, 3,list); 11 | System.out.println(list); 12 | } 13 | 14 | public static void board(String proc, int target, int face){ 15 | if(target == 0){ 16 | System.out.println(proc); 17 | return; 18 | } 19 | 20 | for (int i = 1; i <= face && i <= target ; i++) { 21 | board(proc+i, target-i, face); 22 | } 23 | } 24 | 25 | public static void boardList(String proc, int target, int face, ArrayList list){ 26 | if(target == 0){ 27 | list.add(proc); 28 | return; 29 | } 30 | 31 | for (int i = 1; i <= face && i <= target ; i++) { 32 | boardList(proc+i, target-i, face, list); 33 | } 34 | } 35 | 36 | public static int countboard(String proc, int target, int face){ 37 | if(target == 0){ 38 | return 1; 39 | } 40 | 41 | int count = 0,acc = 0; 42 | 43 | for (int i = 1; i <= face && i <= target ; i++) { 44 | acc += countboard(proc+i, target-i, face); 45 | } 46 | count += acc; 47 | return count; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/com/company/Lecture9/CountSort.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture9; 2 | 3 | import java.lang.reflect.Array; 4 | import java.util.Arrays; 5 | 6 | public class CountSort { 7 | public static void main(String[] args) { 8 | int[] nums = {0,1,0,0,1,0,1}; 9 | zeroOneSort(nums); 10 | System.out.println(Arrays.toString(nums)); 11 | } 12 | 13 | public static void zeroOneSort(int[] nums){ 14 | 15 | int zeros = 0; 16 | for (int i = 0; i < nums.length; i++) { 17 | if(nums[i] == 0){ 18 | zeros++; 19 | } 20 | } 21 | 22 | for (int i = 0; i < zeros ; i++) { 23 | nums[i] = 0; 24 | } 25 | 26 | for (int i = zeros; i < nums.length; i++) { 27 | nums[i] = 1; 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/com/company/Lecture9/SubSeq.java: -------------------------------------------------------------------------------- 1 | package com.company.Lecture9; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | public class SubSeq { 7 | public static void main(String[] args) { 8 | String chars = "abc"; 9 | ArrayList list = new ArrayList(); 10 | // subseqList("", chars, list); 11 | System.out.println(subseqlist("", chars)); 12 | System.out.println(list); 13 | // subseq("", chars); 14 | // subseq2("", chars); 15 | // permutation("", chars); 16 | // System.out.println(countsubseq2("", chars)); 17 | } 18 | 19 | public static void subseq(String proc, String unproc){ 20 | if(unproc.isEmpty()){ 21 | System.out.println(proc); 22 | return; 23 | } 24 | 25 | char ch = unproc.charAt(0); 26 | unproc = unproc.substring(1); 27 | 28 | subseq(proc + ch, unproc); 29 | subseq(proc, unproc); 30 | } 31 | 32 | public static void subseqList(String proc, String unproc, ArrayList list){ 33 | if(unproc.isEmpty()){ 34 | if(!proc.isEmpty()){ 35 | list.add(proc); 36 | } 37 | return; 38 | } 39 | 40 | char ch = unproc.charAt(0); 41 | unproc = unproc.substring(1); 42 | 43 | subseqList(proc + ch, unproc, list); 44 | subseqList(proc, unproc, list); 45 | } 46 | 47 | 48 | public static void subseq2(String proc, String unproc){ 49 | if(unproc.isEmpty()){ 50 | System.out.println(proc); 51 | return; 52 | } 53 | 54 | char ch = unproc.charAt(0); 55 | unproc = unproc.substring(1); 56 | 57 | subseq2(proc + ch, unproc); 58 | subseq2(proc + (int)ch, unproc); 59 | subseq2(proc, unproc); 60 | } 61 | 62 | public static List subseqlist(String proc, String unproc){ 63 | if(unproc.isEmpty()){ 64 | List list = new ArrayList<>(); 65 | list.add(proc); 66 | return list; 67 | } 68 | 69 | List res = new ArrayList<>(); 70 | char ch = unproc.charAt(0); 71 | unproc = unproc.substring(1); 72 | 73 | res.addAll(subseqlist(proc + ch, unproc)); 74 | res.addAll(subseqlist(proc, unproc)); 75 | 76 | return res; 77 | } 78 | 79 | public static int countsubseq2(String proc, String unproc){ 80 | if(unproc.isEmpty()){ 81 | return 1; 82 | } 83 | 84 | char ch = unproc.charAt(0); 85 | unproc = unproc.substring(1); 86 | 87 | int count = 0; 88 | 89 | count += countsubseq2(proc + ch, unproc); 90 | count += countsubseq2(proc + (int)ch, unproc); 91 | count += countsubseq2(proc, unproc); 92 | 93 | return count; 94 | } 95 | 96 | public static void permutation(String proc, String unproc){ 97 | if(unproc.isEmpty()){ 98 | System.out.println(proc); 99 | return; 100 | } 101 | 102 | char ch = unproc.charAt(0); 103 | unproc = unproc.substring(1); 104 | 105 | for (int i = 0; i <= proc.length() ; i++) { 106 | String first = proc.substring(0,i); 107 | String second = proc.substring(i); 108 | 109 | permutation(first + ch + second, unproc); 110 | } 111 | 112 | } 113 | 114 | } 115 | 116 | 117 | --------------------------------------------------------------------------------