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 .

相关推荐
此生决int3 小时前
深入理解C++系列(15)——AVL树
开发语言·c++
树獭哥3 小时前
量化金融入门:从数据规则到随机游走与凯利公式
人工智能·算法·金融·量化金融
筱璦3 小时前
PHP+ VUE3机构级股票分仓管理交易系统源码可出
开发语言·php·vue3·量化·股票分仓
爱奥尼欧3 小时前
10.C++ string 实现详解
java·开发语言·c++
小飞学编程...3 小时前
【equals 、Comparable、Comparator 三者的区别】
java·python
骇客野人3 小时前
Java分布式任务调度方案(完整落地指南)
java·开发语言·分布式
JacksonMx3 小时前
Spring @Async 坑点 + 改造方案
java·开发语言
你怎么知道我是队长3 小时前
IPv6 地址完全解析:从结构到实战
开发语言·php
薛定e的猫咪4 小时前
(arXiv 2026)GLiBRL :可学习基函数的深度贝叶斯元强化学习 ----待补充
人工智能·深度学习·学习·算法·机器学习
Dovis(誓平步青云)4 小时前
牛奶不能减成负数:冰箱库存的筛选、去重与不可变更新
android·java·开发语言