Vous êtes sur la page 1sur 18

EX.

NO:1

LINKED LIST

1. Define data structures and its types. Data structure is the structural representation of logical relationships between collection of data element. It represents the way of storing organizing and retrieving data. It is classified as Linear data structure Nonlinear data structure

2. State few examples for linear and non linear data structure Linear data structure: List, Stack, Queue Non linear data structure: Tree, Graph.

3. What are the types of implementations in data structures? All the data structures can be implemented using two ways. Arrays Linked list

4. Define abstract data types (ADT)? Abstract data type is a set of operations of data. It also specifies the logical and mathematical model of the data type. Examples : Lists, Sets and Graphs along with their operations.

5. Define list . A list is a collection of elements. It can be represented as A1, A2, A3.An and its size is n. A list with size 0 is called as an empty list. For any list except empty list say that

Ai+1 follows Ai(i<n) and Ai-1 proceeds Ai(i>1). The first element is A1 and last element is AN, I is the position.

6. Define linked list. Linked list is a list which is implemented using structures and pointers. In order to avoid the linear cost of insertion and deletion it is not stored contiguously in linked list.

A linked list L
HEADER

1.NULL A 4 4 4 4 4 7. Difference between linked list and array implementation. 4 Liked list Array implementation 4 4 It is implemented using structures and It is implemented using array 4 pointers. 4 4 A1 A2 A3

Insertion and deletion are expensive.

The running time for insertion and deletion is so slow.

8. How a node is created in a singly linked list? The memory needed to store the node is allocated and the pointers are set up. The node is created by struct Node * ptr; ptr=(struct Node *)malloc(sizeof(struct NODE); struct Node { int element; struct Node*Next; } malloc( ) is a predefined function used for dynamic memory allocation. free( ) is used for deallocate the memory to make it available for future use.

9. What is a pointer? Pointer is a variable that contains the address of another variable or data.

10. When curser based linked list is used? Many languages, such as BASIC and FORTRAN do not support pointers. If linked lists are required and pointers are not available, then an alternative implementation must be used. Thus curser based linked lists are used in such cases . 11. Write a function to test whether a linked list is empty. If the linked list is empty it returns the value 1 otherwise 0. It is done by checking the next pointer of header. If it is NULL, then the list is empty.

int IsEmpty(List L) { return L-> Next==NULL } else return 0; if(L->Next==NULL) return 1;

12. Applications of linked list. For representing polynomials. It means addition, subtraction, multiplication etc of two polynomials For representing sparse matrix.

EX.NO:2

DOUBLY LINKED LIST

1. What is doubly linked list? Doubly linked list is a list which is implemented using structures and pointers. struct Node { int element; sruct Node*prev; struct Node*Next; } Each structure has three fields Data. Pointer to previous structure. Pointer to next structure.

2.

Advantages of doubly linked list The doubly linked list can be traversed in the backward direction. It simplifies the direction because no longer have to refer to a key by using a pointer to the previous cell.

3. Structure of a node in a doubly linked list. The structure of a node in double linked list has three fields. They are Data Pointer to previous structure Pointer to next structure.

HEADER A DOUBLY LINKED LIST

A1

A2

A3

NULL

EX.NO:3

POLYNOMIAL ADDITION USING LINKED LIST

1. What is a structure of a node in linked list which is used for polynomial addition? An abstract data type for single variable polynomials can be defined by using a list. A structure of a node in a linked list which is used polynomial addition is struct Node { int coeff; int exp; struct Node*Next; }

EX.NO:4 CONVERSION OF INFIX TO POSTFIX EXPRESSION USING A STACK

1. Define stack. Stack is a list with the restriction that insertion and deletion can be performed in only one end,namely, the end of the list called the top. It is also sometimes called as LIFO(Last In First Out).

2. What are the fundamental operations on a stack? The fundamental operations on a stack are Push inserts an element at the top. Pop deletes the most recently inserted element.

STACK MODEL

pop(s)
Stack S

push(x,s)

top(s)

3. Give example of infix and postfix expressions. Infix expression : a+b*c+(d*e+f)*g Postfix expression : abc*+def+g*+

4. Give some applications of stack. Balancing symbols Postfix expressions

Infix to postfix conversion Function calls

5. Convert a given infix expression to postfix expression (a+b)*(c-d) Infix expression : (a+b)*(c-d) Postfix expression : ab+cd-*

6. Draw the expression tree of the following expression (a+b)*[c*(d+e)]

* * +

EX.NO:5

DOUBLE ENDED QUEUE

1. Define queue. Queue is a list with a restriction that insertion can be done at one end called rear and deletion can be done at the other end called front. It is also called as first in first out.

2. What are the operations performed on queue? There are two operations Insertion or enqueue. Deletion or dequeue.

3. Give some applications of queue. Printer : when jobs are submitted to a printer, they are arranged in order of arrival. Thus job sent to a line printer are placed in a queue. Large companies : calls to large companies are generally placed on a queue when all operations are busy.

4. What is double ended queue? A double ended queue which is abbreviated to dequeue is an abstract data type that generalizes a queue for which elements can be added to or removed from either the front or back. It is also called as head tail linked list.

5. What is circular queue? Circular queue is a linear data structure which follows FIFO principle. It is made by joining the front and rear ends of the queue. In circular queue,the last node is connected back to the first node. Both the front and the rear pointer points to the beginning of the array.

EX.NO:6 IMPLEMENTATION OF AN EXPRESSION TREE AND PRODUCING INORDER PREORDER AND POST ORDER TRAVERSALS

1. Define binary tree? A binary tree is a tree in which no node can have more than two children.

ROOT

Tl

Tr

GENERIC BINARY TREE

2. What is tree traversal? Mention the types of traversals. Tree traversal is the process of visiting all the nodes in a tree only once. There are three types of traversals. They are Inorder traversals Preorder traversals Post order traversals. 3. Write the algorithm for inorder traversal and give an example. Algorithm: Step 1: Process the left child. Step 2: process the root. Step 3: process the right child.

Example:

The inorder traversal is ABCDEFG

4. Write the algorithm for preorder traversal and give an example Step 1: process the root node. Step 2: process the left child. Step 3: process the right child.

The preorder traversal is FBADCEG

5. Write the algorithm for post order traversal given an example. Step 1: process the left child. Step 2; process the right child. Step 3: process the root.

A D

The post order traversal is ACEDBGE

6. Draw the expression tree for the following expression (a+b)*[c*(d+e)]

7. Define expression tree. Expression tree is a binary tree in which leaves are operands such as constants or variable names and the other nodes contain operations.

Example: (a+b*c)+((d*e+f)*g)

EX.NO:7

IMPLEMENTATION OF BINARY SEARCH TREE

1. Define binary search tree. Binary search tree is a binary tree with the following condition. For every node X1, 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 all the keys in its right subtree are larger than the key value in X.

Example:

6 2 8

2. Show the result of inserting 3,1,4,6,9,2,5,7 into an initially empty binary search tree.

3. Conditions of binary search tree Binary search tree is a binary tree in which no node can have more than two children. For every node X1, in the tree, the values of all the keys in its left subtree are smaller than the key values in X and the values of all the keys in its right subtree are larger than the key value in X.

4. For the given tree a. Which node is the root b. Which node are leaves

a. The root node is A. b. The leaves are D , E, andB.

5. For the given tree a. Name the parent node b. List the children c. Compute the height d. Compute the depth.

a. b. c. d.

The parent nodes are A,C The children nodes are B,C,D,E The height of the tree is 2. The depth of the tree is 0.

6. Define leaves, siblings , path in a tree. Leaves : nodes with no children are known as leaves Siblings: nodes with the same parent are siblings. Path: A path from node n,to nx is defined as a sequence of nodes n1,n2..nk such that ni is the parent of ni+1 for 1<=i<k. In a tree there is exactly one path from the root to each node.

7. Define depth and height of a tree. Depth: For any node ni, the depth of ni is the length of the unique part from the root to ni. Thus the depth of root is 0. Height: The height of ni is the length of the longest path from ni to leaf. Thus all leaves are at height 0. The height of the tree is equal to the height of the root.

Vous aimerez peut-être aussi