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 .

相关推荐
hetao17338373 小时前
2026-09-27~28 hetao1733837 的刷题记录
c++·算法
只睡四小时3 小时前
JS 手写 D-pad 空间导航:电视端焦点引擎实战
android·开发语言·前端·javascript·ecmascript·hls·空间导航
2601_962218613 小时前
C++的几种编译器的实现
开发语言·c++
Godspeed Zhao3 小时前
现代智能雷达技术15——算法(1)
人工智能·算法·雷达
代码什么用3 小时前
LeetCode-42. 接雨水
算法·leetcode
多弗朗皮卡丘3 小时前
C++ stack和queue
开发语言·c++·deque·queue·stack·容器适配器
lengxuenong3 小时前
枚举及其优化学习手册
c++·学习·算法·青少年编程
维克兜率天3 小时前
【维克】弹性策略:用“乖离率“捕捉超跌反弹
android·开发语言·python·深度学习·kotlin·量化
小O的算法实验室3 小时前
IEEE TAI,RoCo:基于角色的LLM协作实现自动启发式设计
算法
小范的技术工坊3 小时前
大模型蒸馏
人工智能·算法·数据挖掘·大模型