• Wrong document? Swap it for free
  • Written by students who passed
  • Immediately available after payment
  • Read online or as PDF
Sell
Where do you study
Your language
Document preview thumbnail
Preview 2 out of 6 pages
Other

COMP 3051 Algorithm Design and Analysis

Document preview thumbnail
Preview 2 out of 6 pages

Assignment 2 Instructions According to our suggested 16 week “Course Schedule,” you should complete and submit Assignment 2 by the Sunday at the end of Week 6. This assignment is worth 10% of your final grade. To receive full marks, answer each of the following questions in a clear and comprehensive manner. You can find the assignment marking criteria at the end of this document. Questions 1. Show that if f(n) is O(h(n)) and g(n) is O(i(n)), then f(n) + g(n) is O(h(n) + i(n)). [2 marks] 2. Show that 3(n + 1)7 + 2n log n is O(n7). Hint: Try applying the rules of Theorem 1.7. You will have to use the insert equations to answer this question. [2 marks] 3. Give an O(n)-time algorithm for computing the depth of each node of a tree T, where n is the number of nodes of T. Assume the existence of methods setDepth (v,d) and getDepth(v) that run in O(1) time. [2 marks] 4. What does the following algorithm do? Analyze its worst-case running time and express it using “Big-Oh” notation. [2 marks] Algorithm Foo (a,n): Input: two integers, a and n Output: ? k  0 b  1 while k n do k k + 1 b  b *a return b 5. a. Describe (in pseudo-code) a findAll Elements (k) method of an AVL tree T. It should run in O(logn + s) time where n is the size of T and s is the number of elements returned (i.e., the number of nodes in T whose key is k). b. Analyze the running time of your algorithm. [2 marks] Marking Criteria for Assignments You will be awarded full marks if your answer adequately answers the question addressed. Total marks = 10 You will be awarded partial marks if your answer demonstrates: • Application of the major and alternative approaches, methods, or algorithms to solve the problem. • Evidence of appropriate logic. • Evidence of correct computational skills and data structures. • Inclusion of appropriate comments or explanations. For details about how to submit this assignment, refer to the “Assignment Submission Instructions” under the Assignments Overview tab of your course.

Content preview

lOMoARcPSD|3013804




Assignment 2 - Article on
Alogrithms

Data structure (University of Central Punjab)

, lOMoARcPSD|3013804




COMP 3051: Algorithm Design and Analysis A2-1



Assignment 2

Instructions
According to our suggested 16 week “Course Schedule,” you should complete and
submit Assignment 2 by the Sunday at the end of Week 6. This assignment is worth
10% of your final grade. To receive full marks, answer each of the following questions
in a clear and comprehensive manner. You can find the assignment marking criteria at
the end of this document.

Questions
1. Show that if f(n) is O(h(n)) and g(n) is O(i(n)), then f(n) + g(n) is O(h(n) + i(n)).
[2 marks]
f(n) = O(h(n))
g(n) = O(i(n))
from the addition property of equality
f(n) + g(n) = O(h(n) + i(n))


2. Show that 3(n + 1)7 + 2n log n is O(n7). Hint: Try applying the rules of Theorem 1.7.
You will have to use the insert equations to answer this question. [2 marks]
According to rules of Proposition:
log n = O(n)
2nlog n = O(2n2)
3(n + 1)7 is a polynomial of degree 7, therefore it is O(n7)
3(n + 1)7 + 2nlog n = O(n7 + 2n2)
3(n + 1)7 + 2nlog n = O(n7)
3. Give an O(n)-time algorithm for computing the depth of each node of a tree T, where
n is the number of nodes of T. Assume the existence of methods setDepth (v,d) and
getDepth(v) that run in O(1) time. [2 marks]


depth (Tree, node):

if (Tree.isRoot(node)) then

setDepth(node, 0)

Document information

Uploaded on
May 24, 2022
Number of pages
6
Written in
2019/2020
Type
Other
Person
Unknown
$7.89

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
Sold
660
Followers
453
Items
1089
Last sold
5 days ago



Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions