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 .
Data Structures and Programming Methodology CS61
jia V iuww5202024-07-09 8:32
相关推荐
大可-2 小时前
Go Air 热重载安装配置指南2401_894915532 小时前
Geo 优化源码部署避坑指南:解决访问异常、定位失效、收录卡顿问题Dovis(誓平步青云)2 小时前
《 固井工程软件 Cemsol 的数据管理与国产化适配实践》大模型码小白2 小时前
AI安全前沿:AI大模型安全防护的前沿技术evans在进步2 小时前
LeetCode 34:在排序数组中查找元素的首尾位置——Java 两次二分查找详解@卓越俊逸_角立杰出@2 小时前
java实现Agent+ReAct demo(Spring Boot + Spring AI Alibaba ReAct Agent)看浪的路人2 小时前
第6讲:SQL 解析器weixin_440784112 小时前
【OkHttp实现原理】a3535413823 小时前
C++项目如何架构优化AC赳赳老秦3 小时前
官方技术文档聚合实践:用 OpenClaw 批量抓取开源项目文档,构建离线可检索技术知识库