文学城论坛
+A-

Loop in single linked list

外-国人 2009-05-15 07:55:51 ( reads)

Wow, 几天不见,这里正热闹,看来还是Progromers比Mathematician多。怪不得康MM被气得离家出走了。:)
既然大家对Programing感兴趣,给大家做一个。不过,哪位想Progrom也可以。
Any language is ok.

(An interview question)
Given a single linked list with n items.
Find an O(n) algorithm to detect any loops.

跟帖(23)

endofsuburbia

2009-05-15 09:26:24

这题很经典

haha2000

2009-05-15 12:51:13

2X追就可了。。。

戏雨飞鹰

2009-05-15 14:46:34

没错。设置两个pointers,一个追另一个。追上为有Loop。

外-国人

2009-05-17 11:03:27

回复:没错。设置两个pointers,一个追另一个。追上为有Loop。

dynamic

2009-05-18 09:43:31

a similar but harder problem

haha2000

2009-05-18 09:52:57

sum mod n

乱弹

2009-05-18 10:01:54

I asked a similar question in an interview.

dynamic

2009-05-18 10:48:03

you are definitely right... I need to fix it :)

dynamic

2009-05-18 10:51:26

fix of the problem

haha2000

2009-05-18 19:19:21

algorithmic complexity requirement?

haha2000

2009-05-18 19:42:41

can be done in linear time...

dynamic

2009-05-18 19:55:29

it takes a bit more than that

戏雨飞鹰

2009-05-18 21:12:19

hmm,这个有意思:)

utopian

2009-05-20 17:23:11

回复:it takes a bit more than that

dynamic

2009-05-20 17:28:12

hashing needs linear memory as well. we want constant memory her

乱弹

2009-05-20 19:24:24

Pay attention to some key numbers.

haha2000

2009-05-21 07:24:10

觉得在哪里见过这个题目

乱弹

2009-05-21 09:52:29

I don't think so.

戏雨飞鹰

2009-05-21 12:22:12

这题目是IMB 2004 一月的一个puzzle:)

haha2000

2009-05-22 11:05:23

Yes, right! thanks!

dynamic

2009-05-20 21:41:18

solution

戏雨飞鹰

2009-05-21 12:25:03

hmmm,佩服. "形状像一个勺子", haha...

戏雨飞鹰

2009-05-21 13:12:13

这个题目曾是微软的面试题目。但是没有了数组'read only'的条件,