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 .

相关推荐
Omics Pro1 分钟前
预测性虚拟细胞中显式机理算子
大数据·数据库·人工智能·python·算法·机器学习·自然语言处理
驭渊的小故事3 分钟前
算法实战:滑动窗口、素数枚举与字符串模拟(三道经典题解)
java·算法
雪落漂泊3 分钟前
Linux基本指令(下)
java·linux·服务器
Eloudy4 分钟前
全文 - version.A - AMBA CHI Chip-to-Chip(C2C)
java·开发语言·数据库·gpu·chiplet
谁是谁的谁_bj7 分钟前
Process Lasso进程调度/资源管理工具
java
秋名RG12 分钟前
Java历代LTS版本新特性详解(代码增强版)
java·开发语言·python
李少兄12 分钟前
深度剖析 Hutool ObjectUtil
java·开发语言
牢姐与蒯13 分钟前
位运算及其oj题
c++·算法
魏码不凡13 分钟前
Go 编译报错:undefined: webp.Encode 问题排查与解决
开发语言·后端·golang
276695829214 分钟前
youdao/有道翻译APP 算法协议分析
开发语言·前端·python·sign·youdao·有道翻译app算法·有道app协议请求