Vous êtes sur la page 1sur 5

ECX 4265 – Data Structures and Algorithms

Assignment 01
D. S. K. Muthtettugoda. Reg. No. 709087643

Q1.
1.1.

 Often the algorithms with best time complexity are also the best for small data sets.

 It is worth to find good algorithms only for large data sets, as for small data set even
inefficient algorithms take short enough time. And for large data sets the best
algorithms take less time.

 If the best algorithm for a given problem has a really bad time complexity this
complexity gives an approximate size of the maximum data set that is solvable in a
reasonable time for the foreseeable future, even as computers get faster.

 As computers become faster and faster, it is more and more important to find
algorithms with low time complexity, as these algorithms take more advantage of
the progress in hardware than high time complexity algorithms.

1.2.

 O – Big oh Notation.

 Ω – Big Omega Notation.

 Θ –Big Theta Notation.

1.3.

O – Big oh Notation

This notation gives an upper bound for a function to within a constant factor. We write
f(n)=O(g(n)) if there are positive constants
n0 and c such that to the right of n0, the
value of f(n) always lies on or below cg(n).

1
ECX 4265 – Data Structures and Algorithms
Assignment 01
D. S. K. Muthtettugoda. Reg. No. 709087643

Ω – Big Omega Notation.

This notation gives a lower bound for a function to within a constant factor. We write

f(n) =Ω(g(n)) if there are positive constants


n0 and c such that to the right of n0, the
value of f(n) always lies on or above cg(n).

Θ –Big Theta Notation.

This notation bounds a function to within constant factors. We say f(n) = Θ(g(n)) if

there exist positive constants n0, c1 and c2 such


that to the right of n0 the value of f(n) always
lies between c1g(n) and c2g(n) inclusive.

2
ECX 4265 – Data Structures and Algorithms
Assignment 01
D. S. K. Muthtettugoda. Reg. No. 709087643

1.4.

Worst case is an upper bound on the running time. It gives us a guarantee that the
algorithm will never take any longer.

So to increase the running time of an algorithm with the size of input, an upper bound
notation such as Big – Oh can be selected.

Q2.

2.1.

2.1.1. -

2.1.2.

a. Insert

Void insertion(item a[], int N)


{
int i, j;
item temp;
for(i=0; i<n; i++)
{
j=i-1;
temp=a[i];
while((j>=0) && (a[j]>temp))
{
a[j+1] = a[j];
j--;
}
a[j+1]=temp;
}
}

3
ECX 4265 – Data Structures and Algorithms
Assignment 01
D. S. K. Muthtettugoda. Reg. No. 709087643

b. Delete.

PROCEDURE delete(x: INTEGER; VAR p: Node);

VAR q: Node;

PROCEDURE del (VAR r: Node);

BEGIN

IF r.right # NIL THEN del(r.right)

ELSE q.key := r.key; q.count := r.count;

q := r; r := r.left

END

END del;

c. Search.

PROCEDURE search(x: INTEGER; VAR p: Node);

BEGIN

IF p = NIL THEN (*x not in tree; insert*)

NEW(p); p.key := x; p.count := 1; p.left := NIL; p.right := NIL

ELSIF x < p.key THEN search(x, p.left)

ELSIF x > p.key THEN search(x, p.right)

ELSE INC(p.count)

END

END search;

4
ECX 4265 – Data Structures and Algorithms
Assignment 01
D. S. K. Muthtettugoda. Reg. No. 709087643

d. -

2.2.

2.2.1. -

2.2.2. -

2.2.3.

Advantages.

Fast access to elements.

Static data structures have the ability fast access to the database so static data structures
are mostly suitable for search data in a database than dynamic data structure.

Disadvantages.

They are essentially fixed-size. (Not flexible)

Static data structures can be ReDim (Preserve) to resize the array, but all the case this isn't
a reasonable thing to do often, or for large arrays to create a new data structure large
enough for the new array and copy all the elements over, one by one.

They often use too much space. (Costly)

No matter how many elements you're going to put into the array, you must pre declare the
size. If you dimension the array to hold 50 elements and you store only 5, you're wasting
space for the other 45.

2.3. –

Vous aimerez peut-être aussi