Assignment 2
Assignment 2
1. It follows the divide and conquer It also follows the divide and conquer
method. method.
2. Here, we sort the components by It splits the array into two segments or
comparing each component with the subarrays on repetition until one
pivot. component is left.
5. The time complexity for the worst The time complexity for the worst case is O
case is O (n2). (n log n).
6. The quick sort is mostly preferred for The merge sort is mostly applicable for the
large unsorted arrays. linked lists.
Merge Sort also works under the influence of the divide and conquer algorithm. In this
sorting technique, the input array is divided into half, and then these halves are sorted.
After sorting, these two halved sub-arrays are merged into one to form a complete
sorted array.
A full binary tree can be defined as a binary tree in which all the nodes have 0 or two
children. In other words, the full binary tree can be defined as a binary tree in which all
the nodes have two children except the leaf nodes.
The above tree is a full binary tree as all the nodes except the leaf nodes have two
children.
The complete binary tree is similar to the full binary tree except for the two differences
which are given below:
o The filling of the leaf node must start from the leftmost side.
o It is not mandatory that the last leaf node must have the right sibling
In the linked representation of binary trees, more than one half of the link fields
contain NULL values which results in wastage of storage space. If a binary tree
consists of n nodes then n+1 link fields contain NULL values. So in order to
effectively manage the space, a method was devised by Perlis and Thornton in
which the NULL links are replaced with special links known as threads. Such
binary trees with threads are known as threaded binary trees. Each node in a
threaded binary tree either contains a link to its child node or thread to other
nodes in the tree.
In one-way threaded binary trees, a thread will appear either in the right or left
link field of a node. If it appears in the right link field of a node then it will point
to the next node that will appear on performing in order traversal. Such trees are
called Right threaded binary trees
Two-way threaded Binary Trees:
In two-way threaded Binary trees, the right link field of a node containing NULL
values is replaced by a thread that points to nodes inorder successor and left
field of a node containing NULL values is replaced by a thread that points to
nodes inorder predecessor.
CODE:
OUTPUT:
Q6) DESCRIBE POLYNOMIAL REPRESENTATION.
A polynomial is of the form: i n i ∑ ci
Where, ci is the coefficient of the ith term and n is the degree of the polynomial.
Some examples are: 5x2 + 3x + 1 , 12x3 – 4x ,
5x4 – 8x3 + 2x2 + 4x1 + 9x0
A linked list structure that represents polynomials 5x4 – 8x3 + 2x2 + 4x1 + 9x0