Reference no: EM131263030
Problem Set
1. [6] Here is a version of binary search that returns the index of the element if it is found, or -1 if the element is not found.
1 def binary_search (A , x ):
2 '''
3 Pre : list A is sorted in ascending order and has no duplicate elements
4 Post : return the index of x in A if exists ; return -1 otherwise .
5 '''
6 if len ( A ) == 0:
7 return -1
8 m = len ( A )//2
9 if A [ m ] == x :
10 return m
11 elif A [ m ] > x :
12 return binary_search ( A [0.. m -1] , x )
13 else :
14 result = binary_search ( A [ m +1.. len ( A ) -1] , x )
15 if result == -1:
16 return -1
17 else :
18 return result + m + 1
(a) Write the recurrence for the worst-case runtime T(n) of the algorithm, and use the master theorem to find the asymptotic upper-bound on T(n). State clearly which case of the master theorem applies.
(b) Prove that this algorithm is correct.
2. Below is the mystery algorithm that we worked on in Problem Set.
1 def mystery ( lst ):
2 if len ( lst ) <= 1:
3 return
4 if lst [0] > lst [ -1]:
5 lst [0] , lst [ -1] = lst [ -1] , lst [0]
6 if len ( lst ) >= 3:
7 split = len ( lst ) // 3
8 mystery ( lst [0.. len ( lst ) - split - 1])
9 mystery ( lst [ split .. len ( lst ) - 1])
10 mystery ( lst [0.. len ( lst ) - split - 1])
We analyzed that the recurrence of the worst-case runtime of this algorithm is the following.
Some students have already realized that this algorithm is in fact a sorting algorithm. So in this problem set we will formalize our understanding of this interesting sorting algorithm.
(a) Find the asymptotic upper-bound on the worst-case runtime of mystery using the master theorem. State clearly which case of the master theorem applies.
(b) State the proper precondition and postconditi on for the mystery function. Note: "proper" precondition means that it is necessary and sufficient for the algorithm to work correctly. In particular, don't add unnecessary conditions.
(c) Prove that mystery is correct according to the precondition and postcondition that you specified in (b). Note: Be careful when finding the possible program paths, and state clearly which lines of code are executed for each program path (use the line numbers).
Assignment - Please follow all the instructions and write step by steps
https://www.cs.toronto.edu/~ylzhang/csc236/files/ps6.pdf
Lecture Notes
https://www.cs.toronto.edu/~ylzhang/csc236/files/lec07-master-theorem-correctness.pdf
https://www.cs.toronto.edu/~ylzhang/csc236/files/lec08-loop-invariant.pdf
Explain the descriptions of generations from traditionalists
: Analyze the descriptions of generations from traditionalists to Generation. Assess your own category and discuss the ways you agree and differ from the description, indicating which generation best describes you.
|
Provide 2 rn interventions for each goal that you developed
: Provide 2 RN interventions for each goal that you developed in #1. Provide rationale for each intervention being performed by an RN. Short term goals can usually be achieved by the end of your shift. Long term goals are usually achieved by discha..
|
Arise in the field of human resource
: The textbook identified several issues that arise in the field of human resource (HR) management. Sum up the responsibility of HR management to address and solve these problems.
|
The investing activities section of statement of cash flows
: During Benson most recent fiscal year, beginning plant assets, net of depreciation totaled $150,000 and the ending plant assets totaled $187,500. How much will be reported as cash received from the sale of equipment in the investing activities sectio..
|
Write the recurrence for the worst-case runtime
: CSC236 - Problem Set. Write the recurrence for the worst-case runtime T(n) of the algorithm, and use the master theorem to find the asymptotic upper-bound on T(n). State clearly which case of the master theorem applies
|
Examples of best practices an organization
: Discuss and provide examples of best practices an organization can implement to leverage diversity in areas such as group management, recruiting, hiring, retention, and development practices to increase an organization's competitive advantage.
|
What is the difference between a mediator and an arbitrator
: What is the primary reason for your personal conflicts? Your work conflicts? - What is meant by "ownership of the problem"?
|
Calculate break-even point in number of passenger flights
: Comfi Airways, Inc., a small two-plane passenger airline, has asked for your assistance in some basic analysis of its operations. Both planes seat 10 passengers each, and they fly commuters from Comfi’s base airport to the major city in the state, Me..
|
Prepare a persuasive proposal report
: You're company specializes in providing state of the art computer based networking systems to other companies as a way of keeping them in touch with modern technologies in the work place.
|