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
相关推荐
三品吉他手会点灯3 小时前
C语言学习笔记 - 50.流程控制4 - 流程控制为什么非常非常重要huangdong_4 小时前
电商平台图片URL原图转换技术深度解析:从缩略图到高清原图的完整方案記億揺晃着的那天4 小时前
Java 调用外部 Go 程序的实践:ProcessBuilder 在生产环境中的应用JAVA面经实录9174 小时前
Java 数据结构与算法 (终极完整学习文档)JAVA面经实录9175 小时前
操作系统面试题一杯奶茶¥6 小时前
基于springboot的失物招领管理系统带万字文档 校园失物招领管理系统 失物认领管理系统java springboot vue在放️6 小时前
Python 爬虫 · 第三方代理接入与合规使用不能只会打代码6 小时前
边缘视频分析平台的架构设计与性能优化——从750ms到190ms的调优之路小刘|6 小时前
Spring AI Alibaba 集成和风天气 API 实战KANGBboy6 小时前
java知识五(继承)