datastructureandalgorithm2017.files.wordpress.com · Web viewiii) Postorder. 4. (a) Write algorithm...

15
Pad. D. Y. Patil Institute of Engineering, Management and Research, Akurdi, Pune – 44 Department of Computer Engineering Advance data Structure Assignment UNIT -1:TREES Academic Year: 2016-17 Date: 1. (a) Write an algorithm for non-recursive in-order traversal of Binary tree. [8] (b) Differentiate between linear and non-linear data structures. [4] 2. (a) Write an algorithm for deleting leaf nodes and nodes with only one child from a Binary Search Tree. [8] (b) What are threaded trees ? Explain with example. [6] (c) Construct a Binary Search Tree for given numbers, show all steps : [4] 14, 15, 4, 9, 7, 18, 3, 5, 7. 3. (a) List and explain in brief applications of binary tree. [4] (b) What are properties for binary trees that distinguish them from general tree ? [6] (c) Write algorithm for traversal of binary tree and give suitable example for the same : [8] (i) Inorder (ii) Preorder (iii) Postorder. 4. (a) Write algorithm to delete node from BST. [8] (b) Write algorithm for inorder traversal of a threaded binary tree and give its time complexity. Also give example for the same. [10] 5. (a) Define the following with examples : [8] (i) Complete Binary Tree (ii) Predecessor and Successor (iii) Graph (iv) OBST. (b) What is the necessity of converting a tree into binary tree ? Convert the following tree into a binary tree and list down the steps for the same. [8]

Transcript of datastructureandalgorithm2017.files.wordpress.com · Web viewiii) Postorder. 4. (a) Write algorithm...

Page 1: datastructureandalgorithm2017.files.wordpress.com · Web viewiii) Postorder. 4. (a) Write algorithm to delete node from BST. [8] (b) Write algorithm for inorder traversal of a threaded

Pad. D. Y. Patil Institute of Engineering, Management and Research, Akurdi, Pune – 44

Department of Computer Engineering

Advance data StructureAssignment

UNIT -1:TREES

Academic Year: 2016-17

Date:

1. (a) Write an algorithm for non-recursive in-order traversal of Binary tree. [8](b) Differentiate between linear and non-linear data structures. [4]

2. (a) Write an algorithm for deleting leaf nodes and nodes with only one child from a Binary Search Tree. [8](b) What are threaded trees ? Explain with example. [6](c) Construct a Binary Search Tree for given numbers, show all steps : [4]14, 15, 4, 9, 7, 18, 3, 5, 7.

3. (a) List and explain in brief applications of binary tree. [4](b) What are properties for binary trees that distinguish them from general tree ? [6](c) Write algorithm for traversal of binary tree and give suitable example for the same : [8](i) Inorder (ii) Preorder(iii) Postorder.

4. (a) Write algorithm to delete node from BST. [8](b) Write algorithm for inorder traversal of a threaded binary tree and give its time complexity. Also give example for the same. [10]

5. (a) Define the following with examples : [8](i) Complete Binary Tree(ii) Predecessor and Successor(iii) Graph(iv) OBST.(b) What is the necessity of converting a tree into binary tree ? Convert the following tree into a binary tree and list down the steps for the same. [8]

6. (a) Write functions for non-recursive pre-order and in-order traversal algorithms for a in-order threaded binary tree. [8](b) Construct a binary tree from the given traversals : [4]Pre-order : * + a – b c / – d e – + f g hIn-order : a + b – c * d – e / f + g – h(c) Write a function for creating binary search tree. [4]

7. (a) Draw a Huffman tree for the given data set and find the corresponding Huffman codes : [8]

Page 2: datastructureandalgorithm2017.files.wordpress.com · Web viewiii) Postorder. 4. (a) Write algorithm to delete node from BST. [8] (b) Write algorithm for inorder traversal of a threaded

8. (a) Given the following inorder and postorder traversal construct the binary tree : [6]Inorder — D B F E G A H I CPostorder — D F G E B I H C A .

9. (a) What is Threaded Binary Tree ? Explain advantages and disadvantages of Threaded Binary Tree. [6](b) Construct BST for the following : [6]MAR, MAY, NOV, AUG, APR, JAN, DEC, JUL, FEB, JUN, OCT, SEPT(c) Write and explain non-recursive inorder traversal of Binary Tree. [6]

10. (a) Explain the following : [9](i) Full and complete binary trees.(ii) List and explain in brief applications of binary tree.(iii) Explain class & object in OOP concept.(b) Write non-recursive algorithm for traversal of binary tree : [9](i) Inorder(ii) Preorder.

11. (a) Draw binary search tree for data 12, 18, 20, 30, 35, 40, 42,48, 52. If root is 40 and leafs are 12, 52, write Binary Search Tree (BST) search algorithm. [10](b) Explain the following : [8]

(i) What is array representation of given binary tree ?(ii) What is linked representation of given binary tree ?What are important observations of linked representation ?(c) Write a ‘C’ code to create an expression tree and perform non-recursive in-order traversal. [8]12. (a) What is the necessity of converting a tree into binary tree ?

Page 3: datastructureandalgorithm2017.files.wordpress.com · Web viewiii) Postorder. 4. (a) Write algorithm to delete node from BST. [8] (b) Write algorithm for inorder traversal of a threaded

Convert the following tree into a binary tree and list down the steps for the same. [6](b) Implement binary tree as an ADT. [8](c) Write a ‘C’ function to implement post order traversal on threaded binary tree. [4]13. (a) Write a recursive function to find the height of a binary tree. [6](b) Given the following traversals build a binary tree from them : [6](i) In-order : 15, 22, 25, 30, 33, 40, 44, 50, 60, 75, 80, 90(ii) Pre-order : 50, 25, 22, 15, 40, 30, 33, 44, 75, 60, 90, 80.(c) Write a ‘C’ function to delete a node from a binary search tree. [6](b) Explain the mechanism to create Huffman’s tree and use it for encoding and decoding. Assume suitable data. [6](b) Create a Huffman’s tree for the given data set and find the corresponding Huffman’s codes : [8]

Data WeightA 10B 3C 4D 15E 2F 4G 2H 3

14 (a) What is Binary search tree? Write a pseudo for deletion and insertion of a node in Binary search tree.[8](b) Write a non recursive function in C to traverse a binary tree in inorder traversal and preorder traversal.[8]15 (a) What is threaded binary tree? Explain with example. [8](b) For a binary tree, the inorder and postorder traversal is as follows:Inorder:- H,D,I,B,E,A,J,F,K,C,GPostorder:- H,I,D,E,B,J,K,F,G,C.A(c) Create a binary tree & write pseudo code to print non leaf nodes of the tree and find height of the tree.[8]

16. The inorder and postorder traversals of a certain binary search tree are given as follows. Inorder Traversal: 10,30,40,50,52,54,55,60,90 Postorder Traversal: 40,54,52,55,50,30,60,90,10 Construct the binary search tree from above traversals and write the preorder traversal. Draw a Huffman’s tree for the given data set and find thecorresponding Huffman codes:Data FrequencyA 15B 6C 7D 12E 25F 4G 6H 1I 15

Page 4: datastructureandalgorithm2017.files.wordpress.com · Web viewiii) Postorder. 4. (a) Write algorithm to delete node from BST. [8] (b) Write algorithm for inorder traversal of a threaded

Pad. D. Y. Patil Institute of Engineering, Management and Research, Akurdi, Pune – 44

Department of Computer Engineering

Advance data StructureAssignment

UNIT -2:GRAPH

Academic Year: 2016-17

Date:

1. (a) Write a function to create GRAPH using adjacency matrix method. [6](b) For the graph given in Fig. 1, draw minimum cost spanning tree using Prim’s algorithm, show all steps : [6]

(c) What is in-degree, out-degree and degree of a vertex ? Explain with example. [4]

2. (a) Write an algorithm for generating minimum cost spanning tree using Kruskal’s method. [6] (b) Find the shortest path from vertex 1 to all other vertices in the graph of Fig. 2 using Dijkstra’s algorithm :

(c) Explain with example inverse adjacency list representation of graph. [4]

3. (a) What are graph storage structures ? Explain in detail. [8](b) Write algorithm for Depth First Traversal of the graph and give suitable example for the same. [8]

4. (a) Write Prim’s algorithm and explain stages of the algorithm for the following example : [8](b) Write pseudo code to find the shortest path in weighted graph.

Page 5: datastructureandalgorithm2017.files.wordpress.com · Web viewiii) Postorder. 4. (a) Write algorithm to delete node from BST. [8] (b) Write algorithm for inorder traversal of a threaded

Find the shortest path in the following graph from node 0 to node 4. [8]

5. (a) Write an algorithm to perform DFS traversal for a graph. Perform DFS & BFS for the following graph : [10](b) Write short notes on Dijkstra’s algorithm. [4](c) Define Minimum Spanning Tree with an example. [2]

6. (a) Write an algorithm for Prim’s method.Find minimum spanning tree using Prim’s and Krushal’s method. [10](b) Describe the different ways of graph storage structure with an example. [6]

7. (a) For the following construct : [8](i) Adjacency Matrix (ii) Adjacency List(iii) DFS search(iv) BFS search.

(b) Use Dijkstra’s algorithm to obtain in non-decreasing order the lengths of the shortest paths from vertex 1 to all remaining vertices in the diagraph. [8]

8. (a) Find minimum spanning tree for the following using Prims and Kruskal algorithm. [6]

Page 6: datastructureandalgorithm2017.files.wordpress.com · Web viewiii) Postorder. 4. (a) Write algorithm to delete node from BST. [8] (b) Write algorithm for inorder traversal of a threaded

(b) Explain difference between DFS and BFS. [6](c) Explain the following terms with example : [4](i) Path (ii) Simple path (iii) Cycle (iv) Loop.

9. (a) Write algorithm for Breadth First Traversal of the graph. Also write its complexity. [8] (b) Explain the following : [8](i) State the difference between Kruskal’s and Prims algorithm for minimum spanning tree (MST). (ii) Graph as an ADT.

10. (a) Write Kruskal’s Algorithm for MST and explain it with example. [8](b) Explain the following : [8](i) What are graph storage structures ?(ii) Topological sort.

11. (a) For the graph given draw the adjacency list and matrix : [4]

(b) Write pseudo-code for Prim’s method for finding MST of graph and explain the same for the graph whose weight matrix is given : [8]

(c) Define the following w.r.t. graphs with examples : [4](i) Degree of node (ii) Isolated node (iii) Path (iv) Cycle.

Page 7: datastructureandalgorithm2017.files.wordpress.com · Web viewiii) Postorder. 4. (a) Write algorithm to delete node from BST. [8] (b) Write algorithm for inorder traversal of a threaded

12. (a) Write pseudo-code for Kruskal’s method for finding MST of graph and explain the same for the graph whose weight matrix is given in Fig 2. [8](b) Write a ‘C’ function to find the shortest path in a graph using Dijkstra’s algorithm with an example. [8]

13 (a) Explain different types of representation of graphs with example.[4](b) Write a non recursive pseudo code to perform DFS and BFS traversal for following a graph:[10]

(c) Define: (i) Complete graph (ii) Path

14 (a) What is topological sorting? Explain with example. [6] (b) Write a pseudo ‘C’ code to find minimum spanning tree using Kruskal’s algorithm for following graph:

Page 8: datastructureandalgorithm2017.files.wordpress.com · Web viewiii) Postorder. 4. (a) Write algorithm to delete node from BST. [8] (b) Write algorithm for inorder traversal of a threaded

Pad. D. Y. Patil Institute of Engineering, Management and Research, Akurdi, Pune – 44

Department of Computer Engineering

Advance data StructureAssignment

UNIT -3:Hashing

Academic Year: 2016-17

Date:

1. (a) What is bucket hashing ? Explain with example. [8](b) What is hash function ? Explain the following hash functions : [8](i) Mid-square(ii) Modulo Division(iii) Folding Method(iv) Digit Analysis.

2. (a) What is static and dynamic hashing ? Show that the hash function h(k) = k% 17 does not satisfy the one way property, week collision resistance or strong collision resistance. [8](b) What is hash function ? Explain the different types of hash functions. [8]

3. (a) What are hashing methods ? Explain in brief. [8]

4(a) Create a Hash table and resolve collisions using linear probing with and without replacement : 9, 45, 13, 59, 12, 75, 88, 11, 105, 46 Hash table size = 11 and Hash function = key mod 10. [8](b) Write a note on re-hashing. [4]

5(a) What is collision? Explain linear probing with and without replacement for student database with roll numbers:55, 88, 26, 37, 70, 60, 62, 41, 86, 64 Hash Table Size =11 and Hash Function = Key mod 11 [8](b) What do you understand by Hash Table? Why they came into existence? Discuss different Hash functions.

6.(a)What is the use of hash tables? Explain the characteristics of a good hash function.(b) Enlist various static and dynamic tree tables. Explain when to select the static tree tables and dynamic tree tables

7.Assume a hash table of size 10 and hash function H(X)=X mod 10 performs linear probing with and without replacement for the given set of values. 0,1,2,4,72,65,85,87,90,58.

Page 9: datastructureandalgorithm2017.files.wordpress.com · Web viewiii) Postorder. 4. (a) Write algorithm to delete node from BST. [8] (b) Write algorithm for inorder traversal of a threaded

Pad. D. Y. Patil Institute of Engineering, Management and Research, Akurdi, Pune – 44

Department of Computer Engineering

Advance data StructureAssignment

UNIT -4:Search Trees

Academic Year: 2016-17

Date:

1. Create an AVL tree for the following elements. Show all steps with rotation :1 2 3 4 8 7 6 5. [6]2. (a) Write and explain algorithm to insert node into AVL tree. [8](b) Explain with example LL, LR, RR, RL rotation for AVL tree. [8]

3. (a) Construct an AVL search tree by inserting the following elements in the order of their occurrence. Show the balance factor and type of rotation at each stage :148 153 158 1000 112 145 120 149 128 146 [12]

4. (a) Write and explain algorithm to delete node from AVL tree. [8] (b) Explain different types of rotation for AVL tree with suitable example. [8]

5. (a) Construct an AVL search tree by inserting the following elements in the order of their occurrence. Show the balance factor and type of rotation at each stage : 64 1 44 26 10 110 98 85 13 20 [10]

6 (a) Construct an AVL tree by inserting the following elements in the order of their occurrence. Show the balance factor and type of rotation at each stage.55,66,77,15,11,33,22,35,25,44,88,99 [12](b) Write a note on OBST7. Construct AVL search tree by inserting the following elements in the order of their occurrence. Show the balance factor and type of rotation at each step. 70,55,60,65,50,80,49,68,44,66,77,798.Write a pseudo C/C++ code for LL,RR,LR and RL

Pad. D. Y. Patil Institute of Engineering,

Page 10: datastructureandalgorithm2017.files.wordpress.com · Web viewiii) Postorder. 4. (a) Write algorithm to delete node from BST. [8] (b) Write algorithm for inorder traversal of a threaded

Management and Research, Akurdi, Pune – 44Department of Computer Engineering

Advance data StructureAssignment

UNIT -5 :Indexing and Multiway Trees

Academic Year: 2016-17

Date:

1. Write an ADT for a binary heap. Explain different operations on MAX heap in brief with example (any three). [10]

2. What is multiway tree ? State need of multiway trees. Explain B+ tree in brief. [8]

3. Construct a B tree of order 5 for the following data : [10]50, 85, 12, 10, 6, 60, 70, 80, 37, 100, 120, 65,150, 62, 30, 17, 15, 28, 75, 78.

4. Write an algorithm to arrange numbers in ascending order using heapsort. Arrange the following numbers in ascending order using heapsort : [8]48, 0, –1, 82, 10, 2, 100.

5. (a) Define heap. Explain types of heap. Write an algorithm to insert an element into heap. [8](b) Construct a B tree of order 5 for the following data : 50, 85, 42, 10, 16, 60, 70, 80, 87, 100, 120, 65, 150, 62, 30, 17, 18, 28, 75, 78.What is the best and worst case complexity of insert and delete operation on B tree ? [10]

6. (a) What is B tree ? Explain the process for deleting a particular value from B tree. [8](b) State algorithm to sort elements of a given array in ascending order using heapsort. Sort the following numbers using heapsort in ascending order :38, –10, –11, 72, 98, 62, 44. [10]7. Sort the following numbers in descend using heap sort 22,75,34,55,25,10,45,52,90,65

8. What is Heap? Sort the following numbers in ascending order using heap sort.12,2,16,30,8,28,4,10,20,6,18

9.Define the term heap trees. Write a pseudo C/C++ code to insert the element in

10 Create a B+ tree of order 3 for the data given below 55,10,40,20,12,15,90,80,45,52,25,22,85,95,65

Page 11: datastructureandalgorithm2017.files.wordpress.com · Web viewiii) Postorder. 4. (a) Write algorithm to delete node from BST. [8] (b) Write algorithm for inorder traversal of a threaded

Pad. D. Y. Patil Institute of Engineering, Management and Research, Akurdi, Pune – 44

Department of Computer Engineering

Advance data StructureAssignment

UNIT -7:File Organization

Academic Year: 2016-17

Date:

1. (a) Write a C/C++ program to perform create, insert, display and search operations for sequential file organization. [8](b) What is index sequential file organization ? State its advantages and disadvantages. [8]

2. (a) List different file organizations. State the need of file organizations. List different primitive operations on files. Compare sequential file with index sequential file organization. [10] (b) Explain in brief direct access file organization with example. [6]

3.(a) Differentiate between sequential and index sequential file.Write a pseudocode to read and write contents using index sequential file. [8](b) Write a program in ‘C’ for sequential file and perform the following operations: [8](i) Copying all data from one file to another(ii) Count number of characters in a file(iii) Count number of words in file(iv) Search a particular word in a file.

4. (a) Write an algorithm to perform create, insert, display and search operations for sequential file organization. [8] (b) What is index sequential file organization ? State its advantages and disadvantages

5. (a) What is file ? List different file opening modes. Explain Index sequential file organization in brief. [8](b) Explain in brief : [8](i) Linked file organization(ii) Direct file organisation.

6. (a)Compare index sequential and direct access files. [6](b) What is file? Explain the different types of file organization? [8]

7. (a) Write pseudo-code for implementation of primitive functions of index-sequential file. [8](b) Write a note on characteristics of good hash function. [4](c) Write a ‘C’ program using command line arguments to perform the following operations on a file :(i) Count number of white spaces(ii) Count number of special characters. [6]

8 (a) Write a pseudo code to perform the following operations on Direct Access files:(i) To modify record with given key value(ii) To delete record with given key value(iii) Insert record at specific location with given key value [8]