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 .

相关推荐
没钥匙的锁112 分钟前
05-Java面向对象构造器与封装
java·开发语言
仙人球部落16 分钟前
-python-LangGraph框架(3-31-LangGraph 「合并式状态管理」的原理与实践)
开发语言·javascript·python
2401_8949155319 分钟前
Geo搜索优化排名源码部署搭建全流程详解
android·开发语言·flask·php·精选
Yang_jie_0333 分钟前
笔记:数据结构(栈是否使用底指针以及头指针的初始化值)
数据结构·笔记·算法
aaPIXa62238 分钟前
C++采样引导优化SPGO——比PGO更智能的编译器决策新方案
java·c++·人工智能
蓝银草同学1 小时前
Stream 实战:博客列表排序、过滤与分页(AI 辅助学习 Java 8)
java·前端·后端
2301_800895101 小时前
信息安全数学基础复习
算法
爱折腾的小黑牛1 小时前
简记往来批量录入功能的实现:从文本到结构化数据
前端·算法
chouchuang1 小时前
day-025-面向对象-上
开发语言·python
Starmoon_dhw1 小时前
题解:P17078 夏日甜点
c++·学习·算法·图论