You are on page 1of 3

WHAT IS SPACE AND TIME TRADEOFF?

- This is a simple algorithm design technique that realizes this


distinction for most input patterns.

- Its main objective is to make the comparison of pattern characters to


- A space-time or time-memory tradeoff is a situation where the text from right to left instead of left to right.
memory use can be reduce at the cost of slower program execution,
or vice versa. - The main application of Shift table includes the following:

- It is one of the most important issues in computer science 1. Stores number of character to shift by depending on first
character compared.
- Computation time can be reduce at the cost of increased memory 2. Construct by scanning pattern before searching starts.
employed. 3. Indexed by the alphabet of text and pattern.
4. All entries are initialized to pattern length.
- Input Enhancement the idea to preprocess the problem’s input in
whole or just simple part of the whole, and store the additional BOYER-MOORE ALGORITHM
information obtained to accelerate solving problem. - This is when the comparison of the rightmost character in the pattern
with the corresponding character c in the text fails.
INPUT ENHANCEMENT IN STRING MANIPUALATION
HASHING ALGORITHM
- Input enhancement can be applied in different string manipulation - This is the different approach to searching on the value of the key.
problems. - It is based on the idea of distributing keys among a one-dimensional
array, which is referred to as the hash table.
- Pattern matching problems - It is considered as a very efficient way to implement dictionaries.
- Hashing is based on the idea of distributing keys among a one-
- Input enhancement using Brute force algorithm: dimensional array H[0…m-1] called hash table.
- The distribution is done by computing for each key, the value of
1. Align pattern at beginning of text some predefined function h called the hash function.

2. Moving from left to right, compare each character of pattern to Collision


the corresponding character in text until either: - Good hash functions result in fewer collisions, but some collisions
should be expected. If you choose a hash table’s size m to be smaller
a. All characters are found to match (successful search); or than the number of keys, you will get collision.
- Are phenomenons of two or more keys being hashed into the same
b. A mismatch is detected cell of the hash table.

3. While pattern is not found and the text is not yet exhausted,
realign pattern one position to the right and repeat step 2.
Open Hashing
- Each cell is a header of linked list of all keys hashed to it.

HORPOOL’S ALGORITHM Close Hashing


- One key per cell
- In case of collision, it finds another cell by 3. The selection function which does not appear explicitly, but
o Linear probing: use next free bucket gives the value of a solution.
o Double hashing: use second hash function to compute
increment
PRIM’S ALGORITHM

- Generally, the effectiveness of searching depends on the lengths of – is an algorithm in graph theory that finds a minimum spanning tree
the linked list, which, in turn, depend on the dictionary and table size for a connected weighted graph.
s, as well as the quality of the hash function. o Spanning Tree of a connected graph is its connected acyclic
- If hash function distribute keys uniformly, average length of linked sub graph like a tree that contain all the vertices of the graph
list will be: [LEV07].
o a=ry’m o A Minimum spanning tree (MST) of a weighted connected
- this ration is called load factor. graph is its spanning tree of the smallest weight, where the
weight of a tree is defined as the sum of the weights on all its
edges [LEV07].
o The Minimum spanning tree problem is the problem of
finding a minimum spanning tree for a given weighted
ABOUT GREEDY ALGORITHM DESIGN TECHNIQUE connected graph [LEV07].

- GREEDY ALGORITHMS are simple and straight forward.


- Most greedy algorithms are easy to develop, implement, and time
efficient
- Suggests constructing a solution through sequence of steps, each
expanding a partially constructed obtained so far, until a complete
solution to the problem is reached. Prim’s algorithm works as follows:
- On each step, which is the central point of this technique, the choices 1. Create a tree containing a single vertex, chosen arbitrarily
mode must be: from the graph
o Feasible 2. Create a set containing all the edges in the graph
o Locally Optimal 3. Loop until every edge in the set connects two vertices in the
o Irrevocable tree
- Each step, it suggests a “greedy” grab of the best alternative i. Remove from the set an edge with minimum weight
available. that connects a vertex in the tree with a vertex not in
the tree
1. Informal Algorithm - starts with nothing and at every stage without ii. Add that edge to the tree
passing the given amount and adds the largest coins already chosen.
2. Formal Algorithm – makes change for n units using the least possible KRUSKAL’S ALGORITHM
number of coins.
- an algorithm in graph theory that finds a minimum spanning tree for
The Greedy algorithm consists of four functions and these are as follows: a connected weighted graph [www.wordiq.com]
1. A function that validates whether the selected set of items - introduced by Joseph Kruskal
provided a solution.
2. A function that validates the feasibility of a set.
- an algorithm which find a subset of the edges that forms a tree that - Step 2: Sub sequently, we will look for the two nodes with the
includes every vertex, where the total weight of all the edges in the smallest combined frequency weights and combine them to forma
tree is minimized third node, ensuing a simple two-level tree
- If in case the graph is not connected, it finds a minimum spanning - Step 3: Repeat step 2 until all of the nodes on each level are
forest connected component. combined in a single tree.

Kruskal’s algorithm works as follows:


1. Create a forest F(a set of trees), where each
vertex in the graph is a separate tree
2. Create a set S containing all the edges in the
graph
3. While S is nonempty
a. Remove an edge with minimum
weight from S
b. If that edge connects two different
trees, then add it to the forest, combining two trees into a
single tree
c. Otherwise discard that edge

DIJKTRA’S ALGORITHM

- introduced in 1959 by Edsger Dijktra, who is a Dutch computer


scientist
- a graph search algorithm that solves the single-source shortest path
problem for a graph with nonnegative edge path costs, producing a
shortest path tree [www.wikipedia.org]
- finds the shortest paths to a graph’s vertices in order of their distance
from a given source
o it finds the shortest path form the source to a vertex nearest
to it, then to the second and so on.

HUFFMAN TREE ALGORITHM


- Huffman tree: Are binary trees which are based on the probability
distribution of a symbol set and the principle that symbols occurring
more frequently will be represented by shorter codes than other, less
probable ones.

Three basic steps in constructing a tree:


- Step 1: Arrange the entire character set into a row and should be
ordered according to its frequency from lowest to highest or vise
versa.

You might also like