Data Structure and Algorithms Assignment
Data Structure and Algorithms Assignment
ASSIGNMENT
QUESTION-01: DEFINE ARRAY
ANSWER:
In programming, a series of objects all of which are the same size and type.
Each object in an array is called an array element. For example, you could
have an array of integers or an array of characters or an array of anything
that has a defined data type. The important characteristics of an array are:
Each element has the same data type (although they may have different
values).
The entire array is stored contiguously in memory (that is, there are no gaps
between elements).
Arrays can have more than one dimension. A one-dimensional array is called
a vector ; a two-dimensional array is called a matrix.
EXPLAIN ALGORITHM FOR INSERTING ELEMENTS IN AN ARRAY?
ARRAY Insertion
Inserting an element at end of linear array can be done easily if the array is
large
enough
to
accommodate
new
item.
If the element is to be inserted in the middle of array then half members
must be moved downward to new location to accommodate new element by
keeping
the
order
of
other
elements
ARRAY INSERTION ALGORITHM
Algorithm for Insertion: (Inserting into Linear Array) INSERT (LA, N, K, ITEM)
1. [Initialize counter] Set J: = N.
2. Repeat Steps 3 and 4 while j >= k;
3. [Move jth element downward.] Set LA [J + 1]: =LA [J].
4. [Decrease counter] Set J: = J-1
>> The function f(n) = (g(n)) iff there exist positive constants c and n0
such that f(n) c * g(n) for all n, n n0.
>> The statement f(n) = (g(n)) states only that g(n) is only a lower bound
on the value of f(n) for all n, n no.
Theta Notation ()
>> (g(n)) = { f(n) : there exist positive constants c1 and c2 and n0 such
that 0 < c1 * g(n) < f(n) < c2 * g(n) for all n > n0 }
>> The function f(n) = (g(n)) iff there exist positive constants C1, C2 and
n0 such that C1 * g(n) f(n) C2 * g(n) for all n, n n0.
Little oh Notation (o)
>> o(g(n)) = { f(n) : for any positive constant c>0 , there exists a constant
n0 such that 0 < f(n) < c * g(n) for all n > n0 }
>> We use o notation to denote an upper bound that is not asymptotically
tight.
>> The definitions of O-notation and o-notation are similar. The main
difference is that in f(n) =O(g(n)), the bound 0 < f(n) < c*g(n) holds for some
constant c>0 but in f(n) =O(g(n)), the bound 0 < f(n) < c *g(n) holds for all
constants c > 0.
Little omega Notation (w)
>> w(g(n)) = { f(n) : for any positive constant c>0 , there exists a constant
n0 such that 0 < c * g (n) < f(n) for all n > n0 }
>> We use w notation to denote an lower bound that is not asymptotically
tight.