The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Jul 2017 |
| Last Sign in: | 304 Weeks Ago, 1 Day Ago |
| Questions Answered: | 15833 |
| Tutorials Posted: | 15827 |
MBA,PHD, Juris Doctor
Strayer,Devery,Harvard University
Mar-1995 - Mar-2002
Manager Planning
WalMart
Mar-2001 - Feb-2009
1. Show that if d(n) is O( f (n)) and e(n) is O(g(n)), then the product d(n)e(n) is O( f (n)g(n)).
2. Give a big-Oh characterization, in terms of n, of the running time of the Ex1 function shown in Code Fragment 4.6.
Code Fragment 4.6: Some algorithms.
Algorithm Ex1(A):
Input: An array A storing n ≥ 1 integers.
Output: The sum of the elements in A.
s←A[0]
fori←1to n−1 do
s←s+A[i]
returns
Algorithm Ex2(A):
Input: An array A storing n ≥ 1 integers.
Output: The sum of the elements at even cells in A.
s←A[0]
fori←2to n−1 by increments of 2 do
s←s+A[i]
returns
Algorithm Ex3(A):
Input: An array A storing n ≥ 1 integers.
Output: The sum of the prefix sums in A.
s←0
fori←0to n−1 do
s←s+A[0]
forj←1 to i do
s←s+A[ j]
returns
Algorithm Ex4(A):
Input: An array A storing n ≥ 1 integers.
Output: The sum of the prefix sums in A.
s←A[0]
t←s
fori←1to n−1 do
s←s+A[i]
t←t +s
returnt
Algorithm Ex5(A,B):
Input: Arrays A and B each storing n ≥ 1 integers.
Output: The number of elements in B equal to the sum of prefix sums in A.
c←0
fori←0to n−1 do
s←0
forj←0 to n−1 do
s←s+A[0]
fork←1to j do
s←s+A[k]
ifB[i] = s then
c←c+1
returnc
----------- ----------- H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly