1 Asymptotics
(a) We have a function findMax that iterates through an unsorted int array once and returns the
maximum element found in that array. Give the tightest lower (Ω( · )) and upper bounds ( O ( · )) of
findMax in terms of N , the length of the array. Is it possible to define a Θ( · ) bound for findMax ?
(b) Give the worst case and best case runtime in terms of M and N . Assume ping is in Θ(1) and returns
an int .
1
for ( int i = N; i > 0; i--) {
2
for ( int j = 0; j <= M; j++) {
3
if (ping(i, j) > 64) break ;
4
}
5
}
(c) Below we have a function that returns true if every int has a duplicate in the array, and false if there
is any unique int in the array. Assume sort(array) is in Θ( N log N ) and returns array sorted.
1
public static boolean noUniques( int \[\] array) {
2
array = sort(array);
3
int N = array.length;
4
for ( int i = 0; i < N; i += 1) {
5
boolean hasDuplicate = false ;
6
for ( int j = 0; j < N; j += 1) {
7
if (i != j && arrayi == arrayj) {
8
hasDuplicate = true ;
9
}
10
}
11
if (!hasDuplicate) return false ;
12
}
13
return true ;
14
}
Give the worst case and best case runtime in Θ( · ) notation, where N = array.length .
Data Structures and Programming Methodology CS61
jia V iuww5202024-07-09 8:32
相关推荐
karry_k12 小时前
MyBatis批量insert-select踩坑:useGeneratedKeys=true 可能让PostgreSQL返回大量插入结果karry_k12 小时前
PostgreSQL 在 MyBatis 中执行正常 SQL 失效:一次 DELETE USING 踩坑记录vibecoding日记14 小时前
双非如何快速入职字节等大厂大模型?真实案例分析:推理优化和投机解码yszaygr213816 小时前
Verilog参数化游程编码RLE模块SamDeepThinking16 小时前
从源码到代码:MyBatis-Flex 与 MyBatis-Plus 的逐项对比望易16 小时前
刚设计的大模型架构-双域耦合认知框架她的男孩19 小时前
Spring Boot 接 Flowable 工作流:用 3 个注解搭一个请假审批流程复杂网络20 小时前
多个 Claude Code 与多个 Codex 协同工作:设计与实现方案荣码21 小时前
LLM结构化输出:让AI返回JSON而不是废话,我踩了4个坑