Simulated Annealing: A Probabilistic Optimization Technique
Simulated Annealing (SA) is a probabilistic optimization algorithm inspired by the physical annealing process in metallurgy.
The Physical Annealing Process
Annealing involves heating a material to a specific temperature and then cooling it down gradually. During this process, the internal energy of crystalline molecules tends to decrease. The m ...
Posted on Sun, 26 Jul 2026 17:00:01 +0000 by name1090
Computing the Top Element of a Median Pyramid from Base Permutation
Problem Overview
A pyramid consists of N levels numbered from top (level 1) to bottom (level N). Each level i contains exactly 2*i - 1 cells arranged in a centered row. The bottommost row (level N) holds a permutation of integers from 1 to 2*N - 1. Values in upper layers are derived by taking the median of three values directly beneath each cel ...
Posted on Sun, 26 Jul 2026 16:12:28 +0000 by raptor1120
Identifying a Valid Row Subset in a Binary Matrix via Bitmasking
In a binary matrix of size m x n, a subset of rows is considered "good" if, for every column, the sum of the elements in that column does not exceed half the size of the subset. Formally, if the subset conntains k rows, the sum of each column must be less than or equal to floor(k / 2). The goal is to return the indices of such a subse ...
Posted on Thu, 16 Jul 2026 16:05:53 +0000 by jsinker
A Comprehensive Guide to Scoring in Competitive Programming
The Pragmatic Guide to Maximizing Scores in Informatics Contests
In competitive programming, the prevailing wisdom often emphasizes rigorous training and mastering advanced algorithms. However, for those who are still developing their technical foundation, "cheating"—or more accurately, strategic scoring—is an essential survival skill ...
Posted on Wed, 08 Jul 2026 16:30:47 +0000 by 2oMst
Efficient Embedded Programming Techniques
Calculating Sturcture Member Size
#include <stdio.h>
// Get size of struct member
#define MEMBER_SIZE(type, member) sizeof(((type*)0)->member)
// Get offset of struct member
#define MEMBER_OFFSET(type, member) ((size_t)(&(((type*)0)->member)))
typedef struct {
char x;
char y;
char z;
} coord_t;
typedef struct {
...
Posted on Thu, 02 Jul 2026 16:07:32 +0000 by Syranide
Essential PyTorch Code Snippets for Deep Learning
Tensor Creaiton and Initialization
Basic Tensor Operations
import torch
# Create tensor from list
data_tensor = torch.tensor([1, 2, 3], dtype=torch.float32)
# Create tensor with random values (uniform distribution)
rand_tensor = torch.rand(2, 3)
# Create tensor with normal distribution values
normal_tensor = torch.randn(3, 4)
# Create tenso ...
Posted on Wed, 01 Jul 2026 17:53:53 +0000 by blintas
Dynamic Programming Techniques for Knapsack Problems
0/1 Knapsack
Given N items and a knapsack with capacity V, each item can only be selected once. Item i has volume v[i] and value w[i]. Determine which items to select to maximize total value without exceeding the knapsack's volume.
Constraints:
0 < N, V ≤ 1000
0 < v[i], w[i] ≤ 1000
Time Complexity: O(N × V)
int n, m;
int f[100010], w[10 ...
Posted on Mon, 29 Jun 2026 17:26:05 +0000 by Duxie
Optimizing Salesman Route with Greedy Approach
This document outlines a greedy strategy for a sales optimization problem.
Let's consider the sample input:
6
1 2 3 4 5 6
4 2 3 5 3 1
Assume the current location is at point X = 1. We define an array F, where F[i] represents the additional contribtuion to the total answer by visiting user a[i] without any detours. ans will store the cumulative ...
Posted on Sat, 27 Jun 2026 17:53:43 +0000 by MadTechie
High-Performance Multi-Pattern Searching in Python Using ESMRE
The esmre library offers an efficient solution for processing large sets of regular expressions or multi-pattern searches within text data. By leveraging the Aho-Corasick automaton algorithm, it significantly reduces the computational overhead compared to iterating through individual regex patterns.
Installation
Install the package directly via ...
Posted on Sat, 27 Jun 2026 17:23:22 +0000 by cyandi_man
Comprehensive Guide to Search Algorithms in Computer Science
Depth-First Search (DFS)
DFS explores as far as possible along each branch before backtracking. It's implemented using recursion or a stack.
def dfs(graph, node, visited):
if node not in visited:
visited.add(node)
for neighbor in graph[node]:
dfs(graph, neighbor, visited)
Applications
Maze Solving: DFS can find ...
Posted on Fri, 26 Jun 2026 17:06:15 +0000 by ericw