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.
 
  • Post
  • Reply
sarehu
Apr 20, 2007

(call/cc call/cc)
Avoiding O(N) factors is already useful enough. It's the log(N)'s you've got to watch. An O(log N) that hops through pointers or disk blocks is one thing, but if it hops through bits of a word, that's another.

Adbot
ADBOT LOVES YOU

TooMuchAbstraction
Oct 14, 2012

I spent four years making
Waves of Steel
Hell yes I'm going to turn my avatar into an ad for it.
Fun Shoe

Simulated posted:

Summing the elements in a linked list and summing the elements in an array are both O(N) in theory; they should both execute around the same number of instructions. In reality the array will be faster and the larger your dataset (or the more spread out the linked list nodes) the faster the array will be. For a 1 GB dataset the array can absolutely kill the linked list, in some scenarios by an order of magnitude. How useful was knowing they are both O(N) if one takes 10x as long to execute?

Now I'm wondering if there's some point at which the linked list starts to win out overall just because you don't have to allocated a gigantic contiguous block of memory for it. Assuming the task looks something like "create datastructure, load data into datastructure, perform O(N) operation on datastructure, release allocated memory". (And nevermind that in most cases you'd do the "perform operation" as you load data)

brap
Aug 23, 2004

Grimey Drawer
I've seen a heuristic for whether a linked list makes sense of: if you are adding and removing in the middle 10x as often as you are performing a full traversal, the linked list is better.

Fergus Mac Roich
Nov 5, 2008

Soiled Meat

hobbesmaster posted:

This is why a common interview question is to explain when you shouldn't use quick sort.

I know a few reasons why you wouldn't use quicksort, even a modern, randomized, three way partition quicksort,(you want stability etc) but I don't know the answer to this interview question with respect to running time. My best guess is that you might know certain properties of the input that could make another approach(like the Timsort used by Java, iirc) more efficient, allowing for extra memory use.

Am I on the right track?

Fergus Mac Roich fucked around with this message at 02:16 on Oct 16, 2016

Simulated
Sep 28, 2001
Lowtax giveth, and Lowtax taketh away.
College Slice

TooMuchAbstraction posted:

Now I'm wondering if there's some point at which the linked list starts to win out overall just because you don't have to allocated a gigantic contiguous block of memory for it. Assuming the task looks something like "create datastructure, load data into datastructure, perform O(N) operation on datastructure, release allocated memory". (And nevermind that in most cases you'd do the "perform operation" as you load data)

Here is a Swift library that uses B-trees. I attached his performance graph showing inserting into a sorted array at O(n^2) is an order of magnitude faster than a red-black tree at O(N log N) up to a certain size because the array is just so drat amenable to prefetch, branch prediction, and fits in L1/L2. It takes 100,000 items for the red-black tree to be faster.

B-trees (not B+trees) are a reasonable compromise because each node's array holds quite a few items, but you don't need to allocate one massive array when the datasets get large and the concatenation performance isn't so degenerate. A side benefit for copy-on-write implementations is you can continue to share non-mutated parts of the tree.

Only registered members can see post attachments!

Axel Rhodes Scholar
May 12, 2001

Courage Reactor

UraniumAnchor posted:

A bit old but it popped up in my Twitter feed today and it seems relevant:

http://gwan.ch/blog/20160405.html

(Coding interview horrors.)

I'm liking the updates at the end.

quote:

Update: http://technicaltalkaboutit.blogspot.com.au/2016/10/what-to-expect-interviews-and-google.html a Goggle employee blog post successfully posted on LinkedIn with incoherent junk vocabulary starting from the middle of the text (probably aimed at lowering my post's rank in search engines) written by Marcia Pinheiro who looks like a Google Internet Shill (in orange, text related to me and Google but favoring Google, in red, the unrelated offending vocabulary)

(all emphasis his)

TooMuchAbstraction
Oct 14, 2012

I spent four years making
Waves of Steel
Hell yes I'm going to turn my avatar into an ad for it.
Fun Shoe

Simulated posted:

Here is a Swift library that uses B-trees. I attached his performance graph showing inserting into a sorted array at O(n^2) is an order of magnitude faster than a red-black tree at O(N log N) up to a certain size because the array is just so drat amenable to prefetch, branch prediction, and fits in L1/L2. It takes 100,000 items for the red-black tree to be faster.

Neat, thanks for doing this analysis!

dougdrums
Feb 25, 2005
CLIENT REQUESTED ELECTRONIC FUNDING RECEIPT (FUNDS NOW)

Axel Rhodes Scholar posted:

I'm liking the updates at the end.

(all emphasis his)

Ok, the end of that is a little strange, but I take it that english is probably not her native tounge... also it's pretty funny that he's so mad that he has to load up his image editor and underline stuff.

Someone mentioned that array problem... what he's doing is casting the pointer to a 64 bit integer a la *(uint64_t*), since the popcnt of 4 shorts is the same as one 64 bit integer, saving some movs I think. He didn't make it too clear to someone who probably doesn't write c code every day. And like someone else mentioned, popcnt is usually the right answer. (Unless it's a 68k, I'm bad at reading I guess.)

Are modern C compilers able to infer this? I'm asking because I really don't know.


Either way, I think I'm half this guys age, and I can probably answer all of those questions without making the interviewer want to hit me. (I didn't notice before, but he actually states what half his age is exactly ...)

dougdrums fucked around with this message at 12:16 on Oct 16, 2016

Edison was a dick
Apr 3, 2010

direct current :roboluv: only
On Linux I'd use ffs from Glibc, since it'll normally become the x86 instruction or a compiler builtin.

raminasi
Jan 25, 2005

a last drink with no ice

TooMuchAbstraction posted:

Now I'm wondering if there's some point at which the linked list starts to win out overall just because you don't have to allocated a gigantic contiguous block of memory for it. Assuming the task looks something like "create datastructure, load data into datastructure, perform O(N) operation on datastructure, release allocated memory". (And nevermind that in most cases you'd do the "perform operation" as you load data)

One time on a project I had to switch a structure from an array to a linked list because it was so big that there wasn't a single spot in the heap that could fit it all.

(Well I assumed that was the problem, anyway. The allocation failed with std::vector but not std::list.)

fritz
Jul 26, 2003

Axel Rhodes Scholar posted:

I'm liking the updates at the end.


(all emphasis his)

I've seen that Pinheiro person before, she's a regular linkedin spammer, and even a nominal bing.com search brings up her other blog: https://drmarciapinheiro.wordpress.com/about/ and she looks like some kind of crank.

Xarn
Jun 26, 2015

rjmccall posted:

I have no idea what you're trying to say here. Xarn said that walking a linked list is N log N; Fergus correctly pointed out that it's N log K, where K is the size of the address space; and I added that if you're including this "size of the address space" factor, you need to apply it to everything instead of singling out linked lists. Indexing into an array is O(log K). You can try to make a locality argument to drop this factor because of translation caches, but now you're talking about a sequence of operations, because reading a single array element at a random index does not in fact have some sort of inherent, magical locality. And if you're walking an entire array, you are still going to have to translate a linear number of pages at O(log K) per translation, even if you're only falling into that O(log K) expensive case 1/whatever-th as often as you would if you were walking a linked list.

Yeah, I should've specified that random access in general is not O(1), not just for the case of lists.

However I stand by the fact that sequential walk through array is O(N) (ok, N + K), because only the first access is random, where the other ones are easily predictable.

Xarn
Jun 26, 2015

UraniumAnchor posted:

A bit old but it popped up in my Twitter feed today and it seems relevant:

http://gwan.ch/blog/20160405.html

(Coding interview horrors.)

I can sorta sympathize with getting an interviewer who checks answers by comparing them with the magic text on his paper being pain, but based on his writing I really, really wouldn't want to work with that guy.

Coffee Mugshot
Jun 26, 2010

by Lowtax
Was the interviewing process bad? Yes.
Did it successfully weed out an unqualified candidate? Yes.

Seems good to me.

UraniumAnchor
May 21, 2006

Not a walrus.

Coffee Mugshot posted:

Was the interviewing process bad? Yes.
Did it successfully weed out an unqualified candidate? Yes.

Seems good to me.

Well I never said that the interviewee wasn't a horror too. :v:

hackbunny
Jul 22, 2007

I haven't been on SA for years but the person who gave me my previous av as a joke felt guilty for doing so and decided to get me a non-shitty av
His only fault is that he's old :shrug:

Linear Zoetrope
Nov 28, 2011

A hero must cook

Volte posted:

He doesn't even answer the quicksort question (merely states that the question is invalid)

In fairness, "What's the best sorting algorithm" is a bad question for a Recruiter Bot screen, while being a potentially great question for a technical interview, because it depends on a lot. Most in-use general purpose sorting algorithms are hybrid sorts anyway. While quicksort-based algorithms are slightly more common (and avoid quicksort's nasty worst case), mergesort based ones are definitely not unheard of. In general, I'd expect both mergesort and quicksort to be a good off-the-cuff answer to the question, not just quicksort. Noting, of course, the standard caveat that this is just for blobs of arbitrary real world data and if you know the specifics of your data's format other algorithms may be more suitable.

This is again assuming the interview was presented faithfully and such.

Linear Zoetrope fucked around with this message at 10:04 on Oct 17, 2016

TheresaJayne
Jul 1, 2011

Jsor posted:

In fairness, "What's the best sorting algorithm" is a bad question for a Recruiter Bot screen, while being a potentially great question for a technical interview, because it depends on a lot. Most in-use general purpose sorting algorithms are hybrid sorts anyway. While quicksort-based algorithms are slightly more common (and avoid quicksort's nasty worst case), mergesort based ones are definitely not unheard of. In general, I'd expect both mergesort and quicksort to be a good off-the-cuff answer to the question, not just quicksort. Noting, of course, the standard caveat that this is just for blobs of real world data and if you know specifics other algorithms may be more suitable.

This is again assuming the interview was presented faithfully and such.

I think the point is that the interviewer had no knowledge and was just using the answers on the sheet, so unless the person said exactly what was on the sheet they failed.

The questions are not bad, the way they were asked and the lack of understanding of the subject was the horror. From the article it was obvious that the interviewee was possibly overqualified for the position but the interview drone had no idea what he was saying just that it did not match the answer on his sheet.

dougdrums
Feb 25, 2005
CLIENT REQUESTED ELECTRONIC FUNDING RECEIPT (FUNDS NOW)

hackbunny posted:

His only fault is that he's old :shrug:

Hah yeah to be honest in 25 years I'll probably be ranting on my holoblog about how the interviewer at the TRUMP CyberRealm was just reading poo poo off of his padd even though I'm totally qualified for Prince of Engineering or whatever. I can't really blame him for it.

hyphz
Aug 5, 2003

Number 1 Nerd Tear Farmer 2022.

Keep it up, champ.

Also you're a skeleton warrior now. Kree.
Unlockable Ben

TheresaJayne posted:

The questions are not bad, the way they were asked and the lack of understanding of the subject was the horror. From the article it was obvious that the interviewee was possibly overqualified for the position but the interview drone had no idea what he was saying just that it did not match the answer on his sheet.

Yea, if that "returns an inode" thing had been on a college exam any decent moderator would have given the paper author a clip round the ear. Any wording error like that and people are going to think it's a trick question. Heck, when he said "count the bits" I couldn't help but think "um, you mean count the 1 bits, right? Otherwise you just multiply 10000 by 16.."

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt

Xarn
Jun 26, 2015

Name and shame.

Volte
Oct 4, 2004

woosh woosh
I hope there's also a 7 character maximum for the password. And passwords may only contain lowercase letters and numbers. You know, like my bank

Xarn
Jun 26, 2015

Volte posted:

I hope there's also a 7 character maximum for the password. And passwords may only contain lowercase letters and numbers. You know, like my bank

That sounds suspiciously like my own bank, except the password is set to 8 characters and is autogenerated for you. At least every single action requires 2FA from SMS I guess. :v:

Polio Vax Scene
Apr 5, 2009




No way.

xzzy
Mar 5, 2009

I'm going to guess someone's nephew set it up, after reading a tutorial on mysql put a unique constraint on the password field to OPTIMIZE FOR SPEED!!!

Too bad they missed the tutorial on not storing plaintext passwords you idiot.

Bognar
Aug 4, 2011

I am the queen of France
Hot Rope Guy

xzzy posted:

Too bad they missed the tutorial on not storing plaintext passwords you idiot.

You don't need to store in plaintext to check if another user is using the password.

Volte
Oct 4, 2004

woosh woosh

xzzy posted:

I'm going to guess someone's nephew set it up, after reading a tutorial on mysql put a unique constraint on the password field to OPTIMIZE FOR SPEED!!!

Too bad they missed the tutorial on not storing plaintext passwords you idiot.
Hey now, there's no reason to assume they are storing plaintext passwords like idiots. They could be storing unsalted hashes like idiots.

Corla Plankun
May 8, 2007

improve the lives of everyone
But then some other user could just be using a password that hashes the same!

xzzy
Mar 5, 2009

I will continue to assume that anyone who requires a password to be unique among all users is not hashing them, because no one that dumb would even know the terms "hash" and "salt" apply to computers.

Sedro
Dec 31, 2008
My bank disables paste on their password fields for maximum security

necrobobsledder
Mar 21, 2005
Lay down your soul to the gods rock 'n roll
Nap Ghost
The thing that bugs me about bank security is how they can get away with so many bad password rules for retail banking sites while everything after that point (until it reaches some 45-year old COBOL program) is second in paranoia only to DoD standards for encryption and security. It seems extremely short-sighted and hypocritical to be so tight on security in places perhaps less susceptible to massive attack vectors.

Volte
Oct 4, 2004

woosh woosh
They probably don't want to constantly have to deal with old people who forgot their online banking password, so they practically force it to be their son's name or something.

xzzy
Mar 5, 2009

Sedro posted:

My bank disables paste on their password fields for maximum security

Too bad they haven't come up with a way to deal with the fact that the browser is under the control of the user.

http://www.prioritized.net/blog/re-enabling-password-pasting-on-annoying-web-forms

HFX
Nov 29, 2004

xzzy posted:

Too bad they haven't come up with a way to deal with the fact that the browser is under the control of the user.

http://www.prioritized.net/blog/re-enabling-password-pasting-on-annoying-web-forms

More effort than I should need especially when I'm using a probably more secure method than typing it from memory.

qntm
Jun 17, 2009

necrobobsledder posted:

The thing that bugs me about bank security is how they can get away with so many bad password rules for retail banking sites while everything after that point (until it reaches some 45-year old COBOL program) is second in paranoia only to DoD standards for encryption and security. It seems extremely short-sighted and hypocritical to be so tight on security in places perhaps less susceptible to massive attack vectors.

The thing that bugs me about bank security is how every bank's website I've ever seen is using plain HTTP. Not the customer portal, that's always HTTPS, and that's the part that counts, I guess. But why not just secure the entire operation from top to bottom?

boo_radley
Dec 30, 2005

Politeness costs nothing
from twitter this morning:

xzzy
Mar 5, 2009

qntm posted:

The thing that bugs me about bank security is how every bank's website I've ever seen is using plain HTTP. Not the customer portal, that's always HTTPS, and that's the part that counts, I guess. But why not just secure the entire operation from top to bottom?

Apparently not true anymore because I just visited all the major banks I could think of and they all redirect to https.

Polio Vax Scene
Apr 5, 2009



Hah, just visited my bank's website through https and it redirected to http.

It's a small bank in a 1k pop town though so I can't be mad.

Adbot
ADBOT LOVES YOU

necrobobsledder
Mar 21, 2005
Lay down your soul to the gods rock 'n roll
Nap Ghost
Then again, most of the population has piddly little bits of cash in their accounts so maybe for retail banking it's more cost-effective to keep PEBKAC problems down than to risk millions of $150 balances to hackers. Most of the big credit card and bank heists have been conducted against their internal networks rather than Internet endpoints.

A liberal interpretation of Jython I suppose.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply