Using Big O notation, indicate the time requirement of each of the following tasks in the worst case.
Computing the sum of the first n even integers by using a for loop
[ Choose ] O(1) O(2n) O(n*log n ) O(2^n) O(log n) O(n^2) O(n) O(2) O(n^3)
Displaying all n integers in an array
[ Choose ] O(1) O(2n) O(n*log n ) O(2^n) O(log n) O(n^2) O(n) O(2) O(n^3)
Displaying all n integers in a sorted linked chain
[ Choose ] O(1) O(2n) O(n*log n ) O(2^n) O(log n) O(n^2) O(n) O(2) O(n^3)
Displaying all n names in an array of linked chains
[ Choose ] O(1) O(2n) O(n*log n ) O(2^n) O(log n) O(n^2) O(n) O(2) O(n^3)
Displaying one array element
[ Choose ] O(1) O(2n) O(n*log n ) O(2^n) O(log n) O(n^2) O(n) O(2) O(n^3)
Displaying the last integer in a linked chain
[ Choose ] O(1) O(2n) O(n*log n ) O(2^n) O(log n) O(n^2) O(n) O(2) O(n^3)
Searching an array of n items for a particular value by using a sequential search
[ Choose ] O(1) O(2n) O(n*log n ) O(2^n) O(log n) O(n^2) O(n) O(2) O(n^3)
Searching an array of n items for a particular value by using a binary search
[ Choose ] O(1) O(2n) O(n*log n ) O(2^n) O(log n) O(n^2) O(n) O(2) O(n^3)
Adding an item to a stack of n items
[ Choose ] O(1) O(2n) O(n*log n ) O(2^n) O(log n) O(n^2) O(n) O(2) O(n^3)
Adding an item to a bag of n items
[ Choose ] O(1) O(2n) O(n*log n ) O(2^n) O(log n) O(n^2) O(n) O(2) O(n^3)
Answer :
Computing the sum of the first n even integers by using a for loop : O(n).
Displaying all n integers in an array : O(n).
Displaying all n integers in a sorted linked chain : O(n).
Displaying all n names in an array of linked chains : O(n).
Displaying one array element : O(1).
Displaying the last integer in a linked chain : O(n).
Searching an array of n items for a particular value by using a sequential search : O(n).
Searching an array of n items for a particular value by using a binary search : O(log n).
Adding an item to a stack of n items : O(1).
Adding an item to a bag of n items : O(1).
Get Answers For Free
Most questions answered within 1 hours.