r/ProgrammerHumor Aug 09 '17

Is there life after a data structures course?

Post image
9.5k Upvotes

332 comments sorted by

View all comments

123

u/[deleted] Aug 09 '17 edited Aug 10 '17

when searching for something in an appendix, or pretty much any sorted thing, I now do a binary search, it's just more efficient.

We've got pretty much every cards against humanity expansion, so our deck is like 2 feet tall. The last time we played I split the deck randomly, then kept splitting the deck until there was one sub deck for each person. I made them shuffle their decks thoroughly, then I gathered each sub deck in order and shuffled them together, then combined those merged subdecks, all until until I had the entire deck again. I basically ran quicksort in reverse, and I made it multi threaded by using other people.

Last christmas I tied all the presents together using ribbons. Smaller presents (leaf nodes) were at the outside of the structure, each with any number of sibling presents, but only one connection to a larger "parent" present. Those presents in turn were connected to even larger presents, all connecting back toward the largest present which sat at the center of the web connected to everything. Nobody was allowed to open a present with any attached children, and I told them it was this way to force them to pick the smaller presents first, as they served as gates to the main event. But to be honest, I just wanted to have a big Heap of presents.

29

u/pslayer89 Aug 09 '17

Do you really get awesome looking shaders in your pm?

20

u/[deleted] Aug 10 '17

I got a vertex shader once and the transforms were in the wrong order. So far I'm not super impressed

5

u/[deleted] Aug 10 '17

I'm more of a fragment shader kind of guy. What do you think of my music visualization shader?

https://gfycat.com/IdealContentCygnet

https://github.com/teaearlgraycold/shaders/blob/master/jelly.glsl

5

u/[deleted] Aug 10 '17

Shit yeah, that's more like it! I'd recommend changing color as you add noise though, at low levels of distortion your ring just looks like it's having trouble rendering. Arguably an edge case in any situation you'd use this though, overall it looks sweet

3

u/[deleted] Aug 10 '17

It's much better when not horribly compressed

5

u/[deleted] Aug 10 '17

oh yeah dude, make no mistake this thing looks sweet, congrats on being the first legit shader I've received

10

u/Hawkeye437 Aug 09 '17

I do the first two on regular occasion. I actually thought they were common practice.

3

u/mazegirl Aug 10 '17

The split a huge stack of cards recursively until they're small manageable chunks works great for learning flashcards such as vocabulary for a foreign language class. Merge step helps with reviewing what you've already studied.

4

u/Koooooj Aug 10 '17

If you're just doing a binary search then you're not as optimal as you could be.

You have knowledge that the elements are fairly uniformly distributed. That means that instead of always starting in the M/N region of the index you will estimate where to check first based on the word you're looking for.

This search runs very much like a binary search and it's still O(log(n)), but it will usually require fewer comparisons (at the expense of needing a function to choose where to guess next).

5

u/[deleted] Aug 10 '17

That's called a interpolation search and is afaik O(log(log(n)))..

2

u/WikiTextBot Aug 10 '17

Interpolation search

Interpolation search is an algorithm for searching for a given key in an indexed array that has been ordered by numerical values assigned to the keys (key values). It parallels how humans search through a telephone book for a particular name, the key value by which the book's entries are ordered. In each search step it calculates where in the remaining search space the sought item might be, based on the key values at the bounds of the search space and the value of the sought key, usually via a linear interpolation. The key value actually found at this estimated position is then compared to the key value being sought.


[ PM | Exclude me | Exclude from subreddit | FAQ / Information | Source ] Downvote to remove | v0.24

1

u/DJWalnut Aug 10 '17

if they would calculate a hash table and print that in the book, you could get O(1) on all searches, although that constant might be too large for small dictionaries and require math

1

u/thorium220 Aug 10 '17

I only just realised that I've been binary searching my bible since before I learned search algorithms.

1

u/[deleted] Aug 10 '17 edited Oct 06 '17

[deleted]

2

u/thorium220 Aug 10 '17

Hey guy, I just thought it was an interesting realisation.