Dominion Strategy Forum

Please login or register.

Login with username, password and session length
Pages: 1 ... 113 114 [115] 116 117 ... 123  All

Author Topic: Random Stuff Part III  (Read 653054 times)

0 Members and 1 Guest are viewing this topic.

gkrieg13

  • Minion
  • *****
  • Offline Offline
  • Posts: 509
  • Shuffle iT Username: gkrieg
  • Respect: +463
    • View Profile
Re: Random Stuff Part III
« Reply #2850 on: October 01, 2017, 01:47:39 am »
0

My brother, during a job interview, was asked to find the best algorithm to find the looping point of a linearly linked list that loops back to some point in the middle (so it looks like a P).  The best that we can come up with is n2 time, with constant space, or n time with n space.  However, the person doing the interview claimed that he had n time with constant space.  Can any of you think of the answer?  My brother and I have been trying to think of something to no avail.

Can you set the next pointer to null in each node as you go along?  That would ruin your linked list, but it would find the point for you when you get to a node with a null pointer. N time and constant space
Logged

sudgy

  • Cartographer
  • *****
  • Offline Offline
  • Posts: 3431
  • Shuffle iT Username: sudgy
  • It's pronounced "SOO-jee"
  • Respect: +2707
    • View Profile
Re: Random Stuff Part III
« Reply #2851 on: October 01, 2017, 01:51:25 am »
0

My brother, during a job interview, was asked to find the best algorithm to find the looping point of a linearly linked list that loops back to some point in the middle (so it looks like a P).  The best that we can come up with is n2 time, with constant space, or n time with n space.  However, the person doing the interview claimed that he had n time with constant space.  Can any of you think of the answer?  My brother and I have been trying to think of something to no avail.

Can you set the next pointer to null in each node as you go along?  That would ruin your linked list, but it would find the point for you when you get to a node with a null pointer. N time and constant space

Forgot to mention, you can't kill the list too.

(Actually, in the interview my brother found several solutions, including this one, and each time the interviewer asked if there was another way that was better in some way.)

Keep in mind that the guy could have been stupid too and he doesn't actually have a solution.  It would be hard to prove that though.
Logged
If you're wondering what my avatar is, watch this.

Check out my logic puzzle blog!

   Quote from: sudgy on June 31, 2011, 11:47:46 pm

gkrieg13

  • Minion
  • *****
  • Offline Offline
  • Posts: 509
  • Shuffle iT Username: gkrieg
  • Respect: +463
    • View Profile
Re: Random Stuff Part III
« Reply #2852 on: October 01, 2017, 02:34:05 am »
0

My brother, during a job interview, was asked to find the best algorithm to find the looping point of a linearly linked list that loops back to some point in the middle (so it looks like a P).  The best that we can come up with is n2 time, with constant space, or n time with n space.  However, the person doing the interview claimed that he had n time with constant space.  Can any of you think of the answer?  My brother and I have been trying to think of something to no avail.

Can you set the next pointer to null in each node as you go along?  That would ruin your linked list, but it would find the point for you when you get to a node with a null pointer. N time and constant space

Forgot to mention, you can't kill the list too.

(Actually, in the interview my brother found several solutions, including this one, and each time the interviewer asked if there was another way that was better in some way.)

Keep in mind that the guy could have been stupid too and he doesn't actually have a solution.  It would be hard to prove that though.

Are you allowed to move the list?  Pointers are really just numbers representing memory locations, so you could maybe move them so they are in order and then you know if you get back to the loop part when your pointer doesn’t point to a node anymore because it has been moved. But then you don’t know where in the list you were supposed to be pointing.

Hmmmmm
Logged

Donald X.

  • Dominion Designer
  • *****
  • Offline Offline
  • Posts: 6363
  • Respect: +25699
    • View Profile
Re: Random Stuff Part III
« Reply #2853 on: October 01, 2017, 03:06:36 am »
0

My brother, during a job interview, was asked to find the best algorithm to find the looping point of a linearly linked list that loops back to some point in the middle (so it looks like a P).  The best that we can come up with is n2 time, with constant space, or n time with n space.  However, the person doing the interview claimed that he had n time with constant space.  Can any of you think of the answer?  My brother and I have been trying to think of something to no avail.
I've heard this one before. There is an answer.
Logged

blueblimp

  • Margrave
  • *****
  • Offline Offline
  • Posts: 2849
  • Respect: +1559
    • View Profile
Re: Random Stuff Part III
« Reply #2854 on: October 01, 2017, 05:21:34 am »
0

My brother, during a job interview, was asked to find the best algorithm to find the looping point of a linearly linked list that loops back to some point in the middle (so it looks like a P).  The best that we can come up with is n2 time, with constant space, or n time with n space.  However, the person doing the interview claimed that he had n time with constant space.  Can any of you think of the answer?  My brother and I have been trying to think of something to no avail.
I was going to accuse that of being a bad interview question because I only knew one solution, which is a bit of a trick answer and not particularly relevant to algorithms you'd actually use. But then I looked up the problem and it turns out there are more easily discoverable algorithms, so maybe it's not so bad after all.

If you get stuck, look on Wikipedia for cycle detection.
Logged

liopoil

  • Margrave
  • *****
  • Offline Offline
  • Posts: 2587
  • Respect: +2479
    • View Profile
Re: Random Stuff Part III
« Reply #2855 on: October 01, 2017, 05:54:16 pm »
0

I'm not sure I understand the question. What exactly is n supposed to be? What information exactly are you given and what does each query or whatever tell you?
Logged

sitnaltax

  • Apprentice
  • *****
  • Offline Offline
  • Posts: 284
  • Respect: +490
    • View Profile
Re: Random Stuff Part III
« Reply #2856 on: October 01, 2017, 06:33:47 pm »
0

I'm not sure I understand the question. What exactly is n supposed to be? What information exactly are you given and what does each query or whatever tell you?

This is a slangy way of talking about the efficiency of the algorithm. n is the size of the list. When they're referring to an "n" or "n^2", they're referring to a solution that's O(n) or O(n^2), meaning that as the list grows in size, the time or space needed by the algorithm will grow only by that factor (times some constant) of the input size.

The Wikipedia article is overly technical; CS students get the basics without the tedious mathematical underpinnings, typically in an algorithms course. https://rob-bell.net/2009/06/a-beginners-guide-to-big-o-notation/ is a good quick intro.

Logged

liopoil

  • Margrave
  • *****
  • Offline Offline
  • Posts: 2587
  • Respect: +2479
    • View Profile
Re: Random Stuff Part III
« Reply #2857 on: October 01, 2017, 07:11:37 pm »
0

I know how run-time works in general, just not sure precisely what quantity n is referring to in this context. If it's the size of the list, I guess my question is exactly how the list is structured. Before I assumed that the list was infinite and it just started being periodic after some point and the period was around n or something. So now I don't have any real idea what a "linearly linked list" is. If it's like, each element points to its successor, or something, I'm not sure what stops you from just like going down the list until you get somewhere you've already been. If it's just a graph shaped like a P or something, then you're just looking for the vertex with degree three. I'm just trying to guess what this structure is at this point... I guess that's what I meant by "What information exactly are you given" - as in what's the data structure.
Logged

sudgy

  • Cartographer
  • *****
  • Offline Offline
  • Posts: 3431
  • Shuffle iT Username: sudgy
  • It's pronounced "SOO-jee"
  • Respect: +2707
    • View Profile
Re: Random Stuff Part III
« Reply #2858 on: October 01, 2017, 07:44:08 pm »
0

I know how run-time works in general, just not sure precisely what quantity n is referring to in this context. If it's the size of the list, I guess my question is exactly how the list is structured. Before I assumed that the list was infinite and it just started being periodic after some point and the period was around n or something. So now I don't have any real idea what a "linearly linked list" is. If it's like, each element points to its successor, or something, I'm not sure what stops you from just like going down the list until you get somewhere you've already been. If it's just a graph shaped like a P or something, then you're just looking for the vertex with degree three. I'm just trying to guess what this structure is at this point... I guess that's what I meant by "What information exactly are you given" - as in what's the data structure.

Code: [Select]
struct Node {
    Type data;
    Node* next;
};

With this, the only operation you can do to traverse the list is go to the next element in it.  You are given the first node, and that's it.
Logged
If you're wondering what my avatar is, watch this.

Check out my logic puzzle blog!

   Quote from: sudgy on June 31, 2011, 11:47:46 pm

silverspawn

  • Adventurer
  • ******
  • Offline Offline
  • Posts: 5318
  • Shuffle iT Username: sty.silver
  • Respect: +3224
    • View Profile
Re: Random Stuff Part III
« Reply #2859 on: October 02, 2017, 02:33:35 pm »
0

Apropos to nothing, this is totally worth rereading

Titandrake

  • Mountebank
  • *****
  • Offline Offline
  • Posts: 2210
  • Respect: +2856
    • View Profile
Re: Random Stuff Part III
« Reply #2860 on: October 03, 2017, 02:34:11 am »
0

If it's like, each element points to its successor, or something, I'm not sure what stops you from just like going down the list until you get somewhere you've already been.

Sure, you can do that, but how do you know if you're visiting a place again, if you're only allowed a constant amount of space to store things?

I agree with blueblimp that this doesn't seem like a good question, I only know the trick solution and it's more like a novelty. (Like the problem of switching a and b without defining a 3rd temporary variable.)
Logged
I have a blog! It's called Sorta Insightful. Check it out?

sudgy

  • Cartographer
  • *****
  • Offline Offline
  • Posts: 3431
  • Shuffle iT Username: sudgy
  • It's pronounced "SOO-jee"
  • Respect: +2707
    • View Profile
Re: Random Stuff Part III
« Reply #2861 on: October 03, 2017, 01:00:45 pm »
+1

If it's like, each element points to its successor, or something, I'm not sure what stops you from just like going down the list until you get somewhere you've already been.

Sure, you can do that, but how do you know if you're visiting a place again, if you're only allowed a constant amount of space to store things?

I agree with blueblimp that this doesn't seem like a good question, I only know the trick solution and it's more like a novelty. (Like the problem of switching a and b without defining a 3rd temporary variable.)

Trick solution?  I looked up the solutions and they don't seem like tricks to me.  Complicated, yes, but tricks, no.
Logged
If you're wondering what my avatar is, watch this.

Check out my logic puzzle blog!

   Quote from: sudgy on June 31, 2011, 11:47:46 pm

Kirian

  • Adventurer
  • ******
  • Offline Offline
  • Posts: 7096
  • Shuffle iT Username: Kirian
  • An Unbalanced Equation
  • Respect: +9412
    • View Profile
Re: Random Stuff Part III
« Reply #2862 on: October 03, 2017, 01:46:24 pm »
+1

Speaking of time constraints:

There isn't enough time to deeply learn everything I want to know about.
There isn't enough time to shallowly learn everything I want to know about.

There isn't even enough time to learn enough to make a list of the things I want to know about, even if I had started 39 years ago.  Mostly because I don't even know of the existence of many of these things.  (These thoughts are precipitated by reading an article on model-based design, which I hadn't heard of until today.)

This doesn't take into account motivation or available spoons, just actual time.

Someone try to cheer me up?
Logged
Kirian's Law of f.DS jokes:  Any sufficiently unexplained joke is indistinguishable from serious conversation.

LastFootnote

  • Adventurer
  • ******
  • Offline Offline
  • Posts: 7495
  • Shuffle iT Username: LastFootnote
  • Respect: +10722
    • View Profile
Re: Random Stuff Part III
« Reply #2863 on: October 03, 2017, 03:02:34 pm »
+5

Speaking of time constraints:

There isn't enough time to deeply learn everything I want to know about.
There isn't enough time to shallowly learn everything I want to know about.

There isn't even enough time to learn enough to make a list of the things I want to know about, even if I had started 39 years ago.  Mostly because I don't even know of the existence of many of these things.  (These thoughts are precipitated by reading an article on model-based design, which I hadn't heard of until today.)

This doesn't take into account motivation or available spoons, just actual time.

Someone try to cheer me up?

Your existence is ultimately meaningless. Any knowledge you do or do not acquire is unimportant.









Did it work?
Logged

Seprix

  • Adventurer
  • ******
  • Offline Offline
  • Posts: 5607
  • Respect: +3680
    • View Profile
Re: Random Stuff Part III
« Reply #2864 on: October 03, 2017, 04:06:07 pm »
0

Speaking of time constraints:

There isn't enough time to deeply learn everything I want to know about.
There isn't enough time to shallowly learn everything I want to know about.

There isn't even enough time to learn enough to make a list of the things I want to know about, even if I had started 39 years ago.  Mostly because I don't even know of the existence of many of these things.  (These thoughts are precipitated by reading an article on model-based design, which I hadn't heard of until today.)

This doesn't take into account motivation or available spoons, just actual time.

Someone try to cheer me up?

If you invest really hard in life extension/immortality, you might get more time.
Logged
DM me for ideas on a new article, either here or on Discord (I check Discord way more often)

Donald X.

  • Dominion Designer
  • *****
  • Offline Offline
  • Posts: 6363
  • Respect: +25699
    • View Profile
Re: Random Stuff Part III
« Reply #2865 on: October 03, 2017, 04:45:50 pm »
+5

Your existence is ultimately meaningless. Any knowledge you do or do not acquire is unimportant.
Meaning depends on context, which you provide (and I don't mean, the meaning of words, though, that too).

Devoid of context, meaninglessness is also meaningless. Meaninglessness only gets value from you assigning it value and well I don't recommend it.
Logged

Kirian

  • Adventurer
  • ******
  • Offline Offline
  • Posts: 7096
  • Shuffle iT Username: Kirian
  • An Unbalanced Equation
  • Respect: +9412
    • View Profile
Re: Random Stuff Part III
« Reply #2866 on: October 03, 2017, 05:08:45 pm »
0


Devoid of context, meaninglessness is also meaningless. Meaninglessness only gets value from you assigning it value and well I don't recommend it.


That is oddly comforting, actually.
Logged
Kirian's Law of f.DS jokes:  Any sufficiently unexplained joke is indistinguishable from serious conversation.

silverspawn

  • Adventurer
  • ******
  • Offline Offline
  • Posts: 5318
  • Shuffle iT Username: sty.silver
  • Respect: +3224
    • View Profile
Re: Random Stuff Part III
« Reply #2867 on: October 03, 2017, 05:33:30 pm »
0

I actually think pleasure and happiness are inherently meaningful.

Witherweaver

  • Adventurer
  • ******
  • Offline Offline
  • Posts: 6476
  • Shuffle iT Username: Witherweaver
  • Respect: +7866
    • View Profile
Re: Random Stuff Part III
« Reply #2868 on: October 04, 2017, 09:18:52 am »
0

Logged

crax

  • Coppersmith
  • ****
  • Offline Offline
  • Posts: 45
  • they/them pronouns but nbd if you mess up
  • Respect: +16
    • View Profile
Re: Random Stuff Part III
« Reply #2869 on: October 05, 2017, 01:19:31 pm »
0

Should I get an avatar?
Logged

Kuildeous

  • Cartographer
  • *****
  • Offline Offline
  • Posts: 3840
  • Respect: +2221
    • View Profile
Re: Random Stuff Part III
« Reply #2870 on: October 05, 2017, 02:23:25 pm »
0


Should I get an avatar?


If you don't, then someone will yell at you to choose an avatar. That's how I got this one.

I forgot who yelled at me. Was it Silverspawn? I want to say it was Silverspawn.
Logged
A man has no signature

Awaclus

  • Adventurer
  • ******
  • Offline Offline
  • Posts: 11815
  • Shuffle iT Username: Awaclus
  • (´。• ω •。`)
  • Respect: +12867
    • View Profile
    • Birds of Necama
Re: Random Stuff Part III
« Reply #2871 on: October 05, 2017, 02:27:32 pm »
+1

The problem with people not having avatars is that it's more difficult to tell them apart. It's not as big of a problem as having the same card art as someone else or just a very similar color scheme though.
Logged
Bomb, Cannon, and many of the Gunpowder cards can strongly effect gameplay, particularly in a destructive way

The YouTube channel where I make musicDownload my band's Creative Commons albums for free

Tables

  • Margrave
  • *****
  • Offline Offline
  • Posts: 2816
  • Build more Bridges in the King's Court!
  • Respect: +3349
    • View Profile
Re: Random Stuff Part III
« Reply #2872 on: October 05, 2017, 05:52:34 pm »
0

Having an avatar makes it look like you're a member of the community, rather than someone who just joined and is making a few quick posts. It makes you look a little more unique, rather than just a username posting.
Logged
...spin-offs are still better for all of the previously cited reasons.
But not strictly better, because the spinoff can have a different cost than the expansion.

ThetaSigma12

  • Torturer
  • *****
  • Offline Offline
  • Posts: 1681
  • Shuffle iT Username: ThetaSigma12
  • Respect: +1812
    • View Profile
Re: Random Stuff Part III
« Reply #2873 on: October 05, 2017, 07:25:59 pm »
+1

Having an avatar makes it look like you're a member of the community, rather than someone who just joined and is making a few quick posts. It makes you look a little more unique, rather than just a username posting.

The best avatars are either a painting of you or dominion art.
Logged
My magnum opus collection of dominion fan cards is available here!

Kuildeous

  • Cartographer
  • *****
  • Offline Offline
  • Posts: 3840
  • Respect: +2221
    • View Profile
Re: Random Stuff Part III
« Reply #2874 on: October 06, 2017, 12:27:48 am »
0

Having an avatar makes it look like you're a member of the community, rather than someone who just joined and is making a few quick posts.

I think my 3500+ posts may be a dead giveaway.

I know, not everyone is going to look, but yeesh. I don't normally bother with avatars.
Logged
A man has no signature
Pages: 1 ... 113 114 [115] 116 117 ... 123  All
 

Page created in 0.111 seconds with 21 queries.