This file contains 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
BucketSort(numbers, numbersSize, bucketCount) { | |
if (numbersSize < 1) | |
return | |
buckets = Create list of bucketCount buckets | |
// Find the maximum value | |
maxValue = numbers[0] | |
for (i = 1; i < numbersSize; i++) { | |
if (numbers[i] > maxValue) |
This file contains 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
BSTInsert(tree, node) { | |
if (tree->root is null) | |
tree->root = node | |
node->left = null | |
node->right = null | |
else | |
cur = tree->root | |
while (cur is not null) | |
if (node->key < cur->key) | |
if (cur->left is null) |
This file contains 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
BSTSearch(tree, key) { | |
cur = tree->root | |
while (cur is not null) | |
if (key == cur->key) | |
return cur // Found | |
else if (key < cur->key) | |
cur = cur->left | |
else |
This file contains 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
InsertionSortInterleaved(numbers, numbersSize, startIndex, gap) { | |
i = 0 | |
j = 0 | |
temp = 0 // Temporary variable for swap | |
for (i = startIndex + gap; i < numbersSize; i = i + gap) { | |
j = i | |
while (j - gap >= startIndex && numbers[j] < numbers[j - gap]) { | |
temp = numbers[j] | |
numbers[j] = numbers[j - gap] |
This file contains 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
InsertionSort(numbers, numbersSize) { | |
i = 0 | |
j = 0 | |
temp = 0 // Temporary variable for swap | |
for (i = 1; i < numbersSize; ++i) { | |
j = i | |
// Insert numbers[i] into sorted part | |
// stopping once numbers[i] in correct position | |
while (j > 0 && numbers[j] < numbers[j - 1]) { |
This file contains 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
SelectionSort(numbers, numbersSize) { | |
i = 0 | |
j = 0 | |
indexSmallest = 0 | |
temp = 0 // Temporary variable for swap | |
for (i = 0; i < numbersSize - 1; ++i) { | |
// Find index of smallest remaining element | |
indexSmallest = i |
This file contains 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
Partition(numbers, lowIndex, highIndex) { | |
// Pick middle element as pivot | |
midpoint = lowIndex + (highIndex - lowIndex) / 2 | |
pivot = numbers[midpoint] | |
done = false | |
while (!done) { | |
// Increment lowIndex while numbers[lowIndex] < pivot | |
while (numbers[lowIndex] < pivot) { | |
lowIndex += 1 |
This file contains 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
BinarySearch(numbers, low, high, key) { | |
if (low > high) | |
return -1 | |
mid = (low + high) / 2 | |
if (numbers[mid] < key) { | |
return BinarySearch(numbers, mid + 1, high, key) | |
} | |
else if (numbers[mid] > key) { | |
return BinarySearch(numbers, low, mid - 1, key) |
This file contains 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
## O(1) Constant | |
```py | |
FindMin(x, y) { | |
if (x < y) { | |
return x | |
} | |
else { | |
return y | |
} |
This file contains 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
/** | |
* Outputs a modified comment markup. | |
* | |
* | |
* @see wp_list_comments() | |
* | |
* @param WP_Comment $comment Comment to display. | |
* @param int $depth Depth of the current comment. | |
* @param array $args An array of arguments. |
NewerOlder