Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
UNIT I
LINEAR STRUCTURES
UNIT II
TREE STRUCTURES
Need for non-linear structures Tree ADT tree traversals left child right sibling data structures for general trees Binary Tree ADT expression trees applications of trees binary search tree ADT
AVL trees Binary Heaps B-Tree Hashing Separate chaining open addressing Linear probing UNIT IV GRAPHS 9
UNIT V
fro
Definitions Topological sort breadth-first traversal - shortest-path algorithms minimum spanning tree Prim's and Kruskal's algorithms Depth-first traversal biconnectivity euler circuits applications of graphs 9
Greedy algorithms Divide and conquer Dynamic programming backtracking branch and bound Randomized algorithms algorithm analysis asymptotic notations recurrences NP-complete problems TOTAL: 45 PERIODS TEXT BOOKS 1. M. A. Weiss, Data Structures and Algorithm Analysis in C, Pearson Education Asia, 2002. 2. ISRD Group, Data Structures using C, Tata McGraw-Hill Publishing Company Ltd., 2006. REFERENCES 1. A. V. Aho, J. E. Hopcroft, and J. D. Ullman, Data Structures and Algorithms, Pearson Education, 1983. 2. R. F. Gilberg, B. A. Forouzan, Data Structures: A Pseudocode approach with C, Second Edition, Thomson India Edition, 2005. 3. Sara Baase and A. Van Gelder, Computer Algorithms, Third Edition, Pearson Education, 2000. 4. T. H. Cormen, C. E. Leiserson, R. L. Rivest, and C. Stein, "Introduction to algorithms", Second Edition, Prentice Hall of India Ltd, 2001.
do
nl
oa
de d
re jin
UNIT III
pa ul .c om
9 9
Abstract Data Types (ADT) List ADT array-based implementation linked list implementation cursor-based linked lists doubly-linked lists applications of lists Stack ADT Queue ADT circular queue implementation Applications of stacks and queues
6.2 SHORT QUESTIONS AND ANSWERS UNIT-I PART - A 1. Define:Abstract data type It is defined as a set of operations. It is also defined as Logical and mathematical properties of a data type. 2. Difference between array and list? Array It consists of fixed number of objects Insertion and deletion is very difficult
List It consists of variable number of elements . Insertion & deletion are performed easily
1. insertion 2. deletion 3. combining 2 or more list 4. splitting a list 5. copy a list 6.sort elements 7.search the element. 4. What are the draw balks of array implementation of list? 1.list must be known in advance. 2.insertion & deletion is very slow.
do
nl
Linked list with two pointers is defined as doubly linked list two pointers are named as forward & backward pointers forward pointers denotes the successor backward pointers denotes predecessor of the current note.
9. List the disadvantages of circular linked list ? 1.Possible to get into an infinite loop.
2nd YEAR/ 3rd SEMESTER
oa
It contains the list of free nodes. A node can be inserted in a list can be taken form the stack.
de d
fro
re jin
pa ul .c om
2.The list should hot be empty. Identifying fist / last note is important this cont be done by using header. 10. List applications of linked list? 1.creations of linked list? 2.polynomial manipulation. 3.sorting 4.tree trades 5.mulitlist organization. 11. Define stack.
Stacks are known as LIFO(last in first out) it is a list with the restriction that insertions are done at the end of the list called top. 12. What are the different ways stack can be implemented? 1.Arry implementation 2.Linked list
13. Write procedure for push operation in stack? Procedure Push (s, top, x) 1.if top >N then Write (stack overflow) Return. 2.top top+1 3.s [top] x. 4.return
14.List the applications of stack? 1.Conversion of infix to post fix expression. 2.Evaluation post fix expression. 3.Towers of hanoi 4.Balancing symbols.
do
nl
15.Defines Queue. Queues are list where insertions is done at one end called rear and deletion is done at other end called front. 16.Applications of Queue? 1.Printer attached to a system uses the concept to print the contents stored. 2.Calls to large companies are placed in a queue 3.In large universities where resources are limited student must wait in a queue to assign to a list of terminals etc.
oa
de d
fro
re jin
pa ul .c om
17.What are the restrictions in the movement of discs in towers of hanoi ? 1.only one disc may be more at a time. 2.dise may be moved from one needle to any other 3.at no time may a larger disc rest capon a smaller disc
It is useful in cases where linked list concept has to be implemented without using pointers. 19.Define: data structure It is a representation of logical relationship of data 20.What is primitive data structure ?
These are basic structures and are directly operated upon by the machine instructions. 21What is Non Primitive data structure ?
do
nl
25.Write a routine to check whether Queue is empty? Int IsEmpty(Queue e) { If(QNext==NULL) Return(1); }
oa
It represents hierarchical arrangement of elements. 24.What are the types of notations to represent Arithmetic expression? INFIX NOTATION PREFIX NOTATION POSTFIX NOTATION
de d
fro
re jin
pa ul .c om
PART B 1.What are the various Linked List operations?. Explain. 2.Explain how stack is applied to evaluate an arithmetic expression?
polynomials? 4.Write the recursive routine for Towers of Hanoi?. 5.Explain cursor implementation of List?
6.Write the insertion and deletion routine for doubly linked list?
UNIT II
1.Define Tree. Tree is a finite set of one or more nodes such that there is a specially designated node called root.
de d
B
fro
C D
do
nl
2.Define the following terms: a)Root b)Sibling c)Degree d)Leaf Root:-A node which does not have a parent. Sibling:-Children of the same parents are said to be siblings. Degree: The number of subtrees of a node is called its degree. Leaf:-A node which does not have children is called leaf or terminal node.
oa
m
A
re jin
pa ul .c om
3.What is binary tree? It is a tree in which no node can have more than two children A
do
nl
6. what is complete binary tree? A tree is said to be complete binary tree ,if all its level except possibly the last level ,have the maximum number of possible nodes, all the nodes at the last level as far left as possible. 7. What is full binary tree?
A binary tree is a full binary tree ,if it contains maximum possible number of nodes in all level.
oa
de d
2nd YEAR/ 3rd SEMESTER
fro
4. What is the maximum number of nodes in a binary tree? The Maximum number of nodes in a binary tree is 2i+1. 5. Compare General Tree and Binary Tree? General Tree Binary Tree General Tree has any number of children Binary tree has not more than two children
re jin
pa ul .c om
8. What is Expression Tree? It is a binary tree in which the leaf nodes are operands and the interior nodes are operators.
It is a binary tree in which for every node X in the tree,the values of all the keys in its left subtree are smaller than the key value in X,and the values of right sub tree are larger than the value in X.
do
nl
oa
de d
fro
re jin
pa ul .c om
Binary tree
26
25
45
re jin
10 8 12
28
30
do
nl
Traversing means visiting each node only once. Tree traversal is a method of visiting all the nodes in the tree exactly once. 12.Name the 3 types of tree traversals? 1.In Order traversal. 2.Pre Order traversal. 3.Post Order traversal
13.How the inorder traversal is performed? Traverse left subtree in inorder. Visit the root Traverse right subtree in inorder.
oa
de d
fro
pa ul .c om
19 22
A binary tree is said to be a binary tree if it has A binary search tree is a binary tree in which key almost two children values in the left tree is less than root node and key values in the right subtree is greater than root.
20
10 10,20,30
30
14. List the Preorder traversal steps? Visit the root. Traverse Left subtree in pre order Traverse Right Subtree in pre order 20
20,10,30
do
nl
oa
Traverse Left subtree in post order. Traverse Right subtree in post order. Visit Root. 20
10
de d
30
16. Convert the following Expression into Preorder Expression? A+B*C-D/E Preorder : *+AB-C/DE
fro
10,30,20
10
30
re jin
pa ul .c om
17. How do you construct expression tree? Read one Symbol at a time from postfix expression. Check whether the symbol is operand or operator . If the symbol is operand ,create one node tree and push pointer to the stack. If it is operator pop two pointers from the stack and form a new tree with root as operator and pointer to new node is pushed on to the stack. 18. what is Left most child ,Right sibling data structure?
In this ,cell space contains three fields namely, Left most child, Label and Right Sibling. A
do
nl
Trees are used to organize information in data base system and to represent syntactic structure of source programs in computers. It can be used to evaluate arithmetic expression. 21. Define following terms: a).Child b).Link
Child:-If the immediate predecessor of a node is the parent of the node then all immediate successor of a node is known as child. Link:-This is a pointer to a node in the tree.
oa
de d
fro
m
D
re jin
pa ul .c om
22. Draw the binary tree for the following expression (A+B)*(C-D)
do
nl
oa
de d
fro
re jin
pa ul .c om
D
PART B 1. A).Write an algorithm to find an element from binary search tree. B).Write a program to insert and delete an element from a binary tree? 2. What are the different tree traversal technique?Expalin 3. Explain the recursive and non recursive routine for FindMin and FindMax?
4. What is the need for nonlinear data structure? Explain Expression Tree with example?
2. What is hashing?
do w
nl o
It is a key to address transformation ,which acts upon a given key to compute the relative position of the key in the array. HASH(KEYVALUE)=KEYVALUE MOD TABLESIZE 5. List the methods of the Hashing function? 1.Module Division 2.Mid Square Method 3.Folding Method. 4.PSEUDO Random Method 5.Digit or Character Extraction Method. 6.Radix Transformation
ad ed
Hash table data structure is an array of some fixed size ,containing the keys. Key is a value associated with each record.
fro m
The implementation of Hash Tables is called as Hashing. It is a technique used for performing insertions,deletions,and finds in constant average time.
re j
in
AVL tree Adelson Velskii and Landis Tree is a binary search tree with a balancing conditions. The condition is Right and Left trees have the same height.
pa ul .c
om
6. When Collision Occurs? Collision occurs when a hash value of a record being inserted hashes to an address that already contains different record.(ie) when 2 key values hash to the same position. 7. What is collision Resolution? It is the process of finding another position for the collide record. 8. List the Collision Resolution Techniques? 1.Separate Chaining. 2.Open Addressing 3.Multiple Hashing. 9.what is separate Chaining?
More number of elements can be inserted as it uses array of linked lists. 11.What are the Disadvantages of Separate Chaining? 1.It requires pointers , which occupies more memory space . 2.It takes more effort to perform a search ,since it takes time to evaluate hash function and also to traverse the list. 12.Define Open Addressing.
do w
nl o
It is also called as Closed Hashing ,which is an alternative to resolve the collisions with linked lists. 13.What are the Collision resolution strategies? 1.Linear Probing 2.Quadratic Probing. 3.Double Hashing.
In Linear Probing ,the position in which a key can be stored is found by sequentially searching all position starting from the position calculated by the hash function until an empty cell is found.
ad ed
fro m
re j
It is an open Hashing Technique. A pointer field is added to each record location .when an overflow occurs this pointer is set to point to overflow blocks making a linked list.
in
pa ul .c
om
15.What is the advantage of Linear Probing? It does not require Pointers. 16. What is the disadvantage of Linear Probing? It forms clusters ,which degrades the performance of the hash table for storing and retrieving data.
The efficient way of implementing priority queue is Binary Heap. 18.What are Heap Properties? 1.Structure Property 2.Heap order Property. 19.What are the basic operations of Binary Heap? 1.Insertion 2.Delete Min
B-Trees are balanced M-way trees, which are well suited for disks. 22.What are the B-Tree Properties?
do w
nl o
1.Root is either a leaf or has between 2 and M children. 2.All no leaf nodes have between M/2 and M children. All leaves are at same depth.
23.what are the uses of trees? Trees are used in operating system, compiler design and searching.
ad ed
fro m
re j
in
pa ul .c
om
2.Write a function to perform insertion and deletion in a binary heap. 3.Write a routine to perform insertion into a B-tree.
1. Define Graph
A graph G=(V,E) consists of a set of Vertices ,V and set of Edges E. 2. What is Digraph?
do w
nl o
ad ed
fro m
4.Define Hash function .Write routines to find and insert an element in separate chaining. UNIT IV PART - A
re j
in
pa ul .c
om
A graph is said to be weighted graph if every edge in the graph is assigned a weight or value.
It is a graph in which there is an edge between every pair of vertices.A complete graph with n vertices will have n(n-1) / 2 edges.
do w
nl o
ad ed
fro m
re j
in
pa ul .c
om
If there is path from every vertex to every other vertex in a directed graph then it is said to be Strongly connected graph.
7.what is path?
do w
nl o
ad ed
fro m
re j
in
pa ul .c
om
Adjacency List 10.What is the advantage of Adjacency Matrix Representation? Simple to implement. 11. What are the disadvantages of Adjacency Matrix Representation? Takes O(n2) space to represent the graph. Takes O(n2) time to solve the most of the problems. 12.What is Adjacency List representation?
In this we store all vertices in a list and then for each vertex ,we have a linked list of its adjacency vertices.
It takes O(n) time to determine whether there is an arc from vertex i to vertex j. 14.What is topological sort?
It is linear ordering of vertices in a directed acyclic graph such that if there is a path from Vi to Vj , then Vj appears after Vi in the linear ordering. 15.What is graph traversal?
16.Name any two graph traversal. Depth First Traversal Breadth First Traversal.
do w
nl o
17.What is the Application of Breadth First Search? To check whether the graph is connected or not.
18.Name the two types of shortest path problems. The single source shortest path problem. The all pairs shortest path problem. 19.List any two algorithm for Minimum Spanning Tree? Prims Algorithm. Kruskals Algorithm
ad ed
fro m
re j
in
pa ul .c
om
20.What is Depth First Search? It works by selecting one vertex as start vertex.V is marked as visited.Then each unvisited vertex adjacent to V is searched in turn using Depth first search recursively. 21.What are the applications of DFS? 1.To check whether the undirected graph is connected or not. 2.To check whether the connected undirected graph is Bioconnected or not. 3.To check the Acyclicity of the directed graph. 22.What is Bioconnectivity?
A connected undirected graph is bioconnected if there are no vertices whose removal disconnects the rest of the graph.
A graph is said to be Euler path if it can be traced in 1 sweep without lifting the pencil from the paper and without tracing the same edge more than once.
Eulers Circuit is similar to an Euler path,except that the starting and ending points must be same. 25.List some of the examples of NP Complete Problems? Hamilton Circuit Travelling Salesman Problem. Knapsack ,graph coloring , Bin Packing and Partition problem. PART B 1. What is topological sort?Write down the pseudocode to perform topological sort? 2. Explain Prims and Kruskals algorithm in detail? 3. Explain bioconnectivity? 4. Explain depth first traversal?
do w
nl o
ad ed
fro m
re j
in
pa ul .c
om
Dijkstras Shortest path algorithm. Kruskals algorithm Prims algorithm 3. List the applications that uses greedy technique? Coin Change Job Scheduling File Compression Bin Packing 4. What is Huffmans algorithm?
It works by selecting two characters having the lowest probabilities and replacing them with a single character whose probability is the sum of the probabilities of two characters. 5.What is bin packing?
This algorithm pack the items in the fewest number of bins,where each bin has unit capacity
do w
nl o
6.What are the different versions of bin packing algorithm? Online algorithm Offline algorithm.
7.What is Next Fit? It checks to see whether the item fits in the same bin as the last item. If it does, it is placed there, otherwise new bin is created. 8.what are the advantages of Next Fit? Simple to implement Runs in linear time.
ad ed
fro m
re j
in
pa ul .c
om
It works in Phases.In each phase a decision is made considering the local optimum at that time that appears to be good,without considering the future consequences.
Easy to analyze the worst-case behavior. 9.what is the disadvantage of Next Fit ? Wastage of Space. 10.What is First Fit?
11.What are the advantages of First Fit? Simple to implement. Runs in O(N2) as well as O(N log N) 12.What is the disadvantage of First Fit? Wastage of memory. 13.What is Best Fit?
15. What is the disadvantage of Best Fit? Does not perform better for random inputs.
do w
nl o
In this all items are read first and sorted placing the largest items first.Then apply the first fit or best fit. 17. What is Divide and Conquer Technique? Divide: Smaller problems are solved recursively. Conquer: The solution to the original problem is then formed from the solutions to the sub problems. 18. What are the classic examples of Divide and Conquer? Merge Sort
ad ed
Performance is more than next fit and first fit. Less wastage of memory.
fro m
The best fit strategy places a new item in the highest among all bins instead of placing in the first spot that is found.
re j
in
pa ul .c
The first fit strategy scans the bins in order and place the new item in the first bin that is large enough to hold it.
om
Quick Sort Binary Search Matrix Multiplication 19.What are the applications that uses Divide and Conquer Technique? Computational Geometry. Closest points problem The selection problem
20.What is the running time of Divide and Conquer algorithm for merge sort? T(N)=2T(N/2)+O(N) 21.What is dynamic programming?
23.What is the application of Optimal Binary Search Trees? To implement dictionary ,a set of elements with the operations of searching , insertion and deletion.
24.What is Back tracking algorithm? It is a search technique to replace the last component of the partially constructed solution with next option.
do w
nl o
25.Give example for Backtracking algorithm? 1.The turnpike reconstruction problem 2.To select moves in computer games such as chess and checkers.
26. Give some examples for Branch and Bound algorithm? Assignment Problem Knapsack Problem
ad ed
fro m
All-pairs shortest path Optimal binary search tree Ordering of Matrix Multiplication.
re j
in
pa ul .c
om