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 && array[i] == array[j]) {
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
相关推荐
W.A委员会3 小时前
JS原型链详解止语Lab3 小时前
Go并发编程实战:Channel 还是 Mutex?一个场景驱动的选择框架她说彩礼65万4 小时前
C# 实现简单的日志打印绿浪19844 小时前
c# 中结构体 的定义字符串字段(性能优化)HoneyMoose4 小时前
Jenkins Cloudflare 部署提示错误阿丰资源4 小时前
基于SpringBoot的物流信息管理系统设计与实现(附资料)Predestination王瀞潞4 小时前
Java EE3-我独自整合(第四章:Spring bean标签的常见配置)overmind4 小时前
oeasy Python 121[专业选修]列表_多维列表运算_列表相加_列表相乘资深数据库专家4 小时前
总账EBS 应用服务器1 的监控分析房开民4 小时前
可变参数模板