Skip to content

Instantly share code, notes, and snippets.

View EssamWisam's full-sized avatar

Essam EssamWisam

View GitHub Profile
@EssamWisam
EssamWisam / shortest.ipynb
Created April 27, 2025 17:57
Shortest Paths
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
def dfs(graph, start):
"""
Perform Depth-First Search (DFS) on a graph starting from a given node.
Args:
graph: Dictionary representing the adjacency list of the graph
start: Starting node for DFS
Returns:
Dictionary with discovery and finish times for each node
@EssamWisam
EssamWisam / Dynamic.c
Last active April 8, 2025 21:27
Dynamic Array
#include <stdio.h>
#include <stdlib.h>
// Define a structure for DynamicArray
typedef struct {
int *data; // Pointer to the array of elements
int size; // Number of elements currently in the array
int capacity; // Total capacity (allocated memory) of the array
} DynamicArray;
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define LOAD_FACTOR_UPPER 1.0
#define LOAD_FACTOR_LOWER 0.25
#define INITIAL_CAPACITY 8
// ------------------- Node & Doubly Linked List -------------------
typedef struct Node {
#include <iostream>
#include <stdexcept>
// Fixed sizes for each data structure
#define STACK_SIZE 5
#define QUEUE_SIZE 5
#define LIST_SIZE 10
// --------------------------
// Stack Class Implementation
@EssamWisam
EssamWisam / quick.ipynb
Created February 26, 2025 05:00
Quick Sort Hands on 6
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
import torch
import numpy as np
import matplotlib.pyplot as plt
# Imagine this is loss function
def polynomial(w):
return (w**5 - 3*w**4 + 2*w**3 + w**2 - w + 1)/100000
# Imagine this is loss function multiplied by 10000
def scaled_polynomial(w):
class MinHeap:
def __init__(self, data=None):
"""
Initialize a Min Heap.
:param data: Optional list to build the heap from.
"""
self.heap = data if data else []
if data:
self.build_min_heap()
@EssamWisam
EssamWisam / Fib.py
Created February 12, 2025 05:39
Algorithms Hands-on
def fib(n, depth=0):
indent = " " * depth # Indentation for better visualization
print(f"{indent}fib({n}) called")
if n == 0:
print(f"{indent}Returning 0")
return 0
if n == 1:
print(f"{indent}Returning 1")
return 1