Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Locked thread
Symbolic Butt
Mar 22, 2009

(_!_)
Buglord
dfs and bfs are straightforward algos that I use quite often

they're like the natural evolution of for loops

Adbot
ADBOT LOVES YOU

Symbolic Butt
Mar 22, 2009

(_!_)
Buglord
you have zero excuse if you can't whip them in a programming interview imo

hobbesmaster
Jan 28, 2008

Symbolic Butt posted:

you have zero excuse if you can't whip them in a programming interview imo

people reading this thread are more likely to be fretting over their cost function for A* or which ordering is optimal for dfs than to have no idea how to create a "trivial" implementation of a bfs or dfs

Shaman Linavi
Apr 3, 2012

i tried to implement some kind of bi-directional A* but instead i just got two A*s that went right past each other
at least the initial/goal states were correct for each direction so i was half right

Bloody
Mar 3, 2013

i have certainly sweat through a bfs/dfs whiteboard before, in part because the interviewer was an rear end in a top hat

Bloody
Mar 3, 2013

but like this is poo poo i use literally never, get off my nuts interview-man

Captain Foo
May 11, 2004

we vibin'
we slidin'
we breathin'
we dyin'

boob-first / dick-first search

carry on then
Jul 10, 2010

by VideoGames

(and can't post for 10 years!)

hobbesmaster posted:

people reading this thread are more likely to be fretting over their cost function for A* or which ordering is optimal for dfs than to have no idea how to create a "trivial" implementation of a bfs or dfs

i need to feel like an ultra-competent hardass by accusing everyone around me of fundamental incompetence, so please don't interrupt

The MUMPSorceress
Jan 6, 2012


^SHTPSTS

Gary’s Answer
i used to know dfs and bfs, but mumps has hosed my brain because they can be fully replaced with $o and $q

BONGHITZ
Jan 1, 1970

Captain Foo posted:

boob-first / dick-first search

pepperoni and keys
Sep 7, 2011

I think about food literally all day every day. It's a thing.
have this been posted yet

https://www.youtube.com/watch?v=ywWBy6J5gz8

Captain Foo
May 11, 2004

we vibin'
we slidin'
we breathin'
we dyin'


oh my goodness

this is fantastic

FamDav
Mar 29, 2008

Symbolic Butt posted:

you have zero excuse if you can't whip them in a programming interview imo

whenever I do phone screens for entry/mid-level hires I usually ask them to write a "head-to-tail" solver and its always :( when they come up with very bad optimizations (hash the words in the dictionary and then sort?) and then when I do convince them to just write the bfs and track incoming edges they do p miserably :(. please just learn a search; it will make you comfortable with using several different data structures (set, queue, stack, and a map if you're storing back references) while not being more than like 10 lines of code.

code:

fn do_a_search(visit_container_ctr, graph, start, end) -> Maybe(Node)
  let seen = set()
  let to_visit = visit_container_ctr(start)

  while !to_visit.empty?
     let n = to_visit.pop
     seen.add(n)
     return n if n == start

     to_visit.push_all(n.neighbors.difference(seen))
  end

  return Nothing
end

let bfs = do_a_search(queue)
let dfs = do_a_search(stack)

FamDav fucked around with this message at 15:23 on Sep 15, 2016

AWWNAW
Dec 30, 2008

what's a "head-to-tail" solver?

ahmeni
May 1, 2005

It's one continuous form where hardware and software function in perfect unison, creating a new generation of iPhone that's better by any measure.
Grimey Drawer

AWWNAW posted:

what's a "head-to-tail" solver?

an extra $50

FamDav
Mar 29, 2008

AWWNAW posted:

what's a "head-to-tail" solver?

if you're given two words (like head and tail) find a chain of words that's one letter different that link the two words. so

head
heal
teal
tell
tall
tail

Captain Foo
May 11, 2004

we vibin'
we slidin'
we breathin'
we dyin'

FamDav posted:

if you're given two words (like head and tail) find a chain of words that's one letter different that link the two words. so

head
heal
teal
tell
tall
tail

this poo poo was a great way to kill time in high school

poo poo
shot
soot
toot
tort
port
post

The MUMPSorceress
Jan 6, 2012


^SHTPSTS

Gary’s Answer

FamDav posted:

if you're given two words (like head and tail) find a chain of words that's one letter different that link the two words. so

head
heal
teal
tell
tall
tail

so i assume one of the preconditions of the interview question is that you can assume youre provided with a dictionary from which you can load words? and the expected answer is basically just "load these into a graph with edges between all words that are one letter apart performance be damned, then do a dfs or bfs to find a path between the two input words"?

i really enjoy how in 90% of problems like this where someone wants you to use a graph to solve the problem, the lovely difficult part of actually building the graph is sort of a handwave.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
why do you need to load them into a graph?

there are only (25 * length-of-word) possible connections, just enumerate them all at every step and check if they're in the dictionary. a constant factor of 100 is irrelevant in the "just get it working" stage.

hobbesmaster
Jan 28, 2008

Jabor posted:

why do you need to load them into a graph?

there are only (25 * length-of-word) possible connections, just enumerate them all at every step and check if they're in the dictionary. a constant factor of 100 is irrelevant in the "just get it working" stage.

but then you'd probably be told to trie again

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder

hobbesmaster posted:

but then you'd probably be told to trie again

lol

FamDav
Mar 29, 2008

LeftistMuslimObama posted:

so i assume one of the preconditions of the interview question is that you can assume youre provided with a dictionary from which you can load words? and the expected answer is basically just "load these into a graph with edges between all words that are one letter apart performance be damned, then do a dfs or bfs to find a path between the two input words"?

i really enjoy how in 90% of problems like this where someone wants you to use a graph to solve the problem, the lovely difficult part of actually building the graph is sort of a handwave.

yeah no need to build a graph. just search and keep track of parents so you can reconstruct the path. the goal is to give you a no magic question; there shouldn't be a critical insight that makes things easy. it's also a question that requires you to use a few different data structures (even if it's an algorithm you should just know), as opposed to many others which are just array operations.

this is for a phone screen, so in the event that they get this all very fast we start talking about similar problems that actually exist and how we can scale them beyond one off scripts.

Shaman Linavi
Apr 3, 2012

i did a genetic algorithm to find rare trade routes in elite: dangerous
of course i dont actually play the game anymore so hell if i know if they are actually good or not

http://i.imgur.com/n3l5xtc.gifv

also i like genetic algorithms

toiletbrush
May 17, 2010
That's really cool. A couple years ago I wrote am iOS Worms clone that started off using genetic algorithms to find the best shot to take to hit an enemy player until I realised that actually just choosing the best angle/power out of 10,000 random shots worked even better. It was disappointing it was such a lame algorithm but the results were brilliant because it would always take the 'obvious' shots when they existed, and choose the shortest 'blow a tunnel through the mountain/roof' route when that was the only option. It was weird how intelligent it seemed when it did sneaky stuff like taking advantage of bugs in collision detection etc.

My final year project at uni used them so a basic voice synthesiser would 'learn' how to pronounce words by example. It was sort of intelligible if you knew what it was trying to say.

OzyMandrill
Aug 12, 2013

Look upon my words
and despair

Captain Foo posted:

this poo poo was a great way to kill time in high school

poo poo
shot
soot
tootsort
tort
port
post

big scary monsters
Sep 2, 2011

-~Skullwave~-
i was trying to find a good memory efficient algorithm to compute the median of large datasets, didn't find one really but there are a number of cool approximations you can use. in the end i treated my data like a stream divided into frames and used reservoir gap sampling to approximate the median. it's not the most difficult or smartest algorithm out there but i thought it was nice

i've also been having fun with algorithms for principal curvature estimation in point clouds, been implementing this thing and learned that "osculating" is a word https://otik.uk.zcu.cz/bitstream/handle/11025/10828/Getto.pdf

i've come to the conclusion that point clouds suck for modelling 3d surfaces, use something with a continuous representation instead

duTrieux.
Oct 9, 2003

toiletbrush posted:

That's really cool. A couple years ago I wrote am iOS Worms clone that started off using genetic algorithms to find the best shot to take to hit an enemy player until I realised that actually just choosing the best angle/power out of 10,000 random shots worked even better. It was disappointing it was such a lame algorithm but the results were brilliant because it would always take the 'obvious' shots when they existed, and choose the shortest 'blow a tunnel through the mountain/roof' route when that was the only option. It was weird how intelligent it seemed when it did sneaky stuff like taking advantage of bugs in collision detection etc.

My final year project at uni used them so a basic voice synthesiser would 'learn' how to pronounce words by example. It was sort of intelligible if you knew what it was trying to say.

this is neat

the bit about the algorithm doing sneaky stuff to seem more robust than it actually was is probably i think very close to how intelligence actually works

i'm pretty sure that at least half of what i do is rationalized as a conscious act after the fact

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

big scary monsters posted:

i was trying to find a good memory efficient algorithm to compute the median of large datasets, didn't find one really but there are a number of cool approximations you can use. in the end i treated my data like a stream divided into frames and used reservoir gap sampling to approximate the median. it's not the most difficult or smartest algorithm out there but i thought it was nice

i've also been having fun with algorithms for principal curvature estimation in point clouds, been implementing this thing and learned that "osculating" is a word https://otik.uk.zcu.cz/bitstream/handle/11025/10828/Getto.pdf

i've come to the conclusion that point clouds suck for modelling 3d surfaces, use something with a continuous representation instead

you can implement quickselect with just streamed inputs and (intermediate) outputs - the actual resident-in-memory data is absolutely miniscule

Cybernetic Vermin
Apr 18, 2005

how do you stream quickselect with less than linear memory? seems non-obvious since you can't really do anything with the output of a partitioning round without knowing which partition will become larger (and solving that is tantamount to solving the original problem)

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
you write two intermediate outputs, one for items larger than the pivot and one for items smaller - the only state you need to track is how many items went each way.

the intermediate streams make it linear in total additional storage required, but streamable storage is a whole lot cheaper than random-access memory.

Adbot
ADBOT LOVES YOU

Cybernetic Vermin
Apr 18, 2005

right, strictly speaking linear, but with a logarithmic bound on the number of reversals of head movement required on the work tape or something a bit wonky lik ethat. i expect "properly" sub-linear memory use is impossible without some solid additional assumptions though

  • Locked thread