您的位置:首页 > 编程语言 > Go语言

Solution for exercise 1.2-3 in Introduction to Algorithms

2006-03-21 15:14 471 查看
Consider the problem of determining whether an arbitrary sequence (x1, x2, . . . , xn) of n numbers contains repeated occurrences of some number. Show that this can be done in θ(n lg n) time, where lg n stands for log2n.
Solution 1: Any sorting algorithms having log2n complexity will be a capable to solve it in θ(n lg n) time.

Solution 2: If the domain of the sequence is not big, this problem can be solved in θ(n) time using the counting method, compute count[Xi] in the first loop, then find if there is any count[Xi] bigger than 1.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  sorting numbers domain