Live data from Hacker News

Data structures and algorithms I actually used while working at tech companies

blog.pragmaticengineer.com

171–180 of 547 posts

Re: Data structures and algorithms I actually used while working at tech companies

#171
post #164
post #141

Earlier quoted context omitted.

In practice iteration will be faster, even in Python (because there's less overhead). But yes, I should have written "naive recursive solution". There are many ways to fix it. It just wasn't what the question was about.

In Python, yes. If you have a decent language and a good compiler / interpreter, then the recursion with function calls will have no overhead over iteration. (Basically, in Haskell or Scheme your recursion will be compiled into the same machine language sequence of straight-line code plus conditional jump as the iterative loop.) But, agreed with everything else you wrote!

I can't be sure without measuring, but I strongly suspect the overhead will be mostly in tuple packing/unpacking and GC.

And I instinctively distrust Sufficiently Smart Compilers ;)

Re: Data structures and algorithms I actually used while working at tech companies

#172
post #149
post #61

Earlier quoted context omitted.

By the way they discuss the implementation. First level is ensuring that base cases are covered (i.e. correct implementation of recursion) Second level is how they explain the simple recursion that’ll hit stack limits (i.e. without tail recursion) Third level is using accumulator/tail recursion. See how they can express these ideas and are they able to effectively communicate their intentions.

There should be a fourth level where they use the closed form solution to get to the solution they want without any recursion or looping for reasonable values of N. Maybe even a fifth level using the O(log(N)) matrix exponentiation method.

I’m a bit puzzled at the idea of using recursion for an infinite sequence (did OP mean factorial?). Give me a LazyList / generator / IEnumerable instead any day for Fib.

Re: Data structures and algorithms I actually used while working at tech companies

#173
post #22
post #10

I've used Dijkstra algorithm for calculating distance in a graph once. It was a highlight of that month. Of course I had to look it up(despite learning it and implementing it at university). Who remembers this stuff exactly after years of glueing libraries together? And even if you remember - won't you check it anyway just to be sure? It's OK to ask people general questions (what's algorithmic complexity, what kind o…

We always tell our candidates in advance what algorithms we'll be quizzing them on. And it's pretty much always: + fibbonacci + a sort + a linked list I like having candidates write out these problems on paper because it shows that they know how to think about code. Fibbonacci allows us to see that they have basic recursion understanding, and basic iterative loop understanding. Linked lists shows us that they underst…

12 years as a developer.

Used recursion only once. Once.

(but that specific time recursion was really a life saver)

Re: Data structures and algorithms I actually used while working at tech companies

#174

Which are the best books to learn Data Structures and Algorithms ? (Or which books did you use/recommend to learn Data Structures and Algorithms?)

Algorithms, Fourth Edition, by Sedgewick and Wayne. A bit more accessible than the CLRS.

Re: Data structures and algorithms I actually used while working at tech companies

#175
post #64

A few years ago I spend lots of time and effort at Goldman Sachs solving a performance problem in a major part of their internal cloud infrastructure. The programme in question was running into performance problems, and a few smart people had already banged their head against a wall solving them. After lots of experiments and different approaches, my solution was to remove most of the advanced data structures that we…

I've learned approaches like this when I took a Operations Research class. I found it all exciting. We've also learned techniques to better choose between meta-heuristics like CGRASP, or flat algos, or integer programming, and so on. Now I'm seeing if I can think of some cool pet project where I can apply this stuff.

Re: Data structures and algorithms I actually used while working at tech companies

#176
post #150

Earlier quoted context omitted.

I agree with this 100%. I'd also like to add that because of this I adapted the traditional whiteboarding exercise at my current company to be about problem solving and design, and not about how many data structures you've memorized. When a candidate comes in, I give them a fake-yet-realistic product requirement (like count elements in a real-time stream from field sensors) and let them run with it however they see f…

It sounds like you're trying which is encouraging. I'll give you a few tips that I hope help. > I adapted the traditional whiteboarding exercise Lots of engineer types freeze when they have to make a presentation. I remember a meeting early in my career with literally three people in a conference room and I almost had a panic attack. No white board. People I already knew. All I had to to do is explain my ideas to thr…

>Lots of engineer types freeze when they have to make a presentation. I remember a meeting early in my career with literally three people in a conference room and I almost had a panic attack.

That's definitely an unfortunate experience, but isn't giving presentations to explain your ideas - sometimes to people you don't really know - actually a significant part of the job? I'm an IC, and I present designs and project plans for feedback to groups of up to a couple dozen people, or to VPs, on a pretty regular basis. If I couldn't do that competently I would be failing at my job, because that kind of communication is just as important as actually writing the code. If I were conducting an interview and discovered that "public" speaking on the order of a few people in a conference room was extremely difficult for you, I'd probably consider that an important red flag.

Re: Data structures and algorithms I actually used while working at tech companies

#177
post #4

I recently had an A-ha moment when I realized that the problem I was trying to solve admitted a simple solution with dynamic programming, something I had never used outside programming competitions. The problem was to divide a text into a number of tweets to make it a thread, with the obvious constraint that no tweet should have more than 280 characters, but you still wanted to minimize some cost based on how far you…

standard 'text justification' dp problem ? Eric's mit video on this : https://www.youtube.com/watch?v=ENyox7kNKeY leetcode https://leetcode.com/problems/text-justification/

(Apologies to people on mobile for the following...)

  One of the things I miss about Usenet was that
  nearly everyone read it with a fixed with font
  so that if you choose your phrasing well so as
  to make your text come out naturally perfectly
  justified, it would come out that way for them
  too.

  English has so many synonyms and near-synonyms
  for every word, and so much flexibility in the
  ordering of words that you can write like this
  in near real time.

  You get to the end of a line, find that you're
  just a little long or short, and you backtrack
  just a couple words or so most of the time and
  you can usually find a way that works. In this
  paragraph, for instance, I was one too long in
  the first line, but contracting "you are" down
  to "you're" fixed it. I was short in that last
  sentence, but inserting "down" fixed it.

  Perfect justification by inserting extra space
  is for amateurs.

  Now we've got all fancy and use variable width
  fonts and automatic wrapping and posting isn't
  quite as fun anymore.

  Give it a try. Use an editor with a fixed font
  to compose your next post and try to get it to
  come out perfectly justified without having to
  insert extra spaces. When you paste it into HN
  that will get lost, but the composing can be a
  fun little English puzzle.

Re: Data structures and algorithms I actually used while working at tech companies

#178

Earlier quoted context omitted.

It sounds like you're trying which is encouraging. I'll give you a few tips that I hope help. > I adapted the traditional whiteboarding exercise Lots of engineer types freeze when they have to make a presentation. I remember a meeting early in my career with literally three people in a conference room and I almost had a panic attack. No white board. People I already knew. All I had to to do is explain my ideas to thr…

>Lots of engineer types freeze when they have to make a presentation. I remember a meeting early in my career with literally three people in a conference room and I almost had a panic attack. That's definitely an unfortunate experience, but isn't giving presentations to explain your ideas - sometimes to people you don't really know - actually a significant part of the job? I'm an IC, and I present designs and project…

What is an IC?

> isn't giving presentations to explain your ideas - sometimes to people you don't really know - actually a significant part of the job?

For many engineering positions it is not. There are loads of shops where the developers, even senior developers, mostly just write code. I have hired many of them and put them to work successfully building stuff while I deal with the meetings.

> If I were conducting an interview and discovered that "public" speaking on the order of a few people in a conference room was extremely difficult for you

And yet I worked very successfully as a junior developer for a couple of years before I ever had to attend a meeting like that. Among the other 100 devs in the shop, I was considered a top talent at coding. That's not to brag but to point out that I was adding lots of value to the company without having to attend meetings with people from other departments. My manager did that. My manager did not code, although he could if he wanted to. In fact at that company they created a separate path for highly talented engineers who wanted to continue coding but wanted to avoid management and meetings. That was a couple of decades ago and less common, but I think it's a lot more common now.

And the fact that I can now publicly speak in front of hundreds of people should hopefully encourage you that it's something people can learn if they want to. Some people don't want to. There are roles for them too.

Re: Data structures and algorithms I actually used while working at tech companies

#179
post #22
post #10

I've used Dijkstra algorithm for calculating distance in a graph once. It was a highlight of that month. Of course I had to look it up(despite learning it and implementing it at university). Who remembers this stuff exactly after years of glueing libraries together? And even if you remember - won't you check it anyway just to be sure? It's OK to ask people general questions (what's algorithmic complexity, what kind o…

We always tell our candidates in advance what algorithms we'll be quizzing them on. And it's pretty much always: + fibbonacci + a sort + a linked list I like having candidates write out these problems on paper because it shows that they know how to think about code. Fibbonacci allows us to see that they have basic recursion understanding, and basic iterative loop understanding. Linked lists shows us that they underst…

> Fibbonacci allows us to see that they have basic recursion understanding

I see no reason to use recursion when asked to calculate Fibonacci numbers. A loop looks like a more reasonable choice that also avoids typical pitfalls associated with recursion. Maybe that's because I did embedded programming for a while.

I suspect recursion is introduced in CS classes with this example, but people understand it as "you are supposed to use recursion to calculate Fibonacci numbers".

Re: Data structures and algorithms I actually used while working at tech companies

#180

Which are the best books to learn Data Structures and Algorithms ? (Or which books did you use/recommend to learn Data Structures and Algorithms?)

Algorithms, Fourth Edition, by Sedgewick and Wayne. A bit more accessible than the CLRS.

Out of both, which do you think is better in explaining things concisely?
Post reply on HN