Data Structures and Programming Methodology CS61

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 .

相关推荐
devpotato2 分钟前
缓存与数据库更新顺序不一致问题
java·数据库·redis
shehuiyuelaiyuehao4 分钟前
算法34,位运算符操作,总结
算法
问天_观心6 分钟前
大模型微调学习(一)
开发语言·人工智能·学习·语言模型·github
阿里嘎多学长11 分钟前
2026-09-03 GitHub 热点项目精选
开发语言·程序员·github·代码托管
xcl092513 分钟前
酒馆预约系统开发实战:从需求分析到上线全流程指南
java·spring boot·需求分析
Navigator_Z17 分钟前
LeetCode //C - 1224. Maximum Equal Frequency
c语言·算法·leetcode
Kyrie_kk22 分钟前
Java--IO--Path文件访问
java·后端
qinqinzqq26 分钟前
Maven POM 格式、Schema 与 XSD:一篇讲透
java·maven
o盟44 分钟前
maven本地仓库有 总是去私仓中下载
java·maven·intellij-idea
devpotato1 小时前
Java 批量并发请求:从“能并发“到“结果按完成顺序可用“的三种写法与选型
java