Design and analysis of algorithms assignment Nov 24
Design and analysis of algorithms assignment Nov 24
a. For each of the following functions which was used to monitor order of growth.
indicate how much the function’s value will change if it’s arguments is increased
fourfold, and indicate which one will not be affected much by large input and which
one will.
i. √𝑛
ii. n
iii. log 2 𝑛
iv. 𝑛2
b. Suppose tA = O (n2) and tB = θ (n2). Calculate the total computation time for the
following.
c. One of the common divide and conquer algorithms is Binary search using binary search
tree. The find, insert and delete algorithms start at the tree root and follow a path down
to, at worst case, the leaf at the very lowest level. The total number of steps of these
algorithms is, therefore, the largest level of the tree, which is called the depth (d) of the
tree.
i. Using an example, illustrate that the total number of nodes n for a full binary
tree with depth d is given by the equation: n= 2d+1 – 1
ii. Considering the formula n= 2d+1 – 1 above for the number of nodes in a
full binary search tree. Show that the runtime of the algorithms is O(lo
iii. Compute the cost/runtime of a full binary search tree of 16 nodes
d. There are 22 gloves in a drawer, 5 pairs of red gloves,4 pairs of yellow and 2 pair of
green. You select the gloves in the dark and can check them only after a selection has
been made. What is the smallest number of gloves you need to select to have at least
one matching pair in the best case and worst case?