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 && array[i] == array[j]) {
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
相关推荐
我真的不会C15 分钟前
QT窗口相关控件及其属性CodeCraft Studio15 分钟前
Excel处理控件Aspose.Cells教程:使用 Python 在 Excel 中进行数据验.生产的驴19 分钟前
SpringBoot 封装统一API返回格式对象 标准化开发 请求封装 统一格式处理火柴盒zhang20 分钟前
websheet之 编辑器猿周LV27 分钟前
JMeter 安装及使用 [软件测试工具]景天科技苑28 分钟前
【Rust】Rust中的枚举与模式匹配,原理解析与应用实战知来者逆29 分钟前
计算机视觉——速度与精度的完美结合的实时目标检测算法RF-DETR详解晨集29 分钟前
Uni-App 多端电子合同开源项目介绍时间之城31 分钟前
笔记:记一次使用EasyExcel重写convertToExcelData方法无法读取@ExcelDictFormat注解的问题(已解决)阿让啊33 分钟前
C语言中操作字节的某一位