This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <vector> | |
#include <stdio.h> | |
#include <cmath> | |
// Merge function | |
void merge(std::vector<int>& target, int left, int mid, int right){ | |
// Sizes | |
int n1 = mid - left + 1; | |
int n2 = right - mid; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdint.h> | |
#include <stdbool.h> | |
#include <stdlib.h> | |
// Ring buffer typedef | |
typedef struct{ | |
volatile uint8_t *buffer; | |
volatile uint16_t head; | |
volatile uint16_t tail; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# A very naive implementation of Dijkstra's algorithm in O(nm) | |
# computational time, where n is the number of nodes and m is | |
# the number of edges. This can be improved to O(m+nlogn) with | |
# a min-heap. | |
# It takes a weighted adjacency list representation of a graph | |
# as input. We assume that all labels can be uniquely identified | |
# in the set {1,2,..,n}, where n is the second parameter. | |
# The output is a dictionary containing the minimum distance from | |
# source_node to every other node in the graph. If node_t is | |
# passed, then the algorithm terminates early and only the |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# A simple implementation of the Kosaraju's algorithm to find the strongly | |
# connected components of a graph. It takes a graph represented as an edge | |
# list as input, which is preferred since it is easily reversible. We are | |
# also assuming that nodes are labeled from 1 to n in the input graph. | |
# The output is is a dictionary containing 'node':'leader_node' pairs. | |
import sys | |
sys.setrecursionlimit(100000) # we will use deep recursions |