G. H. RAISONI COLLEGE OF ENGG NAGPUR-16 Session 2006-2007 DEPARTMENT CSE Semester IV SUBJECT DSPD LIST OF EXPERIMENTS 1.Make a database . The record tag ,TStudent consists of these fields: Name[20],RollNo.[5],Address[40],Phone[12],UT-1[2,from1 to 20],UT2[2,from 1 to 20],PUT[3,1 TO 100],Total[3,from 1 to 140] User should able to add new, edit existing, view student in a list, delete the record also. 2.Write a program for two polynomial additions and subtraction without using records And by using records also. 3.Write a program for sorting into the linked list. 4. Write program to create, insert and delete elements in a linked list. 5. Write a program to implements a stack using array. 6.Write a program to insert ,delete element in queue. 7. Write a program for addition and deletion in the circular queue. 8. Write a program for creation of binary search tree and Inorder traversal. 9.Write a program to create a BST by inserting a node & Preorder ,Inorder and Postorder Traversal. 10. Write a program to store and retrive data of student in a class. The data is stored ina file name ‘file.dat’. Experiment no. :--1 Aim :-- Make a database . The record tag ,TStudent consists of these fields: Name[20],RollNo.[5],Address[40],Phone[12],UT-1[2,from1 to 20],UT-2[2,from 1 to 20],PUT[3,1 TO 100],Total[3,from 1 to 140] User should able to add new, edit existing, view student in a list, delete the record also. Theory:-- A record is a collection of data item, usually different datatypes which are logically combined into single unit. The record is a heterogeneous component datatype as it is composed of data element s that may be of different data types. The components of a records are called fields. Each fields has an identifier and a datatype . Declaration :-1)Record :type<recordname>=record <Member 1>: <type> <member2> :<type> . . <member n> : <type> End; 2) Array of Record Var <nametype> : array of [l..u] of <recordname> Diagram :-- Flowchart of program. Algorithm Record:-1.Declare the Records, Array And type of variables. 2.Create the Menu a)Add new Record. b)Edit the Existing. c)View the List. d)Delete the Record. 3.To Add new record in a list WhileA[i]<=u A[i].name=’name’; A[i].roll=123; A[i].address= ‘Address’; A[i].phone= 12233; A[i].address= 19; A[i].address= 17; A[i].address= 99; A[i].address= 139; i=i+1; 4.To view the list Display all the fields of record by using write statement; 5.To delete the record from the list Sample input/Sample output:--Execute the program for sample values. Result :--- Viva voice • • • • • • What is mean by array. How to define it . What is the record . How to declare it. How to store value in the array How to use Array of record. Experiment No.:--2 Aim: -- Write a program for two polynomial additions and subtraction without using records and by using records also. Theory:--An important application of linked list is to represent Polynomials and their manipulations. In addition and subtraction of two polynomials, say P & Q to get resultant polynomial R, have to compare their terms stating at the first nodes and moving towards the end one by one. Declaration:-Type <PointerType> : ^<Referenced datatype>; Type intpointer = ^ integer; Var counter: intpointer; Diagram:-- Flowchart of program. Algorithm: -- Steps use to implement the coding. 1.Declare the Records, Array And type of variables. 2.Create the Menu a)Add new Record. b)Subtraction. 3.Pptr=PHEADER.LINK,Qptr= QHEADER.LINK 4. RHEADER=GETNODE(NODE) 5.RHEADER.LINK=NULL RHEADER.EXP=NULL,RHEADER.COEFF=NULL 6.Rptr=RHEADER 7.WHILE(Pptr!=NULL)AND(Qptr!= NULL) do 1 CASE:Pptr.EXP 1. NEW= GETNODE(NODE) 2.Rptr.LINK=new, Rptr=new 3.Rptr.COEFF=P.COEFFptr.+ Qptr.COEFF 4.Rptr.EXP=Pptr.EXP 5. Rptr.LINK=NULL 6.Pptr=Pptr.LINK,Qptr=Qptr.LINK 2 CASE:Pptr.EXP>Qptr.Exp 1. NEW=GETNODE(NODE) 2.Rptr.LINK=new, Rptr=new 3.Rptr.COEFF=Pptr.COEFF 4.Rptr.EXP=Pptr.EXP 5. Rptr.LINK=NULL 6.Pptr=Pptr.LINK 3 CASE:Pptr.EXP<Qptr.Exp 1. NEW=GETNODE(NODE) 2.Rptr.LINK=new, Rptr=new 3.Rptr.COEFF=Qptr.COEFF 4.Rptr.EXP=Qptr.EXP 5. Rptr.LINK=NULL 6.Qptr=Qptr.LINK 8.Endwhile 9.If(Pptr1!=NULL)AND(Qptr=NULL) then 1.While((Pptr1= Null)do 1. NEW=GETNODE(NODE) 2.Rptr.LINK=new, Rptr=new 3.Rptr.COEFF=Pptr.COEFF 4.Rptr.EXP=Pptr.EXP 5. Rptr.LINK=NULL 6.Qptr=Qptr.LINK 2. Endwhile 10. Endif 11. If(Pptr1=NULL)AND(Qptr!=NULL) then 1.While((Pptr1= Null)do 1. NEW=GETNODE(NODE) 2.Rptr.LINK=new, Rptr=new 3.Rptr.COEFF=Qptr.COEFF 4.Rptr.EXP=Qptr.EXP 5. Rptr.LINK=NULL 6.Qptr=Qptr.LINK 2. Endwhile 12. Endif 13. Return(RHeader) 14. stop. Sample Input/Sample Output: --- Execute the program for some sample values. Result:-- Viva voice:-• • • Definition of pointers How to declare the pointer. General form of the polynomial. • How to add two polynomials. Experiment No.:--3 Aim: -- 3.Write a program for search an element in sorted the linked list. Theory:--A link list is an ordered collection of finite , homogeneous data element s called nodes where the linear order is maintained by means of links or pointers. Declaration:-Type <PointerType> : ^<Referenced datatype>; Type intpointer = ^ integer; Var counter: intpointer; Diagram:-- Flowchart of program. Algorithm: -- Steps use to sort the elements in linked list. SRCHSL(INFO,LINK,START,ITEM,LOC) LIST is a sorted list in memory. This algorithm find the location LOC of the node where ITEM first appears in LIST , or sets LOC = NULL 1. Set PTR :=START. 2. 2. Repeat Steps 3 while PTR <> NULL 3. If ITEM<INFO[PTR], then: Set PTR=LINK[PTR] Else if ITEM:=INFO[PTR],Exit. Else: Set LOC :=NULL,and Exit. 4. Set LOC :=NULL 5. Exit. Sample Input/Sample output: --- Execute the program for some sample values. Result:-- Viva voice:-• • • • • • Definition of pointers How to declare the pointer. Definition of pointer to pointer What is single link list Circular linked list Double link list. Experiment No.:--4 Aim: -- 4. Write program to create, insert and delete elements in a linked list. Theory:--An important operation on a linked list. Traversing a list Insertion of a node into a list. Deletion of a node from the list. Searching for an element in a list. Merging two linked list into a larger list. Declaration:-Type <Pointer Type> : ^<Referenced datatype>; Type intpointer = ^ integer; Var counter: intpointer; Diagram:-- Flowchart of program. Algorithm: -- Steps use to implement the coding. INSERT-SL-ANY(HEADER,X,KEY) 1. new = GETNODE(NODE) 2. If (new = NULL) then a. Print “Memory is insufficient : Insertion is not possible” b. Exit. 3. Else a. Ptr= HEADER b. While(PTR.DATA<>key)and(ptr.LINK<> NULL) do 1. ptr = ptr1.LINK c. Endwhile e. If (ptr.LINK = NULL) then 1. Print “Key is not available in the list” 2. Exit f. Else 1. new.LINK = ptr.LINK 2. new.data= x 3. ptr.LINK= NEW g. Endif 4. Endif 5. Stop Sample Input/Sample output :--- Execute the program for some sample values. Result:-- Viva voice:-• • • • • Definition of pointers How to declare the pointer. How to insert node in the linked list. Define the Header. How to delete the node at the last position in the linked list. Experiment No.:--5 Aim: --.Write a program to implement stack using array. Theory:--A stack is an ordered collection of homogeneous data element where the insertion and deletion operation take place at one end only. An n-element array can be used to implement a stack with capacity n . The stack top is indicated by the the index top and it points to the element that was entered into the stack. Declaration:-Type Stack = array [1.. stacksize] of integer; Stacklimit = 0..stacksize; Var s: stack Diagram:-- Flowchart of program. Algorithm: -STATUS_A() Input :-- A stack with elements. Output : States whether it is empty or full , available free space and item at TOP . Data Structure : An Array A with TOP as the pointer. Steps 1. If TOP<1 1. Print “Stack is Empty” 2. Else 1.If(TOP>= SIZE) then a. Print “Stack is full” 2. Else 1. Print “The element at TOP is .” A[TOP] 2. free = (SIZE- TOP)/SIZE * 100 3. Print “ Percentage of free stack ”,free 3. Endif 4. Stop. Sample Input /Sample output: --- Execute the program for some sample values. Result:-- Viva voice:-• • • • • Definition of Stack What are the different operations on the stack. Applications of the stack. Define PUSH operation Define POP operation. Experiment No.:--6 Aim: -- Write a program to insert ,delete element in queue. Theory:-- A Queue is an ordered collection of homogeneous data elements where the insertion and deletion operation take place at two extreme ends. Declaration:-Type queue = array [1.. n] of integer; Var p: queue Diagram:-- Flowchart of program. Algorithm: -- Steps use to implement the coding. ENQUEUE(ITEM) Input : An element ITEM that has to be inserted. Output : The ITEM is at the REAR of the Queue. Data Structure : Q is the array representation of queue structure ; two pointers FRONT and REAR of the queue Q are known. Steps: 1. If(REAR = N) then a. Print “Queue is full” b. Exit 2. Else 1. If (REAR = 0)and (FRONT = 0) a.FRONT = 1 2. Endif 3. REAR = REAR+1 4. Q[REAR] = ITEM 3. Endif 4. Stop. Sample Input/Sample Output: --- Execute the program for some sample values. Result:-- Viva voice:-• • • • • Definition of Queue How to use queue in program Explain the operations on the Queue Types of Queue Application of Queue.. Experiment No.:--7 Aim: -- Write a program for addition and deletion in the circular queue. Theory:-- A Queue is an ordered collection of homogeneous data elements where the insertion and deletion operation take place at two extreme ends. Declaration:-Type queue = array [1.. n] of integer; Var p: queue Diagram:-- Flowchart of program. Algorithm: -- Steps use to implement the coding. ENQUEUE(ITEM) Input : An element ITEM that has to be inserted into the circle queue. Output : The circular queue with the ITEM is at the FRONT if the Queue is not full. Data Structure :CQ is the array to represent the circular queue ; two pointers FRONT and REAR of the queue CQ are known. Steps: 1. If(FRONT = 0) then 1.FORNT = 1 2. REAR = 1 3. CQ[FRONT] = ITEM 2. Else 1. next = (REAR MOD LENGTH)+1 2. If(next<>FRONT) then 1. REAR = next 2. CQ[REAR] = ITEM 3. Else 1. Print “Queue is full” 4. Endif 3. Endif 4. stop Sample Input/Sample output: --- Execute the program for some sample values. Result:-- Viva voice:-• • • • • • Definition of Queue How to use queue in program Explain the operations on the Queue Types of Queue Application of Queue.. Define CIRCULAR queue Experiment No.:--8 Aim: -- Write a program for creation of binary search tree and Inorder traversal. Theory:-- A binary tree t is termed as binary search tree if each node N of T satisfies the value at N is greater than every value in the left sub-subtree of N and is less than every value in the right sub tree of N. In INORDER traversal , before visiting the root node ,left sub-tree of the root is to be visited then root node and after the visit of the root node right sub-tree of the root node will be visited . Visit of both Sub-trees again will be in the same fashion . Declaration:-Type ptr = ^node; Node = record Lptr :ptr; Val: char: Rptr : ptr; Diagram:-- Flowchart of program. Algorithm: -- Steps use to implement the coding. Algorithm INORDER(ROOT) Input : ROOT is the pointer to the root node of the binary tree. Out put : Visiting of all the nodes inorder fashion. Data Structure : Linked structure of Binary tree. Steps 1. ptr = ROOT 2. If (ptr <> NULL) 1. INORDER(ptr.LC) 2. VISIT(ptr) 3. INORDER(ptr.rc) 3. Endif 4. Stop Sample Input/Sample output: --- Execute the program for some sample values. Result:-- Viva voice:-• • • • • Define BINARY tree How to represent binary tree in memory location Advantages and Disadvantages of binary tree. Operations on binary tree. Traversals of the binary tree Experiment No.:--9 Aim: -- Write a program to create a BST by inserting a node & Preorder ,Inorder and Postorder Traversal. Theory :-- A binary tree t is termed as binary search tree if each node N of T satisfies the value at N is greater than every value in the left sub-subtree of N and is less than every value in the right sub tree of N. Declaration:-Type ptr = ^node; Node = record Lptr :ptr; Val: char: Rptr : ptr; Diagram:-- Flowchart of program. Algorithm: -- Steps use to implement the coding. Input: ITEM is the data component of a node that has to be inserted. Output : If there is no node having data ITEM , it is inserted into the tree else a message . Data Structure : Linked Structure of binary tree, Pointer to the root node is ROOT Steps 1. ptr = ROOT , flag = FALSE 2. While(ptr<> NULL) and (flag = FALSE) 1. Case : ITEM < ptr.DATA 1. ptr1 = ptr 2. ptr = ptr.LCHILD 2. Case : ITEM> ptr.DATA 1. ptr1 = ptr 2. ptr = ptr.RCHILD 3. Case : ptr.DATA =ITEM 1. flag = TRUE 2. Print “ITEM already exits” 3. Exit 4. End Case 3. End while Sample Input/Sample output: --- Execute the program for some sample values. Result:-- Viva voice:-• • • • • Define BINARY tree How to represent binary tree in memory location Advantages and Disadvantages of binary tree. Operations on binary tree. Traversals of the binary tree Experiment No. :--10. Aim :--Write a program to store and retrieve data of student in a class. The data is stored in a file name ‘file.dat’. Theory:-- The various types of the file organization are 1)Sequential 2)Random 3) Linked 4)Internal Files Declaration:-Type <PointerType> : ^<Referenced datatype>; Type intpointer = ^ integer; Var counter: intpointer; Diagram:-- Flowchart of program. Algorithm: -- Steps use to implement the coding. Input: ITEM is the data component of a node that has to be inserted. Output : If there is no node having data ITEM , it is inserted into the tree else a message . Data Structure : Linked Structure of binary tree, Pointer to the root node is ROOT Steps 1.start 2. Declare record type variable name student having 3 fields 1 string type variable & integer variable storing the name ,rollno & marks of a student respty. 3. Declare two integer variable 4. Declare a variable of the type student 5. Declare the file variable having having the information student in the data type student 6. Display the message “Program to create a sequential file of student 7. Asign the file variable with the file name 8. write in the file new 9. Repeat steps 10 &1 for n>0 10. Display the massage “Enter the no of Sequential files 11. Accept the response from the user 12. Repeat steps 13 to 21 for n times 13. with the record type variable do steps 14 to 20 14. Display message “Name is “ 15. Accept the name from user 16. Display message “age is “ 17. Accept the age from user 18. Display message “Enrolment is “ 19. Accept the enrolment from user 20. write all the information in a file 21. end for loop 22. Reset file pointer of the file 23. Display the massage the data file contain the following information 24. Repeat steps 25 ,26 as long as the end of file is reached 25. Read the information for the student from file 26. Display the information for each from the file 27. stop Sample Input/Sample output: --- Execute the program for some sample values. Result:-- Viva voice:-• • • • • Explain the types of file organization Advantages of sequential file Disadvantage of the random file Advantage of the Internal files Explain operation on the file.