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
Walh Hara
May 11, 2012

Sex Bumbo posted:

Yeah but... recursion is the wrong way to produce Fibonacci numbers. There's no reason to do it like that. Just put it in a loop and it's better code.

I like being pedantic, so: this is not true, there are multiple ways to use recursion to calculate Fibonacci numbers in linear complexity. For example:

fib_recursion (int n, a, b) =
if n <= 0 then b else fib_recursion (n-1, b, a+b)

call with fib_recursion(n, 1, 1)

Adbot
ADBOT LOVES YOU

Walh Hara
May 11, 2012

FamDav posted:

Your solution is quadratic. Fibonacci numbers grow geometrically and bignum arithmetic is linear in the number of digits for addition. Unless you have access to an ALU that can do unbounded integer arithmetic in constant time?

Fibonacci is a dumb interview problem and your answers are probably wrong too.

Ha, fair point, my example is wrong (but my claim that there are ways to calculate fibonacci in linear time is not). Either way I was just pointing out that when people say "solve fibo with recursion" you do not necessarily have to answer with fibo(n) = fibo(n-1) + fibo(n-2). Whether you use recursion or iteration shouldn't really change the time complexity (big O) of the optimal solution of any problem if you know what you're doing.

That said, if I went to a job interview and somebody asked me the fibonacci question I'd be quite offended so I agree it's a silly interview problem.

Walh Hara
May 11, 2012
Hmm, I guess I should have done more research before making claims, serves me right for being pedantic. (I did indeed have the algorithm using matrix multiplication in mind)

That said, I agree now even more that it's a bad interview question.

Walh Hara
May 11, 2012

Infinotize posted:

Not FizzBuzz, but I have yet to find a candidate that could code up a bit counter*, in any language or even pseudocode, in the ~dozen interviews where I asked that question. Maybe I should be asking FizzBuzz first.

* given a byte or an int or whatever the hell you want output how many bits in that thing are on
** these are for senior level coding positions

That actually doesn't surprise me, because I've never learned about bitwise operators at all in my studies. Java, Haskell, Graph theory, advanced algorithmic datastructures, data analsysis, bio-informatics, etc, where all considered more important than bitwise operators by my university.

Walh Hara
May 11, 2012

feedmegin posted:

Then your course sucked. They are the L in ALU. Bitwise instructions are one of the few fundamental things a CPU is for. Im amazed you can go to uni for comp sci and not be given a basic course in how a CPU actually works.

Well, if I had had any interest in CPU's I could probably have taken a course about that, but as I never aimed for a job where I would need to know how a CPU worked I'm not too bothered about my uni not teaching me that. I actually didn't follow a traditional comp sci course either, mine was very focused on the mathematical sides of informatics (i.e. data analysis, bio-informatics, complex algoirthms using graph theory, numerical optimisation, neural networks, time series forecasting, etc).

edit: to clarify, obviously I know what the operators and, or, xor, shift, etc mean in the context of bits. That's very simple. I just never saw the syntax and didn't know the >>= symbol (for left shift I assume?) posted in the code example above.

Walh Hara fucked around with this message at 13:33 on Jun 19, 2016

  • Locked thread