Data Structures & Algorithms
Data Structures & 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.
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
This notation gives a lower bound for a function to within a constant factor. We write
This notation bounds a function to within constant factors. We say f(n) = Θ(g(n)) if
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
3
ECX 4265 – Data Structures and Algorithms
Assignment 01
D. S. K. Muthtettugoda. Reg. No. 709087643
b. Delete.
VAR q: Node;
BEGIN
q := r; r := r.left
END
END del;
c. Search.
BEGIN
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.
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.
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.
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. –