Beruflich Dokumente
Kultur Dokumente
1. Explain the time complexity of selection sort. Also give its derivation ?
2. Differentiate between polynomial and exponential algorithms?
Ans:
3. Explain various operations on binary search trees.
Binary Search Tree is a binary tree where each node contains only smaller
values in its left subtree and only larger values in its right subtree."
1. Insert operation
2. Search operation
3. Deletion operation.
Insertion operation:
Step 1: Create a new node with a value and set its left and right to NULL.
Step 4: If the tree is not empty, check whether a value of new node is smaller
or larger than the node (here it is a root node).
Step 5: If a new node is smaller than or equal to the node, move to its left
child.
Step 6: If a new node is larger than the node, move to its right child.
Algorithm
If root is NULL
then create root node
return
endwhile
insert data
end If
The above tree is constructed a binary search tree by inserting the above
elements {50, 80, 30, 20, 100, 75, 25, 15}. The diagram represents how the
sequence of numbers or elements are inserted into a binary search tree.
2. Search Operation
Step 2: Compare this element with the value of root node in a tree.
Step 3: If element and value are matching, display "Node is Found" and
terminate the function.
Step 4: If element and value are not matching, check whether an element is
smaller or larger than a node value.
Step 7: Repeat the same process until we found the exact element.
Step 9: If we reach to a leaf node and the search value is not match to a leaf
node, display "Element is not found" and terminate the function.
Algorithm
If root.data is equal to search.data
return root
else
while data not found
If data found
return node
endwhile
end if
https://www.youtube.com/watch?v=oKf-SFhRI6c
1. PreorderTraversal
2. PostorderTraversal
3. InorderTraversal
1. Preorder Traversal
Algorithm for preorder traversal
Step 2 :A + B + D (E + F) + C (G + H)
Step 3 :A + B + D + E + F + C + G + H
Preorder Traversal : A B C D E F G H
2. Postorder Traversal
Algorithm for postorder traversal
Step 1 : As we know, preorder traversal starts from left subtree (last leaf)
((Postorder on E + Postorder on F) + D + B )) + ((Postorder on G + Postorder on
H) + C) + (Root A)
Step 2 : (E + F) + D + B + (G + H) + C + A
Step 3 :E + F + D + B + G + H + C + A
Postorder Traversal : E F D B G H C A
3. Inorder Traversal
Algorithm for inorder traversal
Step 3 :B + E + D + F + A + G + C + H
Inorder Traversal : B E D F A G C H
Deletion Operation
Deletion is a two step process −
A binary tree can be represented using array representation or linked list representation. When a
binary tree is represented using linked list representation, the reference part of the node which doesn't
have a child is filled with a NULL pointer. In any binary tree linked list representation, there is a number
of NULL pointers than actual pointers. Generally, in any binary tree linked list representation, if there
are 2N number of reference fields, then N+1 number of reference fields are filled with NULL ( N+1 are
NULL out of 2N ). This NULL pointer does not play any role except indicating that there is no link (no
child).
A. J. Perlis and C. Thornton have proposed new binary tree called "Threaded Binary Tree", which
makes use of NULL pointers to improve its traversal process. In a threaded binary tree, NULL pointers
are replaced by references of other nodes in the tree. These extra references are called as threads.
Threaded Binary Tree is also a binary tree in which all left child pointers that are NULL (in
Linked list representation) points to its in-order predecessor, and all right child pointers that
are NULL (in Linked list representation) points to its in-order successor.
If there is no in-order predecessor or in-order successor, then it points to the root node.
of that tree...
H-D-I-B-E-A-F-J-C-G
When we represent the above binary tree using linked list representation, nodes H, I, E, F, J and G left
child pointers are NULL. This NULL is replaced by address of its in-order predecessor respectively (I
to D, E to B, F to A, J to F and G to C), but here the node H does not have its in-order predecessor,
so it points to the root node A. And nodes H, I, E, J and G right child pointers are NULL. These NULL
C), but here the node G does not have its in-order successor, so it points to the root node A.
Above example binary tree is converted into threaded binary tree as follows.
A threaded binary tree may be defined as follows: "A binary tree is threaded by making all
right child pointers that would normally be null point to the inorder successor of the node,
and all left child pointers that would normally be null point to the inorder predecessor of the
node."
A threaded tree, with the special threading links shown by dashed arrows
DATA SCIENCE
1. How do you compare Linear Regression with K-Nearest Neighbors?
Ans: Page No-104 OR 118
The table below shows some data from the early days of the Italian clothing
company Benetton. Each row in the table shows Benetton’s sales for a year
and the amount spent on advertising that year. In this case, our outcome of
interest is sales—it is what we want to predict. If we use advertising as the
predictor variable, linear regression estimates that Sales = 168 + 23
Advertising. That is, if advertising expenditure is increased by one Euro, then
sales will be expected to increase by 23 million Euro, and if there was no
advertising we would expect sales of 168 million Euro.
3. Describe the trade-off between Prediction Accuracy and Model
Interpretability
Ans: Pdf -38 OR 25