Do you ever sort a b-tree(or whatever) in your daily job?



  • I just got asked a few multiple choice questions like,

    1. B-tree is used to... do this or that
    2. To delete and insert elements at random order under O(log N) time, you need... (some hash and lists)

    Also

    1. What would be the result of this code after x loops by x threads?
    2. Implement a Comparator to run the code below

    Do you ever use these in your daily job?



  • @Ascendant said:

    Implement a Comparator to run the code below

    I'm not sure what that means, exactly, but I have written a lot of Comparators for sorting stuff.



  • @boomzilla said:

    I'm not sure what that means, exactly, but I have written a lot of Comparators for sorting stuff.

    Pardon my ignorance and please enlighten me. Why would one need to sort? And what would one need to sort?

    I've never had to sort anything....



  • We've had this discussion a lot of times before, and the consensus is "generally, no".

    Knowledge about algorithmic complexity is generally useful if you want to be a good programme, but such in-detail questions (especially on data structures, where all you need to know in day-to-day work is which one to pick from standard library, not how to implement it) are generally pure YAGNI.



  • @Ascendant said:

    I've never had to sort anything...

    Wait, seriously? You've never needed to show things like names in alphabetical order on a report or something?



  • @Maciejasjmj said:

    Wait, seriously? You've never needed to show things like names in alphabetical order on a report or something?

    Yes, seriously. I was told to use an

    ORDER BY clause

    (in the database)



  • I don't work at that level of abstraction. Because I'm the kind of software developer who likes to get shit done instead of reading computer science textbooks 6 hours a day.



  • While I like reading CS textbooks, the question I asked myself was, "Why/when would you need those hashmaps, links and trees and why/when would you sort them or whatnot?".

    So I'm trying to find some examples but I never really had to use those.


  • Winner of the 2016 Presidential Election

    @Ascendant said:

    What would be the result of this code after x loops by x threads?

    pretty sure thats something that you need to be able to do. Look at the code others have written and see what it does. Or look at your own code and run it inside your head for a few loops to see why it messed up.
    Basic Code-reading is a thing needed for every coder.

    And understanding what a binary tree is and how it's used is also probably not a bad thing. Knowing what container to use can help you out.

    Not saying you need to know the specific details and the question about the insert is weird but I wouldn't call it wrong to at least ask if the applicant knows some things.

    Filed Under: Wouldn't reject you based on your answer, though



  • I decide based on their fuction. If I need a list of items where I can't have duplicates, that's a HashSet (in C#.) If I need a list of items identified by a key, and the keys can't be duplicated, that's a Dictionary<> in C#. If I need a simple list that allows duplication, that's List<>. Etc.

    I let C#'s designers worry about making those collections performant. It's their job, not mine.

    EDIT: that's not to say you should give my answer in an interview situation, of course. Although personally I'd be suspicious of any interview that asked you about a b-tree-- I always ask (and always am asked) practical questions, writing actual functions that do actual tasks.


  • BINNED

    The worst sort of interview questions are what the interviewer himself is not clear about, long-winded and yet-tobe-defined like: write a linked-list then reverse every 3rd but not every 4th chunk. :wtf: does that mean? what about the 12th chunk? how can I read your mind? ah wait you are not clear yourself? Just fucking write the question on a piece of paper, have an answer ready and help me discover it, then take a picture of my answer. If I am wasting my time answering your stupid question it is an assholish move to not bother thinking about your questions beforehand.



  • Because I'm the kind of software developer who likes to get shit done instead of reading computer science textbooks 6 hours a day.

    Which of course is why you post here for 6 hours a day, on top of your comprehensive video gaming schedule.



  • Well "likes to get shit done" is relative of course. I'd slack off 6 hours a day regardless of method.

    I dunno, I got "senior" in my title, I'm making 6 digits and I've survived 80% of the layoffs I've been through despite this level of slack, so I must be doing something right.



  • I'd say it depends on the job you're applying for. If you're applying for a function as a generic frontend/backend code monkey writing 'the next big hit from the App Store', it's probably irrelevant knowledge. A perfectly valid response in my view would be "I have never had the need to sort a b-tree by hand, because I use the tools that are provided by the framework developers. Now, would you like me to tell you about the differences between a Dictionary, List, Collection, Queue and HashSet and when to use either of them?"

    If you're applying at Boeing to help write the software for their next major aircraft... then you might better know a thing or two about algorithms.



  • @Ascendant said:

    Pardon my ignorance and please enlighten me. Why would one need to sort? And what would one need to sort?

    I've never had to sort anything....


    One example is optimization with meta-heuristics (for problems like calculating parcel delivery routes. or calculating which the hotel reservations that came in today is allocated to which room, etc.). Sometimes these algorithms perform better if you let them begin with the most difficult items. Of course there are frameworks that can help you, but you still need to supply your own difficulty comparator to the framework.



  • This reminds me of a time when I had to update a chunk of code that sorted a list of items in dependency order. The old code was a form of trial-and-error, and it needed to track all indirect dependencies on the item, making it hard to scale as the potential number of items grew. I ended up replacing it with a recursive algorithm I found on wikipedia (but really should've been able to think of myself) which doesn't require that extra memory and is O(n).



  • @Ascendant said:

    Pardon my ignorance and please enlighten me. Why would one need to sort? And what would one need to sort?

    It's usually a list of stuff that I'm getting ready to display. Users tend to frown on randomly ordered items in a table of stuff.

    @Ascendant said:

    Yes, seriously. I was told to use an

    ORDER BY clause

    (in the database)

    I do that a lot, too. But life isn't always that simple.



  • @boomzilla said:

    It's usually a list of stuff that I'm getting ready to display. Users tend to frown on randomly ordered items in a table of stuff.

    I'd go as far as to say that when you are displaying a list of similar items to a user, there should always be a defined sort order (even if it's not configurable, or you're not even telling the user what the order is).

    I do a lot of data processing stuff, and sorting tends to be relevant there as well, like in my example above where parsing/value derivation steps need to run in a certain order, but also in various stages where partitioned input data needs to be sorted by time.

    A special case I use occasionally is a timeout queue. Items shift onto one end in sorted order, and are either picked from the middle of the queue if they become active again, or come out the other end when they expire. As long as you're processing stuff in mostly chronological order, and the timeout is significantly larger than the inaccuracies in your input time ordering, you don't need to bother sorting at all.



  • @Ascendant said:

    Yes, seriously. I was told to use an

    ORDER BY clause

    (in the database)

    So... if you had data on the screen and the user wanted the data sorted by a different column, you would discard the data and fetch a new result set just to implement a sort? That's nuts.


  • :belt_onion:

    Your scenario happens in case of using a webapp though... (Maybe not when it's client side sorting, but at least in the olden days)

    EDIT: Still agree though that knowing how to sort a list is recommended, plain old GUIs can cache and sort if all the data is in memory.



  • Yup, I do. If you need to manage a large set of data in an environment that doesn't have a proper data structure that keeps things sorted, you need to pick one. In some cases, a B-tree makes sense, or a min-max heap, that kind of stuff. I mostly end up using DAGs.

    A comparator is something that returns a value indicating the ordering of two elements. Most common is a < b -> -1, a == b -> 0, a > b -> +1. You need them even in Javascript when you have to sort a list numbers.


  • Winner of the 2016 Presidential Election

    B-tree is used to... do this or that

    :-1:

    I've never had to use a B-tree before, and the only thing I know about it is that you use it as an on-disc data structure when you want to reduce the number of random disk accesses (e.g. in file systems or databases). I have absolutely no idea how they're organized internally or how the operations are implemented, I'd have to look that up.

    If an interviewer expects you to say anything more than that, he's TRWTF. "It's used for DB indexes" or something like that should be sufficient as an answer, they probably want to know whether you've heard about the data structure before. And even if you had never heard about it, I personally wouldn't care (although I might wonder whether you've actually attended your lectures at university).

    Whether that question is appropriate for an interview or not depends on the job. For most jobs, probably not, unless you're trying to get a job as a database developer.

    To delete and insert elements at random order under O(log N) time, you need... (some hash and lists)

    :+1:

    Well, that's a multiple-choice question I'd expect you to be able to answer, if you want to do something more complicated than JS frontends with jQuery. You rarely have to implement a data structure yourself, but you have to be able to choose the correct data structure from the standard library without thinking about it for too long. If I interview you, I'll ask one question like that.

    @Ascendant said:

    What would be the result of this code after x loops by x threads?

    They want to know whether you can actually read code. That's something I'd rather try to find out in the personal interview, not during a multiple-choice test.

    Implement a Comparator to run the code below

    :+1:

    I wouldn't not hire you if you don't know what a comparator is, but I'd expect you to be able to implement one after I've explained to you what it is.


  • Impossible Mission Players - A

    @asdf said:

    if you had never heard about it, I personally wouldn't care (although I might wonder whether you've actually attended your lectures at university).

    :wave: Never came up in any lecture. Though to be fair I never did take any theoretical programming concepts courses....



  • @Jaime said:

    So... if you had data on the screen and the user wanted the data sorted by a different column, you would discard the data and fetch a new result set just to implement a sort? That's nuts.

    Yup. That's what I get told to do in every project.

    Sometimes my senior devs and pms say they have to have some sort of sorting because of specific user requirements. Then they just buy a third party commercial "chart/graph component". That's it.


  • :belt_onion:

    Ever learned Java? If you've been told about the sort methods you should have been introduced to the Comparable interface. From there it's only a small step to the Comparator interface.


  • Impossible Mission Players - A

    @JBert said:

    introduced to the Comparable interface.

    Oh no, I was talking about B-Trees.
    I'm pretty sure you were as well...



  • If I needed a b-tree for something at the project I'm working I would have to implement it, because it have to run in shitty embedded platforms and MS-DOS. So far I didn't need to implement anything better than a simple linked list.



  • So then this is pretty WTF that I've never seen a Comparator implemented, let alone any kind of sorting in the many projects?

    Well, they rarely(read never) use the keywords "extends" or "implements" to begin with.



  • When you're seeing questions like that, you're another victim of the "database of interview questions".

    Interviewers now cannot ask sane, direct interview question because they might just get recited answer from interviewee, and cannot reflect their actual level of knowledge on the subject. They have to tweak it... and unfortunately they didn't do a good job on that.



  • I'm seeing more and more of a < b -> true, a >= b -> false.


  • Winner of the 2016 Presidential Election

    @Tsaukpaetra said:

    :wave: Never came up in any lecture. Though to be fair I never did take any theoretical programming concepts courses....

    Really? I just checked: B-trees were mentioned in at least 3 different mandatory courses I had to take for my B.Sc. (Introduction to Algorithms, Introduction to Databases and Operating Systems). But yeah, I guess it's not mandatory knowledge, since B-trees are a very specific data structure that is only used under very specific circumstances.

    @Ascendant said:

    Yup. That's what I get told to do in every project.

    :facepalm:

    Please forget everything any of your bosses or coworkers ever told you. Think about your future coworkers' sanity!


  • Impossible Mission Players - A

    @asdf said:

    Really? I just checked: B-trees were mentioned in at least 3 different mandatory courses

    Yep! Never mentioned anywhere! :smiley:



  • @asdf said:

    :facepalm:

    Please forget everything any of your bosses or coworkers ever told you. Think about your future coworkers' sanity!

    You see? This is why I have no idea what a senior dev should look like. These are the only people I've seen!
    Now I have to suspect every single decision they make.
    Most of the time it's very obvious that they are gobshites though.


  • Winner of the 2016 Presidential Election

    @Ascendant said:

    This is why I have no idea what a senior dev should look like.

    Ideally, a senior dev:

    • Should have learned a bit about software design in practice. Knows how to avoid both extremes (overengineering vs. unstructured spaghetti code).
    • Doesn't make rookie mistakes anymore: Makes sane technology choices instead of choosing bleeding-edge technology for no good reason. Knows not to touch stuff that isn't broken. Doesn't annoy his coworkers by doing stupid shit like reformatting the entire code base (unless everyone agrees that this is absolutely necessary). Doesn't blindly copy&paste code from StackOverflow that he doesn't understand.
    • Writes readable code and documents both important design decisions and the parts that are hard to understand, because he has learned how important that is.
    • Knows when it's better to get stuff done instead of doing it right and vice-versa.
    • Has gained some organization skills. Knows how to prioritize and how to incrementally build larger features/applications.
    • Is a decent programmer that has mastered a few technologies and won't be completely lost when confronted with a new one.

    One can always dream, right?



  • @asdf said:

    Ideally, a senior dev:

    Can be given a project and told "You're working on this", and can just work on it. Will know when to ask for assistance for internal IT, business process, or client expectations. You can trust you will get something that can be sent to the customer, and not published here.



  • @Lorne_Kates said:

    and not published here.

    Awww where is the fun then.

    But yes. No more WTF puleeeeeeeeease. :sob:



  • Guess I'm the exception then. Yes, I use trees/graphs/etc regularly, and implementing specialized versions of such data structures is frequently a core consideration of whether or not a certain project succeeds. Sorting algorithms are equally important.

    Sorting elements along a z-curve for building a quick & dirty left-balanced n-ary tree is one of my favourite algorithms.



  • What do you use that for though?


  • Winner of the 2016 Presidential Election

    @cvi said:

    Guess I'm the exception then.

    :wave:

    I sometimes have to implement specialized data structures and algorithms as well. And I definitely have to know the characteristics of standard data structures to do my job.



  • I suppose a good example would be stuff like bounding volume hierarchies, where your goal is to locate some objects quickly and efficiently. Also look at part 1 and part 2 of this series on collision detection.

    But you will find either tree-like or hash-table--like structures pretty much everywhere, once you go looking under the hood.


  • Winner of the 2016 Presidential Election

    Do you actually work on game engines or something similar? Every example I could think of is pretty boring in comparison.



  • Actually, it's in the courses of my Mathematics Higher Diplomia too.

    So I think it should be included in any courses that touches programming.

    And btw, we also taught AVL trees... although the detail on how autobalancing works is mostly forgotten now.



  • And will acknowledge PMs/sales on something that cannot be done on timely fashion, so they have time to seek recourse and the developers work under his lead don't have to do shitty things.

    I have once worked with sales that dreams too much too. :anguished:


  • Winner of the 2016 Presidential Election

    @cheong said:

    autobalancing

    I remember that we spent at least 2 whole lectures discussing the pseudocode for red-black trees. If they wanted to make absolutely sure I hate them, they succeeded.



  • @cvi said:

    Yes, I use trees/graphs/etc regularly, and implementing specialized versions of such data structures is frequently a core consideration of whether or not a certain project succeeds.

    What kind of projects do you work on?


  • Winner of the 2016 Presidential Election

    @boomzilla said:

    What kind of projects do you work on?

    $10 on either games or robotics.


  • BINNED

    @cheong said:

    When you're seeing questions like that, you're another victim of the "database of interview questions".

    That is the real :wtf: with the interview process. I absolutely never study for an interview, because I hate wasting my time reading crappy problems. I know I am :doing_it_wrong:.
    The interviewers think all candidates have memorized those crap. When it takes me 2 seconds more than their average candidates to discover an answer to some stupid trivia question they must think aha this guy is slow!



  • There are stuffs that if you don't know in the beginning, you have no chance to check it until you need to use it, or worse, until you hit a bug, and that'll cause you the pain to have to restructure your code a bit in order to fix it.

    For example, a question asked in MSDN forum this morning regarding the use of some UI related API to another window within model dialog. Or strategies of avoiding deadlocks in multiuser environment. Or trying to automatically upload documents by specifying "value" in INPUT type=file controls... just to name a few examples that I see within last week.

    If you plan to continue doing programming career in your next 10 years, you had better read a lot... even informations that's not related to your current work, just in case you have to move... be it you suddenly get a bad boss, or somehow you need to search for a new job. More skill and knowledge in your packet means you have wider option.


  • BINNED

    @cheong said:

    If you plan to continue doing programming career in your next 10 years, you had better read a lot...

    I am doing programming career more than 10 years. I have done all sort of crap, and there is no way one can know all the fucking crap in the world. Every single project has its own crap, that I end up reading and learning. I can learn new crap, and like to read and learn new technology on daily basis, and have done so all during my career. This does not mean I will go and read "reverse linked-list on 3rd nodes" type of stupid questions.


  • Discourse touched me in a no-no place

    I think I have written 2 comparators in the history of ever. LINQ lambdas have obsoleted them in C#.


Log in to reply
 

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.