Assignment 2
Assignment 2
the dimension of an array is determined the moment the array is created, and
cannot be changed later on;
the array occupies an amount of memory that is proportional to its size,
independently of the number of elements that are actually of interest;
if we want to keep the elements of the collection ordered, and insert a new
value in its correct position, or remove it, then, for each such operation we may
need to move many elements (on the average, half of the elements of the array);
this is very inefficient
1. Prove formally, using the definition of asymptotic notation, that if f(n)=n and
g(n)=n 2 ,
3. Find a suitable data structure for the following questions and justify with a
statement,
a. A string contains letters and digits. A program removes digits from a string and
b. Given a number n, A function that generates and prints all binary numbers with
5. In the game of "twenty questions", your task is to guess the value of a secret
number that
is one of the n integers between 0 and n−1. For simplicity, we will assume that n is
a
power of 2 and that the questions are of the form "is the number greater than or
equal to
x?” What effective search strategy you will follow? Why?
7. Trace the following infix expressions into their equivalent postfix form.
8. A major problem in the normal Queue data structure is that even though we
have empty
positions in the queue we cannot make use of them to insert new element Is there
any way to overcome this problem ? Define.
9. Suppose the array A contains [7, 1, 6, 4, 9]. Do the quicksort algorithm where
the first
element in the array is used as pivot. What is the strategy does this algorithm
follow?
10. Show how the singly linked lists remove method works when the item to be
removed is
1. Consider the following function that computes the sum of the elements of an
array
iteratively:
int sum = 0;
n = a.size();
sum += a[i];
return sum; }
Write a recursive function that performs the same task. Depict the Series of
Recursive
infix expression and then evaluate the infix expression – True/False? Justify
b. Evaluate the following postfix expressions. Show the stack as each operand and
operator is processed.
823^/23*+51*-