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 .

相关推荐
可爱系程序猿几秒前
msvcp140_codecvt_ids.dll 缺失的排查记录:C++ 程序启动异常时如何核对运行库版本
开发语言·c++·程序人生·电脑
weixin_4407841110 分钟前
【IntentSeivice实现原理】
android·java·开发语言·intentservice
IanSkunk20 分钟前
企业AI Agent生产化落地:从技术架构到实施服务的全链路分析
java·人工智能·架构
岁岁养乐多39 分钟前
Java 序列化相关问题
java·开发语言
CAE二次开发工程师1 小时前
【C语言入门到精通】-基础篇
c语言·开发语言·python
深圳市快瞳科技有限公司1 小时前
个体识别、行为解读、健康管理:多模态宠物AI大模型的场景化落地
人工智能·算法·计算机视觉·大模型·多模态·宠物·宠物ai识别
AAIshangyanxiu1 小时前
涡度通量碳观测数据 MATLAB 全流程解析与敏感性定量分析、观测数据质控、插补及 footprint 建模技术
开发语言·matlab·涡度通量·生态碳汇·生态碳汇模拟
liulilittle1 小时前
归一化:激活函数
人工智能·算法·机器学习·llm
小短腿乄1 小时前
java实现pdf加水印+签名
java·开发语言·pdf
云烟成雨TD2 小时前
Micrometer 系列【29】源码分析:MeterRegistry 实例化流程
java·云原生·micrometer