Skip to content

Commit

Permalink
Substring, searching, queue, stack, linked list and bunch morw
Browse files Browse the repository at this point in the history
  • Loading branch information
sangaryousmane committed Dec 11, 2023
1 parent 97b7848 commit 622cc4d
Show file tree
Hide file tree
Showing 19 changed files with 828 additions and 45 deletions.
57 changes: 57 additions & 0 deletions src/DevOps/k8s
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
Kubernetes is developed and originated by Google, a solution for Borg

K8s - for containerization
- Containers are ephemeral in nature, meaning they're short lived. Dies anytime.

Problems with Docker
- Single Daemon or host nature
- Docker fail with Auto-healing, which happens when containers restart without human interaction
- Docker doesn't scale automatically or balance load(auto-scaling)
- Docker-O, bridge networking
- Docker doesn't provide any enterprise support
For an application to be enterprise ready, it should contains:
Load balancer, Firewall, API gateway, Auto healing and Auto scaling,
SSH, distributed system, Circuit breaker, Messaging, Streaming

That's why we need Kubernetes, it solves countless of problems presented by Docker

k8s Bring aboard the following:
1. Replication Controller or Replica Set
2. k8s heavily depends on yaml file(manifest file)
3. HPA(Horizontal Port Auto-Scaler)
4. Solve the problem of auto-healing and auto-scaling
5. If for some reasons your container is going down, docker will need you to manually
check the container status and the developer will have to manually restart.
In the case of k8s, containers immediately recreate new containers even before
the container goes down.
- Master, worker and slave node

7. Ingress

K8s Architecture
The simplest thing in Docker is Container and the simplest thing in k8s is Pod
- The container runtime in Docker is called Docker strim
- k8s supports Cri-O containerd, Docker strim and other container runtimes
- kube-proxy provides networking, IP addressing and default load balancing capability
- Container Runtime is responsible for running the containers
- Kubelet is responsible for the creation and maintenance of pods
It is responsible for ensuring that containers are running in a pod.

k8s Platform
- Development environments: KPS, Minikube, Micro8Ks, K3S, KanD

Linux Distribution
- Red Hat, CentOS, Amazon Linux, Kali Linux, Ubuntu

K8s Distribution
- Amazon Elastic Kubernetes Service (EKS)
- Google Kubernetes Engine (GKE)
- Azure Kubernetes Service (AKS)
- DigitalOcean Kubernetes
- K3s , Minikube, KubeSphere, Pharos, Tanzu, Ranctier

K8s Installation
- Kops(kubernetes operation), kubeadm(kubernetes administration)
- minikube start --memory=4096 --driver=virtualbox
- minikube delete
- kubectl cheat-sheet
4 changes: 2 additions & 2 deletions src/DevOps/play.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# Languages
- Python
- Java
Expand All @@ -12,7 +11,7 @@ cities:
- Wuhan

# Write multiple lines as single line
mimic: >
mimic: >
sldndnndndnd
dnnfndnd
mdndnnd
Expand All @@ -28,3 +27,4 @@ octal: !!int 01978
username: !!null Null



10 changes: 10 additions & 0 deletions src/DevOps/pod.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: v1
kind: Pod
metadata:
name: nginx-pod
spec:
containers:
- name: nginx
image: nginx:latest
ports:
- containerPort: 80
8 changes: 8 additions & 0 deletions src/DevOps/table
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Experiment | Dataset | Preprocessing | Model Architecture | Training Duration | Test Accuracy | Precision | Recall | F1 Score |
|------------|------------------|------------------------------------|-----------------------------------------|-------------------|---------------|-----------|--------|----------|
| Experiment 1 | ImageNet | Resize to (224x224), Normalize | SGH-CNN (as described) | 12 hours | 0.85 | 0.86 | 0.84 | 0.85 |
| Experiment 2 | CIFAR-10 | Resize to (32x32), Augmentation, Normalize | SGH-CNN with additional CNN layers | 8 hours | 0.78 | 0.79 | 0.77 | 0.78 |
| Experiment 3 | MNIST | Resize to (28x28), Normalize | SGH-CNN with dropout layers | 6 hours | 0.96 | 0.97 | 0.95 | 0.96 |
| Experiment 4 | Fashion MNIST | Resize to (28x28), Normalize | SGH-CNN with batch normalization | 7 hours | 0.91 | 0.92 | 0.90 | 0.91 |
| Experiment 5 | Stanford Dogs | Resize to (224x224), Normalize | SGH-CNN with transfer learning (ResNet50) | 15 hours | 0.89 | 0.90 | 0.88 | 0.89 |
| Experiment 6 | Flowers | Resize to (224x224), Normalize | SGH-CNN with increased SGH resolution | 10 hours | 0.87 | 0.88 | 0.86 | 0.87 |
137 changes: 137 additions & 0 deletions src/advance/Heaps.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,141 @@
package advance;

import java.util.ArrayList;
import java.util.List;

/**
* Heap data structure is a complete binary tree that satisfies the heap property, where any given node is
* <p>
* always greater than its child node/s and the key of the root node is the largest among all other nodes.
* This property is also called max heap property.
* always smaller than the child node/s and the key of the root node is the smallest among all other nodes.
* This property is also called min heap property.
* This type of data structure is also called a binary heap.
* <p>
* Heapify is the process of creating a heap data structure from a binary tree.
* It is used to create a Min-Heap or a Max-Heap.
* <p>
* Peek operation returns the maximum element from Max Heap or minimum element from Min Heap without deleting the node.
* <p>
* Heap Data Structure Applications
* Heap is used while implementing a priority queue.
* Dijkstra's Algorithm
* Heap Sort
* <p>
* The index of a child element divide by 2 is equal to its parent's index/2
* Index of the root node is 1
* Parent = (i - 1) / 2
* Left = ((2 * i) + 1)
* Right = ((2 * i) + 2)
* <p>
* The value of a given node has to be less than all of its children
* O(log(n)) for insertion
* Heap sort - O(Nlog(N))
*/
public class Heaps {

public static void main(String[] args) throws Exception {
Heap<Integer> heap = new Heap<>();
heap.insert(34);
heap.insert(45);
heap.insert(22);
heap.insert(89);
heap.insert(76);
System.out.println(heap.heapSort());
}
}

class Heap<T extends Comparable<T>> {

private ArrayList<T> items;

public Heap() {
this.items = new ArrayList<>();
}

public void swap(int first, int second) {
T temp = items.get(first);
items.set(first, items.get(second));
items.set(second, temp);
}

public int parent(int index) {
return (index - 1) / 2;
}

public int right(int index) {
return index * 2 + 2; // Gives the right side
}

public int left(int index) {
return index * 2 + 1; // Gives the left side
}

public void insert(T value) {
items.add(value);
upheap(items.size() - 1);
}

// Going up the heap
private void upheap(int index) {
if (index == 0) return;

int parent = parent(index);

// Swap if the current item is smaller than parent
if (items.get(index).compareTo(items.get(parent)) < 0) {
swap(index, parent);
upheap(parent); // Call the parent element
}
}

// Remove the smallest element
public T remove() throws Exception {
if (items.isEmpty())
throw new Exception("Removing from an empty list");

T temp = items.get(0);
T lastElement = items.remove(items.size() - 1);
if (!items.isEmpty()) {
items.set(0, lastElement);
downHeap(0);
}
return temp;
}

// O(log(N))
private void downHeap(int index) {
int min = index;
int left = left(index);
int right = right(index);

// if the left element is the minimum element
if (left < items.size() && items.get(min)
.compareTo(items.get(left)) > 0) {
min = left;
}

// If the right element is the minimum element
if (right < items.size() && items.get(min).compareTo(items.get(right)) > 0) {
min = right;
}
// Swap if the minimum element isn't equal the index.
if (min != index) {
swap(min, index);
downHeap(min); // Go downwards
}
}

public ArrayList<T> heapSort() throws Exception{
ArrayList<T> data=new ArrayList<>();
while (!items.isEmpty()) {
data.add(this.remove());
}
return data;
}

// Construct a max-heap from an unsorted array
public void maxHeapUnsorted(){

}
}
91 changes: 83 additions & 8 deletions src/advance/WorkingWithStrings.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package advance;


import java.io.File;
import java.math.BigInteger;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -79,7 +81,7 @@ public static StringBuffer playWithBuffer(String word) {

public static void playWithFile() {
File file = new File("advance/out.txt");
System.out.println(file.getPath());
System.out.println(file.getParentFile());
System.out.println();
}

Expand Down Expand Up @@ -143,6 +145,7 @@ public static int baseballGame(String[] operations) {
return sum;
}

// O(n)
// https://leetcode.com/problems/valid-parentheses/description/
public static boolean isValid(String s) {

Expand All @@ -161,6 +164,21 @@ else if (stack.isEmpty() || stack.pop() != chr)
return stack.isEmpty();
}

// https://leetcode.com/problems/minimum-add-to-make-parentheses-valid/description/
public int minAddToMakeValid(String s) {
Stack<Character> stack = new Stack<>();
for (char chr: s.toCharArray()){
if (chr == ')')
if(!stack.isEmpty() && stack.peek() == '(')
stack.pop();
else
stack.push(chr);
else
stack.push(chr);
}
return stack.size();
}

// https://leetcode.com/problems/1-bit-and-2-bit-characters/description/
public boolean isOneBitCharacter(int[] bits) {
int i = 0, end = bits.length - 1;
Expand All @@ -173,7 +191,7 @@ public boolean isOneBitCharacter(int[] bits) {
}

// https://leetcode.com/problems/a-number-after-a-double-reversal/description/
public boolean isSameAfterReversals(int num) {
public static boolean isSameAfterReversals(int num) {
return num <= 9 && num % 10 != 0;
}

Expand All @@ -187,18 +205,75 @@ public int accountBalanceAfterPurchase(int purchaseAmount) {
}

// https://leetcode.com/problems/integer-to-roman/description/
public String intToRoman(int num){
String[] ones = {"","I","II","III","IV","V","VI","VII","VIII","IX"};
String[] tens = {"","X","XX","XXX","XL","L","LX","LXX","LXXX","XC"};
String[] hrns = {"","C","CC","CCC","CD","D","DC","DCC","DCCC","CM"};
String[] ths ={"","M","MM","MMM"};
public String intToRoman(int num) {
String[] ones = {"", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"};
String[] tens = {"", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"};
String[] hrns = {"", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM"};
String[] ths = {"", "M", "MM", "MMM"};
return ths[num / 1000] +
hrns[(num % 1000) / 100] +
tens[(num % 100) / 10] +
ones[num % 10];
}

public static void main(String[] args) {
System.out.println(101 % 9);
BigInteger a = new BigInteger("4");
BigInteger b = new BigInteger("5");


}

private static void moreCollections() {
List<String> data = Arrays.asList("ab", "bc", "cd", "ab", "bc", "cd");
Set<String> names = new HashSet<>(data);
SortedSet<String> names1 = new TreeSet<>(data);
Set<String> names2 = new LinkedHashSet<>(data);
Map<String, Boolean> names3 = new TreeMap<>();
Map<String, Boolean> names4 = new LinkedHashMap<>();
Map<String, Boolean> names5 = new HashMap<>(10);

names5.put("Java", true);
names5.put("Python", true);
names5.put("JS", true);
names5.put("GO", false);

HashMap<String, Boolean> names6 = new HashMap<>();

List<String> unModify = Collections.unmodifiableList(data);
// unModify.add("Hello"); // Can't be modify
unModify.forEach(System.out::println);

List<String> anEmptyList = Collections.emptyList();
Map<Integer, Date> anEmptyMap = Collections.emptyMap();
Set<Number> anEmptySet = Collections.emptySet();
// anEmptyList.addAll(data); // Can't modify mutable collections
System.out.println(anEmptyList);
NavigableSet<Integer> desc = new TreeSet<>();
desc.add(4);
desc.add(10);
desc.add(6);
desc.add(7);
System.out.println(desc);
System.out.println("Floor:" + desc.floor(8));
System.out.println("Ceiling:" + desc.ceiling(9));
System.out.println("Lower:" + desc.lower(6));
System.out.println("Higher:" + desc.higher(6));
}

private static void removeElementsInAList() {
// String[] arr = new String[] {"str1", "str2", "str3"};
// Stream<String> stream = Arrays.stream(arr);
// stream.forEach(System.out::println)

List<String> fruits = new ArrayList<>();
fruits.add("Apple");
fruits.add("Banana");
fruits.add("Strawberry");

// System.out.println(fruits.stream().filter((f)->
// !"Banana".equals(f)).toList());
fruits.removeIf("Banana"::equals);
fruits.forEach(System.out::println);
}
}

Expand Down
Loading

0 comments on commit 622cc4d

Please sign in to comment.