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 fast bottom up natural mergesort | |
A full description of the algorithm can be found on | |
http://www.maxgcoding.com/queue-mergesort-a-comparison-optimal-bottom-up-sort-for-linked-lists/ | |
(C) 2023 Max Goren | |
Permission is hereby granted, free of charge, to any person obtaining a copy of this | |
software and associated documentation files (the “Software”), to deal in the Software |
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
/* modest though definite gains over the "text book" implementation | |
of selection sort. Unfortunately this discovery was overshadowed | |
by the original authors aloofness. */ | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <time.h> | |
void optimizedSelectionSort(int array[], int array_length) { | |
int current_position, largest_value, comparison_value; |
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 <stdlib.h> | |
#include <math.h> | |
#include <time.h> | |
#define CUTOFF 16 | |
void sorterQ(int * b, unsigned long a) { | |
unsigned long c = a - 1; | |
unsigned long d = 0; | |
unsigned long e; |
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 <stdlib.h> | |
#include <time.h> | |
void sorterQ(unsigned long a, int * b) { | |
unsigned long c = a - 1; | |
unsigned long d = 0; | |
unsigned long e; | |
int f; |
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 <stdlib.h> | |
#include <time.h> | |
void sorterQ(unsigned long a, int * b) { | |
unsigned long c = a; | |
unsigned long d = 0; | |
unsigned long e; | |
int f; |
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 <iostream> | |
#include <chrono> | |
using namespace std; | |
void sorterQ(unsigned long a, int * b) { | |
unsigned long c = a; | |
unsigned long d = 0; | |
unsigned long e; | |
int f; |
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
/* | |
This highlights the problems with big O notation. This algorithm is | |
a naiive mergesort implementation. When analyzed its clear to see it is O(nlogn) | |
however, this implementation takesd over 5 seconds to sort 2.5m int's where | |
a well done implementation can do it in 1/10th the time. | |
*/ | |
vector<int> merge(vector<int>& a, vector<int>& b) { | |
int i = 0, j = 0; | |
vector<int> res; |
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
ListNode* partition(ListNode* head, int x) { | |
if (head == nullptr || head->next == nullptr) | |
return head; | |
ListNode l; ListNode *a = &l; | |
ListNode r; ListNode *b = &r; | |
ListNode* p = head; | |
while (p != nullptr) { | |
ListNode* t = p; | |
p = p->next; | |
t->next = nullptr; |
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
template <class T, class T2> | |
class AVLTree { | |
private: | |
struct node { | |
T key; | |
T2 value; | |
int height; | |
node* left; | |
node* right; | |
node* parent; |
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
import java.util.List; | |
import java.util.ArrayList; | |
public class SuffixArray { | |
private static class Suffix { | |
public int index; | |
public String suffix; | |
Suffix(int i, String s) { | |
this.index = i; | |
this.suffix = s; |