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 .

相关推荐
千桐科技3 分钟前
DataX 执行引擎正式加入:qData 开源版 v1.6.0 新增 Quartz + DataX 轻量运行模式!
java·大数据·开源·数据治理·数据中台·qdata
微露清风8 分钟前
模拟算法学习记录
学习·算法
lzhdim12 分钟前
C# 中读取CPU、硬盘和内存温度
开发语言·c#
Irene199113 分钟前
Oracle PL/SQL Developer 版本差异(11g、14)实战总结
java·开发语言
AI人工智能+电脑小能手15 分钟前
【大白话说Java面试题 第191题】【08_Kafka篇】第7题:消息队列的优缺点
java·消息队列·系统设计·分布式架构·技术选型
用户4461394302718 分钟前
Spring Boot 接入大模型:从配置到实战的完整指南
java
青石路20 分钟前
如果写Redis序列化与读Redis序列化不一致,你觉得会发生什么
java·redis
qq_4480111621 分钟前
C语言中的getchar()
c语言·开发语言
煎饼学大模型25 分钟前
架构决定上限:Skill 知识架构的三次重构实践
java·重构·架构·skill
肖志-AI全栈26 分钟前
JavaScript 快速排序:从 pivot、双指针到分治思想
开发语言·javascript·排序算法