Suppose that you are writing some sort of recursive
function on a tree, which is in the x=change(x) style. What are the parameters,
and what does it return?
Answer:
There
is one parameter and
And
it will return the x
Some programmers like to write recursive methods, such as
bst_insert(), as methods inside the node class. But in this class, I've
encouraged you to write functions which are not methods of any class, instead
taking the root of the tree as a parameter.
Why did I argue for this style? What advantage does it have over
a method?
Answer:
Because using recursion it will check the all condition present in
change of (x)
Which help to looping the values present in x then it will store the
value in x.
And it will make efficient to
binary search tree algorithm.
What is the runtime cost of the function below? This question is
multiple choice

O(n^2)
Give an example of an array operation that has an average
runtime complexity of O(n):
Answer:
·
Linear Search
def search_ Linear(array,
n, value):
for i in range (0, n):
if (array[i]
== value):
return i;
return 1;
Explain why the algorithm you chose runs in
O(n).
Answer:
In
this case, the algorithm always takes the same amount of time to execute,
regardless of the input size. This is the ideal runtime for an algorithm, but
it’s rarely achievable.
In actual instances, the performance (Runtime) of an set of rules relies upon
on n, that is the size of the input or the variety of operations is required
for every input item. In general one for loop is corresponding to O(n)
A linear algorithm – O(n)
Runtime grows directly in proportion to n.