You are on page 1of 9

ASSIGNMENT-1

1.

K + L - M*N + (O^P) * W/U/V * T + Q

Input Expression Stacks Postfix Expression


K K
+ +
L + KL
- - KL+
M - KL+M
* -* KL+M
N -* KL+MN*
+ + KL+MN*
KL+MN*-
( +( KL+MN*-
O +( KL+MN*-
^ +(^ KL+MN*-O
P +(^ KL+MN*-OP
) + KL+MN*-OP^
* +* KL+MN*-OP^
W +* K L + M N* - O P ^ W
/ +/ KL+MN*-OP^W*
U +/ KL+MN*-OP^W*U
/ +/ KL+MN*-OP^W*U/
V +/ KL+MN*-OP^W*U/V
* +* KL+MN*-OP^W*U/V/
T +* KL+MN*-OP^W*U/V/T
+ + KL+MN*-OP^W*U/V/T*
Q + KL+MN*-OP^W*U/V/T*Q
KL+MN*-OP^W*U/V/T*Q+
2.

Abstract data types:

Abstract Data type is a type for objects whose behavior is defined by a set
of value and a set of operations.
The definition of ADT only mentions what operations are to be performed
but not how these operations will be implemented. It does not specify how
data will be organized in memory and what algorithms will be used for
implementing the operations. It is called “abstract” because it gives an
implementation-independent view. The process of providing only the
essentials and hiding the details is known as abstraction.
ASSIGNMENT-2

1.

Post order: 15,28,25,35,30,45,55,70,60,50,40

Pre order: 40,30,25,15,28,35,50,45,60,55,70

In order: 15,25,30,35,40,45,50,55,60,70

2.

AVL Tree can be defined as height balanced binary search tree in which
each node is associated with a balance factor which is calculated by
subtracting the height of its right sub-tree from that of its left sub-tree.

Tree is said to be balanced if balance factor of each node is in between -1


to 1, otherwise, the tree will be unbalanced and need to be balanced.

Balance Factor (k) = height (left(k)) - height (right(k))

If balance factor of any node is 1, it means that the left sub-tree is one level
higher than the right sub-tree.
ASSIGNMENT-3

1.

The graph is one non-linear data structure. That is consists of some nodes
and their connected edges. The edges may be director or undirected. This
graph can be represented as G(V, E). The following graph can be
represented as G({A, B, C, D, E}, {(A, B), (B, D), (D, E), (B, C), (C, A)})

The graph has two types of traversal algorithms.

These are called the Breadth First Search and Depth First Search.

Breadth First Search (BFS)


The Breadth First Search (BFS) traversal is an algorithm, which is used to
visit all of the nodes of a given graph. In this traversal algorithm one node is
selected and then all of the adjacent nodes are visited one by one. After
completing all of the adjacent vertices, it moves further to check another
vertex and checks its adjacent vertices again.
Depth First Search (DFS)
The Depth First Search (DFS) is a graph traversal algorithm. In this
algorithm one starting vertex is given, and when an adjacent vertex is
found, it moves to that adjacent vertex first and try to traverse in the same
manner.

2.
B-Tree is a self-balancing search tree. In most of the other self-balancing
search trees (like AVL and Red-Black Trees), it is assumed that
everything is in main memory. To understand the use of B-Trees, we must
think of the huge amount of data that cannot fit in main memory. When the
number of keys is high, the data is read from disk in the form of blocks.
Disk access time is very high compared to the main memory access time.
The main idea of using B-Trees is to reduce the number of disk accesses.
Most of the tree operations (search, insert, delete, max, min,.etc ) require
O(h) disk accesses where h is the height of the tree. B-tree is a fat tree.
The height of B-Trees is kept low by putting maximum possible keys in a
B-Tree node. Generally, the B-Tree node size is kept equal to the disk
block size. 
B+ Tree

B+ Tree is an extension of B Tree which allows efficient insertion, deletion


and search operations.

In B Tree, Keys and records both can be stored in the internal as well as leaf
nodes. Whereas, in B+ tree, records (data) can only be stored on the leaf
nodes while internal nodes can only store the key values.

The leaf nodes of a B+ tree are linked together in the form of singly linked
lists to make the search queries more efficient.

B+ Tree are used to store the large amount of data which cannot be stored
in the main memory. Due to the fact that, size of main memory is always
limited, the internal nodes (keys to access records) of the B+ tree are stored
in the main memory whereas; leaf nodes are stored in the secondary
memory.
Assignment-4

1.
Hashing
There are many possibilities for representing the dictionary and one
of the best methods for representing is hashing. Hashing is a type of
a solution which can be used in almost all situations. Hashing is a
technique which uses less key comparisons and searches the element
in O(n) time in the worst case and in an average case it will be done
in O(1) time.

This method generally used the hash functions to map the keys into a table,
which is called a hash table.

1) Hash table

Hash table is a type of data structure which is used for storing and
accessing data very quickly. Insertion of data in a table is based on a key
value. Hence every entry in the hash table is defined with some key. By
using this key data can be searched in the hash table by few key
comparisons and then searching time is dependent upon the size of the
hash table.

2) Hash function

Hash function is a function which is applied on a key by which it produces


an integer, which can be used as an address of hash table. Hence one can
use the same hash function for accessing the data from the hash table. In
this the integer returned by the hash function is called hash key.

Types of hash function

There are various types of hash function which are used to place the data in
a hash table,
 Division method
In this the hash function is dependent upon the remainder of a
division. For example:-if the record 52,68,99,84 is to be placed
in a hash table and let us take the table size is 10.
 Mid square method
In this method firstly key is squared and then mid part of the result is
taken as the index. For example: consider that if we want to place a
record of 3101 and the size of table is 1000. So 3101*3101=9616201
i.e. h (3101) = 162 (middle 3 digit)
 Digit folding method
In this method the key is divided into separate parts and by using
some simple operations these parts are combined to produce a hash
key. For example: consider a record of 12465512 then it will be
divided into parts i.e. 124, 655, 12. After dividing the parts combine
these parts by adding it.
H(key)=124+655+12 =791

2.

Shell Sort Algorithm

Shell sort is the generalization of insertion sort, which overcomes the


drawbacks of insertion sort by comparing elements separated by a gap of
several positions. It is a sorting algorithm that is an extended version of
insertion sort. Shell sort has improved the average time complexity of
insertion sort. As similar to insertion sort, it is a comparison-based and in-
place sorting algorithm. Shell sort is efficient for medium-sized data sets. In
insertion sort, at a time, elements can be moved ahead by one position
only. To move an element to a far-away position, many movements are
required that increase the algorithm's execution time. But shell sort
overcomes this drawback of insertion sort. It allows the movement and
swapping of far-away elements as well. For example:

1. hh = h * 3 + 1  
2. where, 'h' is the interval having initial value 1.  
Quick Sort

Like Merge Sort, Quick Sort is a Divide and Conquer algorithm. It picks an


element as pivot and partitions the given array around the picked pivot. There are
many different versions of quick Sort that pick pivot in different ways. 
1. Always pick first element as pivot.
2. Always pick last element as pivot (implemented below)
3. Pick a random element as pivot.
4. Pick median as pivot.

The key process in quick Sort is partition(). Target of partitions is, given an
array and an element x of array as pivot, put x at its correct position in sorted
array and put all smaller elements (smaller than x) before x, and put all greater
elements (greater than x) after x. All this should be done in linear time.

You might also like