为什么(n)在大符号示例中的值不同?

时间:2015-05-22 17:07:45

标签: algorithm big-o analysis

任何人都可以解释为什么示例4.10中的(n)的值大于或等于2,而在示例4.11中大于或等于1(请注意,在两个示例中,术语n log n都是现有的!)

例4.10:

<%yourPackage.YourClass.yourMethod()%>

理由:5n^2 + 3nlogn + 2n + 5 is O(n^2)

例4.11:

5n^2 + 3nlogn + 2n + 5 <= (5+3+2+5)n^2 = cn^2 , for c=15 , when n greater than or equal to 2  (note that n log n is zero for n = 1 ).

理由:20n^3 + 10nlogn + 5 is O(n^3)

1 个答案:

答案 0 :(得分:0)

如果存在f(n)这样的O(g(n)) C n0 f(n) <= C*g(n),则函数n>=n0被称为n0

此定义不需要n0=2的任何特定值。因此,在您的第一个示例n0=1中,在您的第二个示例n0中,但特定值对于big-O定义无关紧要,它只需要 some (any)存在这样的C

(但是,这个值对证明很重要,这就是价值不同的原因。)

另请注意,C=15常量也不同:第一个示例中为C=35,第二个示例中为@Document(collection = "AUTHOR") public class Author implements Serializable { @Id private String id; @Field("name") private String name; public String getId() {return id;} public void setId(String id) {this.id = id;} public String getName() {return name;} public void setName(String name) {this.name = name;} } @Document(collection = "BOOK") public class Book implements Serializable { @Id private String id; @Field("name") private String name; @DBRef(lazy = true) @Field("author") private Author author; public String getId() {return id;} public void setId(String id) {this.id = id;} public String getName() {return name;} public void setName(String name) {this.name = name;} public Author getAuthor() {return author;} public void setAuthor(Author author) {this.author = author;} }