3 4 6 7 8 N: number of elements in array A x: integer number 2: integer number <10 function X(A,N,x,z) count-0 OO 9 10 11 12 13 14 15 end function 16 What are the best and worst case time complexities of this algorithm? O best case is Theta(a) and worst case is Theta(z) best case is Theta(z) and worst case is Theta(N) none of the others for 0 <- 1 < N if(A[1]--x) count-count+1 if(count>z) return true return false;

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter9: Advanced Array Concepts
Section: Chapter Questions
Problem 14RQ
icon
Related questions
Question
M9
9. The following algorithm returns the Boolean value true if the array has more than z elements equal to x and false
otherwise.
2
A: array
3
N: number of elements in array A
4
x: integer number
5
2: integer number < 10
6
7
function X(A,N,X, Z)
count-0
for 0 < 1< N
if(A[i]--x)
if(count>z)
8
9
10
11
12
13
14
15
end function
16
What are the best and worst case time complexities of this algorithm?
O best case is Theta(z) and worst case is Theta(z)
O best case is Theta(z) and worst case is Theta(N)
none of the others
best and worst cases are Theta(N)
O best case is Theta (1) and worst case is Theta (N)
count-count+1
return true
return false
Transcribed Image Text:9. The following algorithm returns the Boolean value true if the array has more than z elements equal to x and false otherwise. 2 A: array 3 N: number of elements in array A 4 x: integer number 5 2: integer number < 10 6 7 function X(A,N,X, Z) count-0 for 0 < 1< N if(A[i]--x) if(count>z) 8 9 10 11 12 13 14 15 end function 16 What are the best and worst case time complexities of this algorithm? O best case is Theta(z) and worst case is Theta(z) O best case is Theta(z) and worst case is Theta(N) none of the others best and worst cases are Theta(N) O best case is Theta (1) and worst case is Theta (N) count-count+1 return true return false
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage