Skip to content

Commit

Permalink
Add name to articles
Browse files Browse the repository at this point in the history
I'm doing this so that other contributors will follow the example and add their names to their explanations, to get credit for their work.
  • Loading branch information
hollance committed Jan 28, 2016
1 parent 8bca788 commit 5f071fd
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Array2D/README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,5 @@ let myCookie = cookies[column, row]
Internally, `Array2D` uses a single one-dimensional array to store the data. The index of an object in that array is given by `(row x numberOfColumns) + column`. But as a user of `Array2D` you don't have to worry about that; you only have to think in terms of "column" and "row", and let `Array2D` figure out the details for you. That's the advantage of wrapping primitive types into a wrapper class or struct.

And that's all there is to it.

*Written by Matthijs Hollemans*
2 changes: 2 additions & 0 deletions Boyer-Moore/README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,5 @@ The closer a character is to the end of the pattern, the smaller the skip amount
A caveat: If the search pattern consists of only a few characters, it's faster to do a brute-force search. There's a trade-off between the time it takes to build the skip table and doing brute-force for short patterns.

Credits: This code is based on the article ["Faster String Searches" by Costas Menico](http://www.drdobbs.com/database/faster-string-searches/184408171) from Dr Dobb's magazine, July 1989 -- Yes, 1989! Sometimes it's useful to keep those old magazines around.

*Written by Matthijs Hollemans*
2 changes: 2 additions & 0 deletions Fixed Size Array/README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,5 @@ var a = FixedSizeArray(maxSize: 10, defaultValue: 0)
```

Note that `removeAtIndex()` overwrites the last element with this `defaultValue` to clean up the "junk" object that gets left behind. Normally it wouldn't matter to leave that duplicate object in the array, but if it's a class or a struct it may have strong references to other objects and it's good boyscout practice to zero those out.

*Written by Matthijs Hollemans*
2 changes: 2 additions & 0 deletions Insertion Sort/README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -231,3 +231,5 @@ I did a quick test comparing our `insertionSort()` with Swift's built-in `sort()
### See also

See also [Wikipedia](https://en.wikipedia.org/wiki/Insertion_sort).

*Written by Matthijs Hollemans*
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2016 Matthijs Hollemans
Copyright (c) 2016 Matthijs Hollemans and contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 2 additions & 0 deletions Queue/README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,5 @@ However, to dequeue we remove the element from the beginning of the array. This
More efficient implementations would use a linked list, a circular buffer, or a heap. (I might add an example of this later.)

Variations on this theme are [deque](../Deque/), a double-ended queue where you can enqueue and dequeue at both ends, and [priority queue](../Priority Queue/), a sorted queue where the "most important" item is always at the front.

*Written by Matthijs Hollemans*
2 changes: 2 additions & 0 deletions Selection Sort/README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,5 @@ Selection sort is easy to understand but it performs quite badly, **O(n^2)**. It
### See also

See also [Wikipedia](https://en.wikipedia.org/wiki/Selection_sort).

*Written by Matthijs Hollemans*
2 changes: 2 additions & 0 deletions Stack/README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,5 @@ public struct Stack<T> {
Notice that a push puts the new element at the end of the array, not the beginning. Inserting at the beginning of an array is expensive, an **O(n)** operation, because it requires all existing array elements to be shifted in memory. Adding at the end is **O(1)**; it always takes the same amount of time, regardless of the size of the array.

Fun fact about stacks: each time you call a function or a method, the return address is placed on a stack by the CPU. When the function ends, the CPU uses that return address to jump back to the caller. That's why if you call too many functions -- for example in a recursive function that never ends -- you get a so-called "stack overflow" as the CPU stack is out of space.

*Written by Matthijs Hollemans*
2 changes: 2 additions & 0 deletions Two-Sum Problem/README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,5 @@ And finally, we have the answer: `12 + 21 = 33`. Yay!
It's possible, of course, that there are no values for `a[i] + a[j]` that sum to `k`. In that case, eventually `i` and `j` will point at the same number. Then we can conclude that no answer exists and we return `nil`.

I'm quite enamored by this little algorithm. It shows that with some basic preprocessing on the input data -- sorting it from low to high -- you can turn a tricky problem into a very simple and beautiful algorithm.

*Written by Matthijs Hollemans*

0 comments on commit 5f071fd

Please sign in to comment.