Dev Bhoomi Institute Of Technology. Department of Computer Application EXPERIMENT NO. ISSUE NO. : ISSUE DATE: REV. NO. : REV.

Size: px
Start display at page:

Download "Dev Bhoomi Institute Of Technology. Department of Computer Application EXPERIMENT NO. ISSUE NO. : ISSUE DATE: REV. NO. : REV."

Transcription

1 LIST OF PRACTICALS 1. Matrix Operations-Add and Multiply 2. String Operations strlen(), strcat() etc. 3. Stack operations using Arrays. 4. Implementing Polish Notations using Stacks. 5. Evaluating postfix notation. 6. Queues operations using Arrays. 7. Circular queue using arrays. 8. Dequeue using array. 9. Self-referential structures & single linked list operations 10. Implementing Stack using linked lists. 11. Implementing Queue using linked lists. 12. Self-referential structures &doubly linked list operations 13. LinearSearch. 14. Binary Search 15. Selection Sort. 16. Bubble Sort. 17. Insertion sort.

2 18. Merge sort. 19. Quick sort. 20. Radix (bucket) sort method. 21. Binary Search Tree operations. 22. Heap sort & AVL tree implementations. 23. Write a program in C for DFS

3 1. Matrix Operations-Add and Multiply /* Addition */ #include<stdio.h> #include<conio.h> int main() int m, n, i, j, first[10][10], second[10][10], sum[10][10]; printf("enter the number of rows and columns of matrix\n"); scanf("%d%d", &m, &n); printf("enter the elements of first matrix\n"); for (i = 0; i< m; i++) for (j = 0; j< n; j++) scanf("%d", &first[i][j]); printf("enter the elements of second matrix\n"); for (i = 0; i< m; i++) for (j = 0; j< n; j++) scanf("%d", &second[i][j]); printf("sum of entered matrices:-\n"); for (i = 0; i< m; i++) for (j = 0; j< n; j++) sum[i][j] = first[i][j] + second[i][j]; printf("%d\t", sum[i][j]); printf("\n"); return 0;

4 /* Multiplication */ #include <stdio.h> int main() int m, n, p, q, i, j, k, sum = 0; int first[10][10], second[10][10], multiply[10][10]; printf("enter the number of rows and columns of first matrix\n"); scanf("%d%d", &m, &n); printf("enter the elements of first matrix\n"); for (i = 0; i< m; i++) for (j = 0; j< n; j++) scanf("%d", &first[i][j]); printf("enter the number of rows and columns of second matrix\n"); scanf("%d%d", &p, &q); if (n!= p) printf("matrices with entered orders can't be multiplied with each other.\n"); printf("enter the elements of second matrix\n"); for (i = 0; i< p; i++) for (j = 0; j< q; j++) scanf("%d", &second[i][j]); for (i = 0; i< m; i++) for (j = 0; j< q; j++) for (k = 0; k < p; k++) sum = sum + first[i][k]*second[k][j];

5 multiply[i][j] = sum; sum = 0; printf("product of entered matrices:-\n"); for (i = 0; i< m; i++) for (j = 0; j< q; j++) printf("%d\t", multiply[i][j]); printf("\n"); return 0;

6 2. String Operations strlen(), strcat() etc. #include <stdio.h> #include <string.h> int main() char a[20]="program"; char b[20]='p','r','o','g','r','a','m','\0'; char c[20]; printf("enter string: "); gets(c); printf("length of string a = %d \n",strlen(a)); //calculates the length of string before null charcter. printf("length of string b = %d \n",strlen(b)); printf("length of string c = %d \n",strlen(c)); return 0; #include <stdio.h> #include <string.h> int main()

7 char str1[10]= "awesome"; char str2[10]; char str3[10]; strcpy(str2, str1); strcpy(str3, "well"); puts(str2); puts(str3); return 0; #include <stdio.h> #include <string.h> int main() char str1[] = "This is ", str2[] = "programiz.com"; //concatenates str1 and str2 and resultant string is stored in str1. strcat(str1,str2); puts(str1); puts(str2);

8 return 0; #include <stdio.h> #include <string.h> int main() char str1[] = "This is ", str2[] = "dbgidoon.ac.in"; //concatenates str1 and str2 and resultant string is stored in str1. strcat(str1,str2); puts(str1); puts(str2); return 0; #include <stdio.h> #include <string.h> int main() char str1[] = "abcd", str2[] = "abcd", str3[] = "abcd";

9 int result; // comparing strings str1 and str2 result = strcmp(str1, str2); printf("strcmp(str1, str2) = %d\n", result); // comparing strings str1 and str3 result = strcmp(str1, str3); printf("strcmp(str1, str3) = %d\n", result); return 0;

10 3. Stack operations using Arrays. #include<stdio.h> #include<conio.h> #include<stdlib.h> #define MAX 10 struct stack int items[max]; int top; ; typedef struct stack st; void createemptystack(st *s) s->top=-1; int isfull(st *s) if (s->top==max-1) return 1;

11 return 0; int isempty(st *s) if (s->top==-1) return 1; return 0; void push(st *s) int newitem; printf("enter item to be inserted: "); scanf("%d",&newitem); if (isfull(s)) printf("stack FULL"); s->top++; s->items[s->top]=newitem;

12 void pop (st *s) if (isempty(s)) printf("\n STACK EMPTY \n"); printf("item popped= %d",s->items[s->top]); s->top--; void main() int ch; int loop; loop=1; st *s;

13 createemptystack(s); do printf("\n ***STACK OPERATIONS"); printf("\n 1. PUSH"); printf("\n 2. POP"); printf("\n 3. EXIT"); printf("\n ***************"); printf("\n Enter your choice: "); scanf("%d", &ch); switch (ch) case 1: push(s); break; case 2: pop(s); break; case 3: printf("thank YOU"); loop=0; exit(0);

14 default: printf("invalid choice"); while(loop); getch();

15 4. Implementing Polish Notations using Stacks. #include<stdio.h> #include<conio.h> #include<stdlib.h> #include<ctype.h> char Stack[25]; //Operator stack int top; char Infix[25],Postfix[25]; void Convert() int i=0,j=0; while(infix[i]!=0) char ch=infix[i++]; if(isalpha(ch)) Postfix[j++]=ch; while(top!=-1&&precedence(stack[top],ch)) Postfix[j++]=Stack[top--]; if(top==-1 ch!=')') Stack[++top]=ch; while(top!=-1) char c=stack[top--]; if(c!='(') Postfix[j++]=c; Postfix[j]='\0';

16 int Precedence(char top,char cur) if(top!='('&&cur==')') return 1; if((top=='$' top=='*' top=='/')&&(cur=='*' cur=='/' cur=='+' cur=='-')) return 1; if((top=='+' top=='-')&&(cur=='+' cur=='-')) return 1; return 0; void main() clrscr(); top=-1; printf("\n\n\t\tenter the Valid Infix Expression: "); scanf("%s",infix); Convert(); printf("\n\n\t\tthe Infix Expression : %s",infix); printf("\n\n\t\tthe Postfix Expression : %s",postfix); getch(); OUTPUT Enter the Valid Infix Expression: (a+b * c) / (d$e) The Infix Expression : (a+b * c) / (d$e) The Postfix Expression : abc*+de$/

17 5. Evaluating postfix notation. #include<stdio.h> #include<conio.h> #include<stdlib.h> #include<ctype.h> #include<math.h> float Stack[25]; //Operand Stack... int top; char Postfix[25]; int flag; float Evaluate() int i=0; while(postfix[i]!='\0') char ch=postfix[i++]; if(isalpha(ch)) printf("\n\n\tenter value of %c: ",ch); scanf("%f",&stack[++top]); if(top<1) flag=0; float op1,op2; op2=stack[top--]; op1=stack[top--]; switch(ch) case '+': Stack[++top]=op1+op2; break; case '-': Stack[++top]=op1-op2; break;

18 case '*': Stack[++top]=op1*op2; break; case '/': Stack[++top]=op1/op2; break; case '$': case '^': Stack[++top]=pow(op1,op2); break; default: printf("\n\n\tinvalid Character: %c",ch); flag=0; if(top!=0) flag=0; return( Stack[top--]); void main() float result; clrscr(); top=-1; flag=1; printf("\n\n\n\t\tenter the Valid Postfix Expression: "); scanf("%s",postfix); result=evaluate(); printf("\n\n\tinvalid Postfix Expression..."); if(flag==1) printf("\n\n\tthe Result of Postfix Expression %s is: %.3f",Postfix,result); getch(); OUTPUT Enter the Valid Postfix Expression: ab+c/ Enter value of a: 4

19 Enter value of b: 2 Enter value of c: 3 The Result of Postfix Expression ab+c/ is: 2.000

20 6. Queues operations using Arrays. #include<stdio.h> #include<conio.h> #define SIZE 10 void enqueue(int); void dequeue(); void display(); int queue[size], front = -1, rear = -1; void main() int value, choice; clrscr(); while(1) printf("\n\n***** MENU *****\n"); printf("1. Insertion\n2. Deletion\n3. Display\n4. Exit"); printf("\nenter your choice: "); scanf("%d",&choice); switch(choice) case 1: printf("enter the value to be insert: "); scanf("%d",&value); enqueue(value);

21 break; case 2: dequeue(); break; case 3: display(); break; case 4: exit(0); default: printf("\nwrong selection!!! Try again!!!"); void enqueue(int value) if(rear == SIZE-1) printf("\nqueue is Full!!! Insertion is not possible!!!"); if(front == -1) front = 0; rear++; queue[rear] = value; printf("\ninsertion success!!!"); void dequeue() if(front == rear) printf("\nqueue is Empty!!! Deletion is not possible!!!");

22 printf("\ndeleted : %d", queue[front]); front++; if(front == rear) front = rear = -1; void display() if(rear == -1) printf("\nqueue is Empty!!!"); int i; printf("\nqueue elements are:\n"); for(i=front; i<=rear; i++) printf("%d\t",queue[i]);

23 7. Circular queue using arrays. #include <stdio.h> #define SIZE 5 int items[size]; int front = -1, rear =-1; int isfull() if( (front == rear + 1) (front == 0 && rear == SIZE-1)) return 1; return 0; int isempty() if(front == -1) return 1; return 0; void enqueue(int element) if(isfull()) printf("\n Queue is full!! \n");

24 if(front == -1) front = 0; rear = (rear + 1) % SIZE; items[rear] = element; printf("\n Inserted -> %d", element); int dequeue() int element; if(isempty()) printf("\n Queue is empty!! \n"); return(-1); element = items[front]; if (front == rear) front = -1; rear = -1; /* Q has only one element, so we reset the queue after dequeing it.? */ front = (front + 1) % SIZE;

25 printf("\n Deleted element -> %d \n", element); return(element); void display() int i; if(isempty()) printf(" \n Empty Queue\n"); printf("\n Front -> %d ",front); printf("\n Items -> "); for( i = front; i!=rear; i=(i+1)%size) printf("%d ",items[i]); printf("%d ",items[i]); printf("\n Rear -> %d \n",rear); int main()

26 // Fails because front = -1 dequeue(); enqueue(1); enqueue(2); enqueue(3); enqueue(4); enqueue(5); // Fails to enqueue because front == 0 && rear == SIZE - 1 enqueue(6); display(); dequeue(); display(); enqueue(7); display(); // Fails to enqueue because front == rear + 1 enqueue(8); return 0;

27 8. Dequeue using array. #include<stdio.h> #include<conio.h> #include<stdlib.h> #define MAX 10 int q[max],front=0,rear=0; void add_rear(); void add_front(); void delete_rear(); void delete_front(); void display(); void main() int ch; clrscr(); do //clrscr(); printf("\n DQueue Menu"); printf("\n ");

28 printf("\n 1. AddRear"); printf("\n 2. AddFront"); printf("\n 3. DeleteRear"); printf("\n 4. DeleteFront"); printf("\n 5. Display"); printf("\n 6. Exit"); printf("\n "); printf("\n Enter your choice:-"); scanf("%d",&ch); switch(ch) case 1: add_rear(); printf("\n Queue after insert at rear"); display(); break; case 2: add_front(); printf("\n Queue after insert at front");

29 display(); break; case 3: delete_rear(); printf("\n Queue after delete at rear"); display(); break; case 4: delete_front(); printf("\n Queue after delete at front"); display(); break; case 5: display(); break;

30 case 6: default: while(ch!=6); exit(0); break; printf("\n Wrong Choice\n"); void add_rear() int no; printf("\n Enter value to insert : "); scanf("%d",&no); if(rear==max) printf("\n Queue is Overflow"); return;

31 rear++; q[rear]=no; if(rear==0) rear=1; if(front==0) front=1; void add_front() int no; printf("\n Enter value to insert:-"); scanf("%d",&no); if(front<=1) printf("\n Cannot add value at front end"); return; front--; q[front]=no;

32 void delete_front() int no; if(front==0) printf("\n Queue is Underflow\n"); return; no=q[front]; printf("\n Deleted element is %d\n",no); if(front==rear) front=0; rear=0; front++;

33 void delete_rear() int no; if(rear==0) printf("\n Cannot delete value at rear end\n"); return; no=q[rear]; if(front==rear) front=0; rear=0; rear--; printf("\n Deleted element is %d\n",no);

34 void display() int i; if(front==0) printf("\n Queue is Underflow\n"); return; printf("\n Output"); for(i=front;i<=rear;i++) printf("\n %d",q[i]);

35 9. Self-referential structures & single linked list operations. #include<stdio.h> #include<stdlib.h> Typedef struct nodetype int info; struct node *next; Node; Void CreateEmptyList(Node **s) *s=null; Void InsertatBegininning(Node **s) int item; Node *temp; printf( \n enter the item to insert : ); scanf( %d,&item); temp=(node*)malloc(sizeof(node)); temp->info=item;

36 if(*s==null) temp->next=null; temp->next=*s; *s=temp; void InsertatEnd(Node **s) int item; Node *temp,*current; printf( \n enter the item to insert : ); scanf( %d,&item); temp=(node*)malloc(sizeof(node)); temp->info=item; temp->next=null; if(*s==null) *s=null; current=*s; while(current->next!=null) current=current->next; current->next=temp;

37 void InsertAfter(Node **s) int item,after; Node *temp,*current; printf( \n enter the item to insert : ); scanf( %d,&item); printf( \n enter the afterelement : ); scanf( %d,&after); current=*s; while(current->info!=after && current!=null) current=current->next; if(current==null) printf( \n operation not possible ); temp=(node*)malloc(sizeof(node)); temp->info=item; temp->next=current->next; current->next=temp;

38 void DeletefromStart(Node **s) Node *temp; If(*s==NULL) Printf( \n list is empty ); temp=*s; *s=temp->next; free(temp); void DeletefromEnd(Node **s) Node *temp,*current; If(*s==NULL) Printf( \n list is empty ); if((*s)->next==null) temp=*s; *s=null; free(temp);

39 current=*s; temp=current->next; while(temp->next!=null) current=temp; temp=temp->next; current->next=null; free(temp); void DeleteAfter(Node **s) int after; Node *temp,*loc; printf( \n enter the after element : ); scanf("%d",&after); If(*s==NULL) Printf( \n list is empty );

40 loc=*s; while(loc->info!=after && loc!=null) loc=loc->next; if(loc==null) printf("\n after element not present"); temp=loc->next; loc->next=temp->next; free(temp) ; void DeleteEntireList(Node **s) Node *temp; while(*s!=null) temp=*s; *s=(*s)->next; free(temp);

41 void Display(Node **s) Node *temp; printf("\n\n") if(*s==null) printf("list is empty"); temp=*s; while(temp!=null); printf("%d ",temp->info); temp=temp->next; void Menu() printf("\npress 1 - for Insert at start"); printf("\npress 2 - for Insert at End");

42 printf("\npress 3 - for Insert after"); printf("\npress 4 - for Delete from start"); printf("\npress 5 - for Delete from End"); printf("\npress 6 - for Delete after"); printf("\npress 7 - Delete entire list"); printf("\npress 8 - Display"); printf("\npress 0 - For Exit"); void main() Node *s; int choice; CreateEmptyList(&s); clrscr(); while(1) Menu(); printf("\n enter your choice : "); scanf("%d",&chocie); switch(choice) case 1:InsertatBegininning(&s);

43 break; case 2:InsertatEnd(&s); break; case 3:InsertAfter(&s); break; case 4:DeletefromStart(&s); break; case 5:DeletefromEnd(&s); break; case 6:DeleteAfter(&s); break; case 7:DeleteEntireList(&s); break; case 8:Display(&s); break; case 9:exit(0);

44 default:printf("\n enter only available choices");

45 10. Implementing Stack using linked lists. #include<stdio.h> #include<stdlib.h> Typedef struct nodetype int info; struct node *next; Node; Void CreateEmptyList(Node **s) *s=null; void Push(Node **s) int item; Node *temp,*current; printf( \n enter the item to insert : ); scanf( %d,&item); temp=(node*)malloc(sizeof(node)); temp->info=item; temp->next=null;

46 if(*s==null) *s=null; current=*s; while(current->next!=null) current=current->next; current->next=temp; void Pop(Node **s) Node *temp,*current; If(*s==NULL) Printf( \n list is empty ); if((*s)->next==null) temp=*s; *s=null; free(temp);

47 current=*s; temp=current->next; while(temp->next!=null) current=temp; temp=temp->next; current->next=null; free(temp); void Display(Node **s) Node *temp; printf("\n\n") if(*s==null) printf("list is empty"); temp=*s; while(temp!=null);

48 printf("%d ",temp->info); temp=temp->next; void Menu() printf("\npress 1 - for Push"); printf("\npress 2 - for Pop"); printf("\npress 3 - Display"); printf("\npress 4 - exit"); void main() Node *s; int choice; CreateEmptyList(&s); clrscr(); while(1) Menu();

49 printf("\n enter your choice : "); scanf("%d",&chocie); switch(choice) case 1:Push(&s); break; case 2:Pop(&s); break; case 3:Display(&s); break; case 4:exit(); default:printf("\n enter only available choices");

50 11. Implementing Queue using linked lists. #include<stdio.h> #include<stdlib.h> Typedef struct nodetype int info; struct node *next; Node; Void CreateEmptyQueue(Node **s) *s=null; Void Enqueue(Node **s) int item; Node *temp; printf( \n enter the item to insert : ); scanf( %d,&item); temp=(node*)malloc(sizeof(node)); temp->info=item; if(*s==null) temp->next=null;

51 *s=temp; temp->next=*s; void Dequeue(Node **s) Node *temp; If(*s==NULL) Printf( \n queue is empty ); temp=*s; *s=temp->next; free(temp); void Display(Node **s) Node *temp; printf("\n\n") if(*s==null) printf("queue is empty");

52 temp=*s; while(temp!=null); printf("%d ",temp->info); temp=temp->next; void Menu() printf("\npress 1 - Enqueue"); printf("\npress 2 - Dequeue"); printf("\npress 3 - Dispaly"); printf("\npress 4 - exit"); void main() Node *s; int choice; CreateEmptyQueue(&s); clrscr(); while(1)

53 Menu(); printf("\n enter your choice : "); scanf("%d",&chocie); switch(choice) case 1:Enqueue(&s); break; case 2:Dequeue(&s); break; case 3:Display(&s); break; case 4:exit(0); default:printf("\n enter only available choices");

54 12. Self-referential structures &doubly linked list operations #include<stdio.h> #include<stdlib.h> Typedef struct nodetype int info; struct node *next; struct node *prev; Node; Void CreateEmptyList(Node **s) *s=null; Void InsertatBegininning(Node **s) int item; Node *temp; printf( \n enter the item to insert : ); scanf( %d,&item); temp=(node*)malloc(sizeof(node));

55 temp->info=item; if(*s==null) temp->next=temp->prev=null; temp->next=*s; temp->prev=null; (*s)->prev=temp; *s=temp; void InsertatEnd(Node **s) int item; Node *temp,*current; printf( \n enter the item to insert : ); scanf( %d,&item); temp=(node*)malloc(sizeof(node)); temp->info=item; temp->next=null; if(*s==null) temp->prev=null

56 current=*s; while(current->next!=null) current=current->next; current->next=temp; temp->prev=current; void InsertAfter(Node **s) int item,after; Node *temp,*current; printf( \n enter the item to insert : ); scanf( %d,&item); printf( \n enter the after element : ); scanf( %d,&after); if(*s==null) printf("\n list is empty\n operation not possible"); current=*s;

57 while(current->info!=after && current!=null) current=current->next; if(current==null) printf( \n operation not possible ); temp=(node*)malloc(sizeof(node)); temp->info=item; if(current->next==null) temp->next=null; current->next=temp; temp->prev=current; temp->next=current->next; temp->prev=current; (current->next)->prev=temp; current->next=temp;

58 void InsertBefore(Node **s) int item,after; Node *temp,*current; printf( \n enter the item to insert : ); scanf( %d,&item); printf( \n enter the after element : ); scanf( %d,&after); if(*s==null) printf("\n list is empty\n operation not possible"); current=*s; while(current->info!=after && current!=null) current=current->next; if(current==null) printf( \n operation not possible ); temp=(node*)malloc(sizeof(node)); temp->info=item; if(current->prev==null)

59 temp->prev=null; temp->next=current; current->prev=temp; *s=temp; temp->next=current; temp->prev=current-prev; (current->prev)->next=temp; current->prev=temp; void DeletefromStart(Node **s) Node *temp; If(*s==NULL) Printf( \n list is empty ); if((*s)->next==nul)

60 temp=*s; *s=null; temp=*s; *s=temp->next; (*s)->prev=null; free(temp); void DeletefromEnd(Node **s) Node *temp; if(*s==null) Printf( \n list is empty ); if((*s)->next==nul) temp=*s; *s=null;

61 temp=*s; while(temp->next!=null) temp=temp->next; (current->prev)->next=null; free(temp); void DeleteAfter(Node **s) int after; Node *temp,*loc; if(*s==null) Printf( \n list is empty ); printf( \n enter the after element : ); scanf("%d",&after); loc=*s; while(loc->info!=after && loc!=null) loc=loc->next; if(loc==null)

62 printf("\n after element not present"); if((loc->next)->next==null) temp=loc->next; loc->next=null; free(temp) ; temp=loc->next; loc->next=temp->next; (temp->next)->prev=loc; free(temp); void DeleteBefore(Node **s) int before; Node *temp,*loc; if(*s==null) Printf( \n list is empty );

63 printf( \n enter the after element : ); scanf("%d",&before); loc=*s; while(loc->info!=before && loc!=null) loc=loc->next; if(loc==null) printf("\n after element not present"); if((loc->prev)->prev==null) temp=loc->prev; loc->prev=null; *s=loc; free(temp) ; temp=loc->prev; loc->prev=temp->prev; (temp->prev)->next=loc; free(temp);

64 void DeleteEntireList(Node **s) Node *temp; while(*s!=null) temp=*s; *s=(*s)->next; free(temp); void Display(Node **s) Node *temp; printf("\n\n") if(*s==null) printf("list is empty"); temp=*s; while(temp!=null);

65 printf("%d ",temp->info); temp=temp->next; void Menu() printf("\npress 1 - for Insert at start"); printf("\npress 2 - for Insert at End"); printf("\npress 3 - for Insert after"); printf("\npress 4 - for Insert Before"); printf("\npress 5 - for Delete from start"); printf("\npress 6 - for Delete from End"); printf("\npress 7 - for Delete after"); printf("\npress 8 - for Delete before"); printf("\npress 9 - Delete entire list"); printf("\npress 10 - Display"); printf("\npress 0 - For Exit"); void main()

66 Node *s; int choice; CreateEmptyList(&s); clrscr(); while(1) Menu(); printf("\n enter your choice : "); scanf("%d",&chocie); switch(choice) case 1:InsertatBegininning(&s); break; case 2:InsertatEnd(&s); break; case 3:InsertAfter(&s); break; case 4:InsertBefore(&s); break;

67 case 5:DeletefromStart(&s); break; case 6:DeletefromEnd(&s); break; case 7:DeleteAfter(&s); break; case 8:DeleteBefore(&s); break; case 9:DeleteEntireList(&s); break; case 10:Display(&s); break; case 0:exit(0); default:printf("\n enter only available choices");

68 13. LinearSearch. #include <stdio.h> int main() int array[100], search, c, n; printf("enter the number of elements in array\n"); scanf("%d",&n); printf("enter %d integer(s)\n", n); for (c = 0; c < n; c++) scanf("%d", &array[c]); printf("enter the number to search\n"); scanf("%d", &search); for (c = 0; c < n; c++) if (array[c] == search) /* if required element found */ printf("%d is present at location %d.\n", search, c+1); break;

69 if (c == n) printf("%d is not present in array.\n", search); return 0;

70 14. Binary Search. #include <stdio.h> int main() int c, first, last, middle, n, search, array[100]; printf("enter number of elements\n"); scanf("%d",&n); printf("enter %d integers\n", n); for (c = 0; c < n; c++) scanf("%d",&array[c]); printf("enter value to find\n"); scanf("%d", &search); first = 0; last = n - 1; middle = (first+last)/2; while (first <= last) if (array[middle] < search)

71 first = middle + 1; if (array[middle] == search) printf("%d found at location %d.\n", search, middle+1); break; last = middle - 1; middle = (first + last)/2; if (first > last) printf("not found! %d is not present in the list.\n", search); return 0;

72 15. Selection Sort. #include <stdio.h> int main() int data[100],i,n,steps,temp; printf("enter the number of elements to be sorted: "); scanf("%d",&n); for(i=0;i<n;++i) printf("%d. Enter element: ",i+1); scanf("%d",&data[i]); for(steps=0;steps<n;++steps) for(i=steps+1;i<n;++i) if(data[steps]>data[i]) /* To sort in descending order, change > to <. */ temp=data[steps]; data[steps]=data[i]; data[i]=temp; printf("in ascending order: ");

73 for(i=0;i<n;++i) printf("%d ",data[i]); return 0; Output Enter the number of elements to be sorted: 5 1. Enter element: Enter element: 1 3. Enter element: Enter element: 2 5. Enter element: 0 In ascending order:

74 16. Bubble Sort. #include <stdio.h> int main() int data[100],i,n,step,temp; printf("enter the number of elements to be sorted: "); scanf("%d",&n); for(i=0;i<n;++i) printf("%d. Enter element: ",i+1); scanf("%d",&data[i]); for(step=0;step<n-1;++step) for(i=0;i<n-step-1;++i) if(data[i]>data[i+1]) /* To sort in descending order, change > to < in this line. */ temp=data[i]; data[i]=data[i+1]; data[i+1]=temp; printf("in ascending order: ");

75 for(i=0;i<n;++i) printf("%d ",data[i]); return 0; Enter the number of elements to be sorted: 6 1. Enter element: Enter element: 3 3. Enter element: 0 4. Enter element: Enter element: 1 6. Enter element: -9 In ascending order: Insertion sort.

76 #include<stdio.h> int main() int data[100],n,temp,i,j; printf("enter number of terms(should be less than 100): "); scanf("%d",&n); printf("enter elements: "); for(i=0;i<n;i++) scanf("%d",&data[i]); for(i=1;i<n;i++) temp = data[i]; j=i-1; while(temp<data[j] && j>=0) /*To sort elements in descending order, change temp<data[j] to temp>data[j] in above line.*/ data[j+1] = data[j]; --j; data[j+1]=temp;

77 printf("in ascending order: "); for(i=0; i<n; i++) printf("%d\t",data[i]); return 0; Enter number of terms(should be less than 100): 5 Enter elements: In ascending order: Merge sort.

78 #include <stdio.h> void mergesort(int [], int, int, int); void partition(int [],int, int); int main() int list[50]; int i, size; printf("enter total number of elements:"); scanf("%d", &size); printf("enter the elements:\n"); for(i = 0; i < size; i++) scanf("%d", &list[i]); partition(list, 0, size - 1); printf("after merge sort:\n"); for(i = 0;i < size; i++) printf("%d ",list[i]);

79 return 0; void partition(int list[],int low,int high) int mid; if(low < high) mid = (low + high) / 2; partition(list, low, mid); partition(list, mid + 1, high); mergesort(list, low, mid, high); void mergesort(int list[],int low,int mid,int high) int i, mi, k, lo, temp[50]; lo = low; i = low; mi = mid + 1;

80 while ((lo <= mid) && (mi <= high)) if (list[lo] <= list[mi]) temp[i] = list[lo]; lo++; temp[i] = list[mi]; mi++; i++; if (lo > mid) for (k = mi; k <= high; k++) temp[i] = list[k]; i++;

81 for (k = lo; k <= mid; k++) temp[i] = list[k]; i++; for (k = low; k <= high; k++) list[k] = temp[k]; 19. Quick sort.

82 #include <stdio.h> void quicksort (int [], int, int); int main() int list[50]; int size, i; printf("enter the number of elements: "); scanf("%d", &size); printf("enter the elements to be sorted:\n"); for (i = 0; i < size; i++) scanf("%d", &list[i]); quicksort(list, 0, size - 1); printf("after applying quick sort\n"); for (i = 0; i < size; i++) printf("%d ", list[i]); printf("\n");

83 return 0; void quicksort(int list[], int low, int high) int pivot, i, j, temp; if (low < high) pivot = low; i = low; j = high; while (i < j) while (list[i] <= list[pivot] && i <= high) i++; while (list[j] > list[pivot] && j >= low) j--; if (i < j) temp = list[i]; list[i] = list[j];

84 list[j] = temp; temp = list[j]; list[j] = list[pivot]; list[pivot] = temp; quicksort(list, low, j - 1); quicksort(list, j + 1, high); 20. Radix (bucket) sort method.

85 #include <stdio.h> int min = 0, count = 0, array[100] = 0, array1[100] = 0; void main() int k, i, j, temp, t, n; printf("enter size of array :"); scanf("%d", &count); printf("enter elements into array :"); for (i = 0; i < count; i++) scanf("%d", &array[i]); array1[i] = array[i]; for (k = 0; k < 3; k++) for (i = 0; i < count; i++) min = array[i] % 10; /* To find minimum LSD */ t = i; for (j = i + 1; j < count;j++) if (min > (array[j] % 10))

86 min = array[j] % 10; t = j; temp = array1[t]; array1[t] = array1[i]; array1[i] = temp; temp = array[t]; array[t] = array[i]; array[i] = temp; for (j = 0; j < count; j++) /*to find MSD */ array[j] = array[j] / 10; printf("sorted Array (Using LSD Radix sort) : "); for (i = 0; i < count; i++) printf("%d ", array1[i]); 21. Binary Search Tree operations.

87 #include <stdio.h> #include <conio.h> typedef struct node int info; struct node *left; struct node *right; BST; void CreateEmptyTree(BST **tree) *tree=null; void PreOrderTraversal(BST *tree) if(tree==null) printf("%d",tree->info); PreOrderTraversal(tree->left); PreOrderTraversal(tree->right);

88 void InOrderTraversal(BST *tree) if(tree==null) InOrderTraversal(tree->left); printf("%d",tree->info); InOrderTraversal(tree->right); void PostOrderTraversal(BST *tree) if(tree==null) PostOrderTraversal(tree->left); PostOrderTraversal(tree->right); printf("%d",tree->info); int DetermineHeight(BST *tree)

89 int leftheight,rightheight; if(tree==null) return(0); leftheight=determineheight(tree->left); rightheight=leftheight=determineheight(tree->right); if(leftheight>rightheight) return(++leftheight); return(++rightheight); int NodesCount(BST *tree) if(tree==null) return(0); return(nodescount(tree->left) + NodesCount(tree-right) + 1); int InternalNodes(BST * tree)

90 if((tree==null) ((tree->left==null) && (tree->right==null))) return(0); return(internalnodes(tree->left)+internalnodes(tree->right)+1) int ExternalNodes(BST * tree) if((tree==null) ((tree->left==null) && (tree->right==null))) return(0); if((tree->left==null) && (tree->right==null)) return(1); return(externalnodes(tree->left)+externalnodes(tree->right)) void RemoveTree(BST **tree) if(*tree!=null) RemoveTree(&(*tree)->left); RemoveTree(&(*tree)->right); free(*tree);

91 void Insert(BST **tree) int item; BST *temp,*current,*parent; printf("\n enter the element : "); scanf("%d",&item); temp=(bst*)malloc(sizeof(bst)); temp->info=item; temp->left=temp->right=null; if(tree==null) *tree=temp; parent=null; current=*tree; while(current!=null) parent=current; if(item<current->info) current=current->left; current=current->right;

92 if(item<parent->info) parent->left=temp; parent->right=temp; BST *LargetNode(BST *tree) if((tre==null) (tree->right==null)) return(tree) return(largestnode(tree->right)); BST *SmallestNode(BST *tree) if((tre==null) (tree->left==null)) return(tree) return(smallestnode(tree->left)); void DeleteNode(BST **tree,int element)

93 int item; BST *temp; if(*tree==null) printf("\n tree is empty"); if(element<(*tree)->info) Delete(&((*tree)->left)); if(element>(*tree)->info) Delete(&((*tree)->right); if((*tree)->info) && (*tree)->right) temp=largestnode((*tree)->left); (*tree->info)=temp->info; Delete(&((*tree)->left),temp->info); temp=*tree; if(((*tree)->left==null)&&(*tree)->right==null) *tree=null; if((*tree)->left!=null) *tree=(*tree)->left; *tree=(*tree)->right; free(temp);

94 Delete(&((*tree)->left)); void Menu() printf("\n press 1 for Insert"); printf("\n press 2 for Delete"); printf("\n press 3 for In-Order Traversal"); printf("\n press 4 for Pre-Order Traversal"); printf("\n press 5 for Post-Order Traversal"); printf("\n press 6 for Total Nodes"); printf("\n press 7 for Total External nodes"); printf("\n press 8 for Total Internal Nodes"); printf("\n press 9 for Height"); printf("\n press 10 for Smallest Node"); printf("\n press 11 for Largest"); printf("\n press 0 for Exit"); void main() int choice,element; BST *tree;

95 CreateEmptyTree(&tree); while(1) Menu(); printf("\n enter your choice : "); scanf("%d",&choice); switch(choice) case 1:Insert(&tree); break; case 2:printf("\n enter the element to delete : "); scanf("%d",&element); DeleteNode(&tree,element); break; case 3:void InOrderTraversal(tree); break; case 4:void PreOrderTraversal(tree); break; case 5:void PostOrderTraversal(tree); break; case 6:NodesCount(tree); break;

96 case 7:ExternalNodes(tree); break; case 8:InternalNodes(tree); break; case 9: DetermineHeight(tree); break; case 10:SmallestNode(tree); break; case 11:LargetNode(tree); break; case 0:exit(); default: printf("\n please enter available choices only"); 22. Heap sort & AVL tree implementations.

97 #include <stdio.h> void main() int heap[10], no, i, j, c, root, temp; printf("\n Enter no of elements :"); scanf("%d", &no); printf("\n Enter the nos : "); for (i = 0; i < no; i++) scanf("%d", &heap[i]); for (i = 1; i < no; i++) c = i; do root = (c - 1) / 2; if (heap[root] < heap[c]) /* to create MAX heap array */ temp = heap[root]; heap[root] = heap[c]; heap[c] = temp; c = root;

98 while (c!= 0); printf("heap array : "); for (i = 0; i < no; i++) printf("%d\t ", heap[i]); for (j = no - 1; j >= 0; j--) temp = heap[0]; heap[0] = heap[j /* swap max element with rightmost leaf element */ heap[j] = temp; root = 0; do c = 2 * root + 1; /* left node of root element */ if ((heap[c] < heap[c + 1]) && c < j-1) c++; if (heap[root]<heap[c] && c<j) /* again rearrange to max heap array */ temp = heap[root]; heap[root] = heap[c]; heap[c] = temp; root = c;

99 while (c < j); printf("\n The sorted array is : "); for (i = 0; i < no; i++) printf("\t %d", heap[i]); printf("\n Complexity : \n Best case = Avg case = Worst case = O(n logn) \n"); 23. Write a program in C for DFS

100 #include <stdio.h> #include <stdlib.h> struct node int vertex; struct node* next; ; struct node* createnode(int v); struct Graph int numvertices; int* visited; struct node** adjlists; // we need int** to store a two dimensional array. Similary, we need struct node** to store an array of Linked lists ; struct Graph* creategraph(int); void addedge(struct Graph*, int, int); void printgraph(struct Graph*); void DFS(struct Graph*, int);

101 int main() struct Graph* graph = creategraph(4); addedge(graph, 0, 1); addedge(graph, 0, 2); addedge(graph, 1, 2); addedge(graph, 2, 3); printgraph(graph); DFS(graph, 2); return 0; void DFS(struct Graph* graph, int vertex) struct node* adjlist = graph->adjlists[vertex]; struct node* temp = adjlist; graph->visited[vertex] = 1; printf("visited %d \n", vertex); while(temp!=null)

102 int connectedvertex = temp->vertex; if(graph->visited[connectedvertex] == 0) DFS(graph, connectedvertex); temp = temp->next; struct node* createnode(int v) struct node* newnode = malloc(sizeof(struct node)); newnode->vertex = v; newnode->next = NULL; return newnode; struct Graph* creategraph(int vertices) struct Graph* graph = malloc(sizeof(struct Graph)); graph->numvertices = vertices; graph->adjlists = malloc(vertices * sizeof(struct node*));

103 graph->visited = malloc(vertices * sizeof(int)); int i; for (i = 0; i < vertices; i++) graph->adjlists[i] = NULL; graph->visited[i] = 0; return graph; void addedge(struct Graph* graph, int src, int dest) // Add edge from src to dest struct node* newnode = createnode(dest); newnode->next = graph->adjlists[src]; graph->adjlists[src] = newnode; // Add edge from dest to src newnode = createnode(src); newnode->next = graph->adjlists[dest]; graph->adjlists[dest] = newnode;

104 void printgraph(struct Graph* graph) int v; for (v = 0; v < graph->numvertices; v++) struct node* temp = graph->adjlists[v]; printf("\n Adjacency list of vertex %d\n ", v); while (temp) printf("%d -> ", temp->vertex); temp = temp->next; printf("\n");

Sorting & Searching. Hours: 10. Marks: 16

Sorting & Searching. Hours: 10. Marks: 16 Sorting & Searching CONTENTS 2.1 Sorting Techniques 1. Introduction 2. Selection sort 3. Insertion sort 4. Bubble sort 5. Merge sort 6. Radix sort ( Only algorithm ) 7. Shell sort ( Only algorithm ) 8.

More information

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified)

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified) WINTER 18 EXAMINATION Subject Name: Data Structure using C Model wer Subject Code: 22317 Important Instructions to examiners: 1) The answers should be examined by key words and not as word-to-word as given

More information

UNIT 3: QUEUE Programs demonstrated in class. Tojo Mathew Asst. Professor CSE Dept., NIE Mysuru.

UNIT 3: QUEUE Programs demonstrated in class. Tojo Mathew Asst. Professor CSE Dept., NIE Mysuru. UNIT 3: QUEUE Programs demonstrated in class. Tojo Mathew Asst. Professor CSE Dept., NIE Mysuru. Table of Contents 1. Simple Queue Implementation with arrays...3 2. Circular queue with global container

More information

UNIT III ARRAYS AND STRINGS

UNIT III ARRAYS AND STRINGS UNIT III ARRAYS AND STRINGS Arrays Initialization Declaration One dimensional and Two dimensional arrays. String- String operations String Arrays. Simple programs- sorting- searching matrix operations.

More information

Sree Vidyanikethan Engineering College Sree Sainath Nagar, A. Rangampet

Sree Vidyanikethan Engineering College Sree Sainath Nagar, A. Rangampet Sree Vidyanikethan Engineering College Sree Sainath Nagar, A. Rangampet 517 102 Department of Computer Science and Engineering I B. Tech C Programming Language Lab Title: Stack SVEC/IT/EXPT-CP-21 PROBLEM

More information

Linked List in Data Structure. By Prof. B J Gorad, BECSE, M.Tech CST, PHD(CSE)* Assistant Professor, CSE, SITCOE, Ichalkaranji,Kolhapur, Maharashtra

Linked List in Data Structure. By Prof. B J Gorad, BECSE, M.Tech CST, PHD(CSE)* Assistant Professor, CSE, SITCOE, Ichalkaranji,Kolhapur, Maharashtra Linked List in Data Structure By Prof. B J Gorad, BECSE, M.Tech CST, PHD(CSE)* Assistant Professor, CSE, SITCOE, Ichalkaranji,Kolhapur, Maharashtra Linked List Like arrays, Linked List is a linear data

More information

Frequently asked Data Structures Interview Questions

Frequently asked Data Structures Interview Questions Frequently asked Data Structures Interview Questions Queues Data Structure Interview Questions How is queue different from a stack? The difference between stacks and queues is in removing. In a stack we

More information

Basically queue is nothing but an array or a vector with a maximum capacity of size. Front=1 Front=1 REAR=2. Front=1 REAR=3 Front=1 REAR=4 Q is Full

Basically queue is nothing but an array or a vector with a maximum capacity of size. Front=1 Front=1 REAR=2. Front=1 REAR=3 Front=1 REAR=4 Q is Full Queue A Queue is defined as linear list in which insertion is taking place at one end and deletion is taking place at the other end. The end where insertion is taking place is called as rear end. The end

More information

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified)

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified) WINTER 18 EXAMINATION Subject Name: Data Structure Model wer Subject Code: 17330 Important Instructions to examiners: 1) The answers should be examined by key words and not as word-to-word as given in

More information

AIM:- To write a C program to create a singly linked list implementation.

AIM:- To write a C program to create a singly linked list implementation. SINGLY LINKED LIST AIM:- To write a C program to create a singly linked list implementation. ALGORITHM:- 1. Start the program. 2. Get the choice from the user. 3. If the choice is to add records, get the

More information

Solution for Data Structure

Solution for Data Structure Solution for Data Structure May 2016 INDEX Q1 a 2-3 b 4 c. 4-6 d 7 Q2- a 8-12 b 12-14 Q3 a 15-18 b 18-22 Q4- a 22-35 B..N.A Q5 a 36-38 b N.A Q6- a 39-42 b 43 1 www.brainheaters.in Q1) Ans: (a) Define ADT

More information

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION Important Instructions to examiners: 1) The answers should be examined by key words and not as word-to-word as given in themodel answer scheme. 2) The model answer and the answer written by candidate may

More information

POLYNOMIAL ADDITION. AIM:- To write a C program to represent a polynomial as a linked list and write functions for polynomial addition.

POLYNOMIAL ADDITION. AIM:- To write a C program to represent a polynomial as a linked list and write functions for polynomial addition. POLYNOMIAL ADDITION AIM:- To write a C program to represent a polynomial as a linked list and write functions for polynomial addition. ALGORITHM:- 1. Start the program 2. Get the coefficients and powers

More information

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified) WINTER 16 EXAMINATION Model Answer Subject Code:

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified) WINTER 16 EXAMINATION Model Answer Subject Code: Important Instructions to examiners: 1) The answers should be examined by key words and not as word-to-word as given in the model answer scheme. 2) The model answer and the answer written by candidate

More information

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified)

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified) WINTER 17 EXAMINATION Subject Name: Data Structure Using C Model Answer Subject Code: 17330 Important Instructions to examiners: 1) The answers should be examined by key words and not as word-to-word as

More information

Data Structure & Algorithms Laboratory Manual (CS 392)

Data Structure & Algorithms Laboratory Manual (CS 392) Institute of Engineering & Management Department of Computer Science & Engineering Data Structure Laboratory for 2 nd year 3 rd semester Code: CS 392 Data Structure & Algorithms Laboratory Manual (CS 392)

More information

UNIT-2 Stack & Queue

UNIT-2 Stack & Queue UNIT-2 Stack & Queue 59 13. Stack A stack is an Abstract Data Type (ADT), commonly used in most programming languages. It is named stack as it behaves like a real-world stack, for example a deck of cards

More information

Unit 1 - Arrays. 1 What is an array? Explain with Example. What are the advantages of using an array?

Unit 1 - Arrays. 1 What is an array? Explain with Example. What are the advantages of using an array? 1 What is an array? Explain with Example. What are the advantages of using an array? An array is a fixed-size sequenced collection of elements of the same data type. An array is derived data type. The

More information

DS Lab Manual -17CS33

DS Lab Manual -17CS33 Chethan Raj C Assistant Professor Dept. of CSE 6. Design, Develop and Implement a menu driven Program in C for the following operations on Circular QUEUE of Characters (Array Implementation of Queue with

More information

PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of MCA

PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of MCA USN 1 P E PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of MCA INTERNAL ASSESSMENT TEST 2 (Scheme and Solution) Data Structures Using C (16MCA11) 1) A.

More information

Lecture Data Structure Stack

Lecture Data Structure Stack Lecture Data Structure Stack 1.A stack :-is an abstract Data Type (ADT), commonly used in most programming languages. It is named stack as it behaves like a real-world stack, for example a deck of cards

More information

PROGRAMMING IN C LAB MANUAL FOR DIPLOMA IN ECE/EEE

PROGRAMMING IN C LAB MANUAL FOR DIPLOMA IN ECE/EEE PROGRAMMING IN C LAB MANUAL FOR DIPLOMA IN ECE/EEE 1. Write a C program to perform addition, subtraction, multiplication and division of two numbers. # include # include int a, b,sum,

More information

Module III. Linear Data Structures and their Linked Storage Representation

Module III. Linear Data Structures and their Linked Storage Representation Module III Linear Data Structures and their Linked Storage Representation 3.1 Linked List Linked list is the collection of inter connected nodes with a head node representing the first node and a tail

More information

Guide for The C Programming Language Chapter 5

Guide for The C Programming Language Chapter 5 1. Differentiate between primitive data type and non-primitive data type. Primitive data types are the basic data types. These data types are used to represent single values. For example: Character, Integer,

More information

Prepared By:- Dinesh Sharma Asstt. Professor, CSE & IT Deptt. ITM Gurgaon

Prepared By:- Dinesh Sharma Asstt. Professor, CSE & IT Deptt. ITM Gurgaon Data Structures &Al Algorithms Prepared By:- Dinesh Sharma Asstt. Professor, CSE & IT Deptt. ITM Gurgaon What is Data Structure Data Structure is a logical relationship existing between individual elements

More information

CS11001/CS11002 Programming and Data Structures (PDS) (Theory: 3-0-0)

CS11001/CS11002 Programming and Data Structures (PDS) (Theory: 3-0-0) CS11001/CS11002 Programming and Data Structures (PDS) (Theory: 3-0-0) Class Teacher: Pralay Mitra Department of Computer Science and Engineering Indian Institute of Technology Kharagpur Conceptual Idea

More information

MODULE V: POINTERS & PREPROCESSORS

MODULE V: POINTERS & PREPROCESSORS MODULE V: POINTERS & PREPROCESSORS INTRODUCTION As you know, every variable is a memory-location and every memory-location has its address defined which can be accessed using ampersand(&) operator, which

More information

DATA STRUCTURE. o DYNAMIC MEMORY. ALLOCATION o SELF-REFERENTIAL STRUCTURE o TYPEDEF LINK LIST STACK QUEUE TREE

DATA STRUCTURE. o DYNAMIC MEMORY. ALLOCATION o SELF-REFERENTIAL STRUCTURE o TYPEDEF LINK LIST STACK QUEUE TREE DATA STRUCTURE TOPICS PAGE o DYNAMIC MEMORY 2-5 ALLOCATION o SELF-REFERENTIAL STRUCTURE o TYPEDEF LINK LIST 5-16 STACK 17-28 o APPLICATION OF STACK 28-38 QUEUE 39-43 TREE o BINARY SEARCH TREE o HEAP GRAPH

More information

MAHARASHTRASTATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified)

MAHARASHTRASTATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified) Subject Code: 17330 Model Answer Page 1/ 22 Important Instructions to examiners: 1) The answers should be examined by key words and not as word-to-word as given in the model answer scheme. 2) The model

More information

What is recursion. WAP to find sum of n natural numbers using recursion (5)

What is recursion. WAP to find sum of n natural numbers using recursion (5) DEC 2014 Q1 a What is recursion. WAP to find sum of n natural numbers using recursion (5) Recursion is a phenomenon in which a function calls itself. A function which calls itself is called recursive function.

More information

Darshan Institute of Engineering & Technology for Diploma Studies Unit 3

Darshan Institute of Engineering & Technology for Diploma Studies Unit 3 Linear and Non-Linear Data Structures Linear data structure: Linear data structures are those data structure in which data items are arranged in a linear sequence by physically or logically or both the

More information

S.E. Sem. III [CMPN] Data Structures. Primitive Linear Non Linear

S.E. Sem. III [CMPN] Data Structures. Primitive Linear Non Linear S.E. Sem. III [CMPN] Data Structures Time : 3 Hrs.] Prelim Paper Solution [Marks : 80 Q.1(a) Explain different types of data structures with examples. [5] Ans.: Types of Data Structure : Data Structures

More information

Queue: Queue Representation: Basic Operations:

Queue: Queue Representation: Basic Operations: Queue: Queue is an abstract data structure, somewhat similar to Stacks. Unlike stacks, a queue is open at both its ends. One end is always used to insert data (enqueue) and the other is used to remove

More information

Answers. 1. (A) Attempt any five : 20 Marks

Answers. 1. (A) Attempt any five : 20 Marks Important Instructions to examiners: 1) The answers should be examined by key words and not as word-to-word as given in the model answer scheme. 2) The model answer and the answer written by candidate

More information

DEV BHOOMI INSTITUE OF TECHNOLOGY DEHRADUN Department Of Computer Application. Design and Analysis of Algorithms Lab MCA-302

DEV BHOOMI INSTITUE OF TECHNOLOGY DEHRADUN Department Of Computer Application. Design and Analysis of Algorithms Lab MCA-302 DEV BHOOMI INSTITUE OF TECHNOLOGY DEHRADUN Department Of Computer Application Design and Analysis of Algorithms Lab MCA-302 1 INDEX S.No. PRACTICAL NAME DATE PAGE NO. SIGNATURE 1. Write a Program to Implement

More information

A. Year / Module Semester Subject Topic 2016 / V 2 PCD Pointers, Preprocessors, DS

A. Year / Module Semester Subject Topic 2016 / V 2 PCD Pointers, Preprocessors, DS Syllabus: Pointers and Preprocessors: Pointers and address, pointers and functions (call by reference) arguments, pointers and arrays, address arithmetic, character pointer and functions, pointers to pointer,initialization

More information

Application of Stack (Backtracking)

Application of Stack (Backtracking) Application of Stack (Backtracking) Think of a labyrinth or maze How do you find a way from an entrance to an exit? Once you reach a dead end, you must backtrack. But backtrack to where? to the previous

More information

ESc101: (Linear, Circular, Doubly) Linked Lists, Stacks, Queues, Trees. Introduction to Linked Lists

ESc101: (Linear, Circular, Doubly) Linked Lists, Stacks, Queues, Trees. Introduction to Linked Lists ESc101: (Linear, Circular, Doubly) Linked Lists, Stacks, Queues, Trees Instructor: Krithika Venkataramani Semester 2, 2011-2012 1 Introduction to Linked Lists Each bead connected to the next through a

More information

Government Girls Polytechnic, Bilaspur

Government Girls Polytechnic, Bilaspur Government Girls Polytechnic, Bilaspur Name of the Lab: Programming Lab Practical: Data Structure Lab Class: 4 th Semester (Computer Science & Engineering) Teachers Assessment: 30 End Semester Examination:70

More information

CS6202 - PROGRAMMING & DATA STRUCTURES I Unit IV Part - A 1. Define Stack. A stack is an ordered list in which all insertions and deletions are made at one end, called the top. It is an abstract data type

More information

a) State the need of data structure. Write the operations performed using data structures.

a) State the need of data structure. Write the operations performed using data structures. Important Instructions to examiners: 1) The answers should be examined by key words and not as word-to-word as given in the model answer scheme. 2) The model answer and the answer written by candidate

More information

/*Tree Traversals*/ #include<stdio.h> #include<conio.h> typedef struct bin { int data; struct bin *left,*right; }node;

/*Tree Traversals*/ #include<stdio.h> #include<conio.h> typedef struct bin { int data; struct bin *left,*right; }node; /*Tree Traversals*/ #include #include typedef struct bin int data; struct bin *left,*right; node; void insert(node *,node *); void inorder(node *); void preorder(node *); void postorder(node

More information

Arrays a kind of data structure that can store a fixedsize sequential collection of elements of the same type. An array is used to store a collection

Arrays a kind of data structure that can store a fixedsize sequential collection of elements of the same type. An array is used to store a collection Morteza Noferesti Arrays a kind of data structure that can store a fixedsize sequential collection of elements of the same type. An array is used to store a collection of data, but it is often more useful

More information

DATA STRUCTURE : A MCQ QUESTION SET Code : RBMCQ0305

DATA STRUCTURE : A MCQ QUESTION SET Code : RBMCQ0305 Q.1 If h is any hashing function and is used to hash n keys in to a table of size m, where n

More information

S.Y. Diploma : Sem. III [CO/CM/IF/CD/CW] Data Structure using C

S.Y. Diploma : Sem. III [CO/CM/IF/CD/CW] Data Structure using C S.Y. Diploma : Sem. III [CO/CM/IF/CD/CW] Data Structure using C Time: 3 Hrs.] Prelim Question Paper Solution [Marks : 100 Q.1 (a) Attempt any SIX of the following : [12] Q.1 (a) (i) Define time complexity

More information

Model Solution for QP CODE : ( 3 Hours )

Model Solution for QP CODE : ( 3 Hours ) Model Solution for QP CODE : 24788 ( 3 Hours ) All answers are for reference only. Any alternate answer that solves the problem should be considered eqully valid. 1. (a) Define data structure? Give its

More information

Class / Sem: I CSE / II Semester Subject Code: CS 6202 Subject: Programming and Data Structures I Prepared by T. Vithya Unit IV - LINEAR DATA STRUCTURES STACKS AND QUEUES Stack ADT Evaluating arithmetic

More information

S.E. Sem. III [INFT] Data Structures & Analysis. Primitive Linear Non Linear

S.E. Sem. III [INFT] Data Structures & Analysis. Primitive Linear Non Linear S.E. Sem. III [INFT] Data Structures & Analysis Time : 3 Hrs.] Prelim Paper Solution [Marks : 80 Q.1(a) Explain different types of data structures with examples. [5] Ans.: Types of Data Structure : Data

More information

UNIT VI. STACKS AND QUEUES

UNIT VI. STACKS AND QUEUES UNIT VI. STACKS AND QUEUES Syllabus: /*-------------------------------------------------------------------------*/ Stack: Definition: "Stack is an ordered collection of data elements having similar data

More information

UNIT 2: STACK & RECURSION Programs demonstrated in class. Tojo Mathew Asst. Professor CSE Dept., NIE Mysuru.

UNIT 2: STACK & RECURSION Programs demonstrated in class. Tojo Mathew Asst. Professor CSE Dept., NIE Mysuru. UNIT 2: STACK & RECURSION Programs demonstrated in class. Tojo Mathew Asst. Professor CSE Dept., NIE Mysuru. Table of Contents 1. C Program to Check for balanced parenthesis by using Stacks...3 2. Program

More information

DEV BHOOMI INSTITUTE OF TECHNOLOGY

DEV BHOOMI INSTITUTE OF TECHNOLOGY DEV BHOOMI INSTITUTE OF TECHNOLOGY Department of Computer Science and Engineering Year: 2nd Semester: 3rd Data Structures- PCS-303 LAB MANUAL Prepared By: HOD(CSE) DEV BHOOMI

More information

S.Y. B.Sc. (IT) : Sem. III. Data Structures

S.Y. B.Sc. (IT) : Sem. III. Data Structures S.Y. B.Sc. (IT) : Sem. III Data Structures Time : ½ Hrs.] Prelim Question Paper Solution [Marks : 7 Q. Attempt the following (any THREE) [] Q.(a) What is algorithm and explain by on Notation? [] (A) The

More information

DATA STRUCTURES USING C

DATA STRUCTURES USING C DATA STRUCTURES USING C DATA STRUCTURES USING C LECTURE NOTES Prepared by Dr. Subasish Mohapatra Department of Computer Science and Application College of Engineering and Technology, Bhubaneswar Biju Patnaik

More information

DATA STRUCTURES LAB MANUAL

DATA STRUCTURES LAB MANUAL DATA STRUCTURES LAB MANUAL Year : 2016-2017 Course Code : ACS102 Regulations : R16 Semester : I B.Tech II Semester Branch : CSE / IT Prepared by Ms. N. JAYANTHI ASSOCIATE PROFESSOR INSTITUTE OF AERONAUTICAL

More information

'C' Programming Language

'C' Programming Language F.Y. Diploma : Sem. II [DE/EJ/ET/EN/EX] 'C' Programming Language Time: 3 Hrs.] Prelim Question Paper Solution [Marks : 70 Q.1 Attempt any FIVE of the following : [10] Q.1(a) Define pointer. Write syntax

More information

C programming Lecture 7. School of Mathematics Trinity College Dublin. Marina Krstic Marinkovic Marina Krstic Marinkovic 1

C programming Lecture 7. School of Mathematics Trinity College Dublin. Marina Krstic Marinkovic Marina Krstic Marinkovic 1 C programming 5613 Lecture 7 Marina Krstic Marinkovic mmarina@maths.tcd.ie School of Mathematics Trinity College Dublin Marina Krstic Marinkovic 1 / 10 5613 - C programming Timing the execution of your

More information

Programming in C Lab

Programming in C Lab Programming in C Lab 1a. Write a program to find biggest number among given 3 numbers. ALGORITHM Step 1 : Start Start 2 : Input a, b, c Start 3 : if a > b goto step 4, otherwise goto step 5 Start 4 : if

More information

MC9217 / Programming and Data Structures Lab MC9217 PROGRAMMING AND DATA STRUCTURES LAB L T P C

MC9217 / Programming and Data Structures Lab MC9217 PROGRAMMING AND DATA STRUCTURES LAB L T P C MC9217 PROGRAMMING AND DATA STRUCTURES LAB L T P C 0 0 3 2 1.Create a Stack and do the following operations using arrays and linked lists (i)push (ii) Pop (iii) Peep 2.Create a Queue and do the following

More information

BITS PILANI, DUBAI CAMPUS DUBAI INTERNATIONAL ACADEMIC CITY, DUBAI FIRST SEMESTER

BITS PILANI, DUBAI CAMPUS DUBAI INTERNATIONAL ACADEMIC CITY, DUBAI FIRST SEMESTER BITS PILANI, DUBAI CAMPUS DUBAI INTERNATIONAL ACADEMIC CITY, DUBAI FIRST SEMESTER 2017-2018 COURSE : COMPUTER PROGRAMMING (CS F111) COMPONENT : Tutorial#4 (SOLUTION) DATE : 09-NOV-2017 Answer 1(a). #include

More information

This document can be downloaded from with most recent updates. 1 Data Structures using C: Module 4 (16MCA11) LINKED LISTS

This document can be downloaded from   with most recent updates. 1 Data Structures using C: Module 4 (16MCA11) LINKED LISTS 1 Data Structures using C: Module 4 (16MCA11) LINKED LISTS 4.1 MEMORY MANAGEMENT 4.1.1 Basics about Memory When a C program is compiled, the compiler translates the source code into machine code. Now the

More information

Abstract Data Type: Stack

Abstract Data Type: Stack Abstract Data Type: Stack Stack operations may involve initializing the stack, using it and then de-initializing it. Apart from these basic stuffs, a stack is used for the following two primary operations

More information

PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of Computer Science and Engineering

PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of Computer Science and Engineering USN 1 P E PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of Computer Science and Engineering SOLUTION FOR INTERNAL ASSESSMENT TEST 2 Date : 6/10/2017 Marks:

More information

LECTURE NOTES ON DATA STRUCTURES THROUGH C

LECTURE NOTES ON DATA STRUCTURES THROUGH C LECTURE NOTES ON DATA STRUCTURES THROUGH C Revision 4 July 2013 L. V. NARASIMHA PRASAD Professor and Head E. KRISHNARAO PATRO Associate Professor Department of Computer Science and Engineering Shamshabad,Hyderabad

More information

Linear Data Structure

Linear Data Structure Linear Data Structure Definition A data structure is said to be linear if its elements form a sequence or a linear list. Examples: Array Linked List Stacks Queues Operations on linear Data Structures Traversal

More information

/*Addition of two polynomials*/ #include<stdio.h> #include<malloc.h> #include<conio.h> struct link { int coeff; int pow; struct link *next; }; struct

/*Addition of two polynomials*/ #include<stdio.h> #include<malloc.h> #include<conio.h> struct link { int coeff; int pow; struct link *next; }; struct /*Addition of two polynomials*/ #include #include #include struct link int coeff; int pow; struct link *next; ; struct link *poly1=null,*poly2=null,*poly=null; void create(struct

More information

Vivekananda College of Engineering & Technology. Data Structures and Applications

Vivekananda College of Engineering & Technology. Data Structures and Applications Vivekananda College of Engineering & Technology [Sponsored by Vivekananda Vidyavardhaka Sangha, Puttur ] Affiliated to Visvesvaraya Technological University Approved by AICTE New Delhi & Govt of Karnataka

More information

Assignment 6. Q1. Create a database of students using structures, where in each entry of the database will have the following fields:

Assignment 6. Q1. Create a database of students using structures, where in each entry of the database will have the following fields: Assignment 6 Q1. Create a database of students using structures, where in each entry of the database will have the following fields: 1. a name, which is a string with at most 128 characters 2. their marks

More information

Introduction to Data Structures and Algorithms

Introduction to Data Structures and Algorithms Introduction to Data Structures and Algorithms Data Structure is a way of collecting and organising data in such a way that we can perform operations on these data in an effective way. Data Structures

More information

UNIT 4: Linked List Programs demonstrated in class. Tojo Mathew Asst. Professor CSE Dept., NIE Mysuru.

UNIT 4: Linked List Programs demonstrated in class. Tojo Mathew Asst. Professor CSE Dept., NIE Mysuru. UNIT 4: Linked List Programs demonstrated in class. Tojo Mathew Asst. Professor CSE Dept., NIE Mysuru. 1 Table of Contents 1. Array Implementation of Linked List...3 2. Queue using Array Implementation

More information

Write a C program to add two Complex numbers using functions illustrating-

Write a C program to add two Complex numbers using functions illustrating- Scheme of valuvation Date : 29/8/2017 Marks: 40 Subject & Code : Data Structures and Applications (15CS33) Class : III A&B Name of Faculty : Ms. Saritha Time : 8:30 am to 10 am NOTE: ANSWER All FIVE QUESTIONS

More information

INSTITUTE OF AERONAUTICAL ENGINEERING

INSTITUTE OF AERONAUTICAL ENGINEERING INSTITUTE OF AERONAUTICAL ENGINEERING (Autonomous) Dundigal, Hyderabad - 500 043 COMPUTER SCIENCE AND ENGINEERING TUTORIAL QUESTION BANK Course Name Course Code Class Branch DATA STRUCTURES ACS002 B. Tech

More information

Darshan Institute of Engineering & Technology for Diploma Studies Unit 1

Darshan Institute of Engineering & Technology for Diploma Studies Unit 1 Darshan Institute of Engineering & Technology for Diploma Studies Unit 1 Introduction Computer is an electronic machine which is used for data processing and manipulation. In order to make computer work

More information

Procedural Programming

Procedural Programming Exercise 6 (SS 2016) 04.07.2015 What will I learn in the 6. exercise Math functions Dynamic data structures (linked Lists) Exercise(s) 1 Home exercise 4 (3 points) Write a program which is able to handle

More information

Downloaded from : Algorithm: Implementation QUESTION 1 :

Downloaded from :   Algorithm: Implementation QUESTION 1 : QUESTION 1 : WRITE AN ALGORITHM THAT ACCEPTS A BINARY TREE AS INPUT AND PR INTS ITS HEIGHT TO STANDARD OUTPUT. Algorithm: 1. If tree is empty then return 0 2. Else (a) Get the max depth of left subtree

More information

List of Programs: Programs: 1. Polynomial addition

List of Programs: Programs: 1. Polynomial addition List of Programs: 1. Polynomial addition 2. Common operations on vectors in c 3. Matrix operation: multiplication, transpose 4. Basic Unit conversion 5. Number conversion: Decimal to binary 6. Number conversion:

More information

Programming. Lists, Stacks, Queues

Programming. Lists, Stacks, Queues Programming Lists, Stacks, Queues Summary Linked lists Create and insert elements Iterate over all elements of the list Remove elements Doubly Linked Lists Circular Linked Lists Stacks Operations and implementation

More information

DATA STRUCTURES LAB MANUAL USING C (CS,IT,MCA)

DATA STRUCTURES LAB MANUAL USING C (CS,IT,MCA) DATA STRUCTURES LAB MANUAL USING C (CS,IT,MCA) DATA STRUCTURES LAB LIST OF EXPERIMENTS 1) Write a program to perform the following in one dimensional array, Insertion, Deletion, and Searching (Linear and

More information

BITS PILANI, DUBAI CAMPUS DUBAI INTERNATIONAL ACADEMIC CITY, DUBAI FIRST SEMESTER

BITS PILANI, DUBAI CAMPUS DUBAI INTERNATIONAL ACADEMIC CITY, DUBAI FIRST SEMESTER BITS PILANI, DUBAI CAMPUS DUBAI INTERNATIONAL ACADEMIC CITY, DUBAI FIRST SEMESTER 2017-2018 COURSE : COMPUTER PROGRAMMING (CS F111) COMPONENT : Tutorial# 7 (SOLUTIONS) DATE : 06-DEC-2017 Answer 1 enum

More information

Q 1. Attempt any TEN of the following:

Q 1. Attempt any TEN of the following: Subject Code: 17212 Model Answer Page No: 1 / 26 Important Instructions to examiners: 1) The answers should be examined by key words and not as word-to-word as given in the model answer scheme. 2) The

More information

Computers Programming Course 12. Iulian Năstac

Computers Programming Course 12. Iulian Năstac Computers Programming Course 12 Iulian Năstac Recap from previous course Strings in C The character string is one of the most widely used applications that involves vectors. A string in C is an array of

More information

Data Structure (MCA) Nitasha Jain Assistant Professor Department of IT Biyani Girls College, Jaipur

Data Structure (MCA) Nitasha Jain Assistant Professor Department of IT Biyani Girls College, Jaipur Biyani's Think Tank Concept based notes Data Structure (MCA) Nitasha Jain Assistant Professor Department of IT Biyani Girls College, Jaipur 2 Published by : Think Tanks Biyani Group of Colleges Concept

More information

Revision Statement while return growth rate asymptotic notation complexity Compare algorithms Linear search Binary search Preconditions: sorted,

Revision Statement while return growth rate asymptotic notation complexity Compare algorithms Linear search Binary search Preconditions: sorted, [1] Big-O Analysis AVERAGE(n) 1. sum 0 2. i 0. while i < n 4. number input_number(). sum sum + number 6. i i + 1 7. mean sum / n 8. return mean Revision Statement no. of times executed 1 1 2 1 n+1 4 n

More information

STACKS 3.1 INTRODUCTION 3.2 DEFINITION

STACKS 3.1 INTRODUCTION 3.2 DEFINITION STACKS 3 3.1 INTRODUCTION A stack is a linear data structure. It is very useful in many applications of computer science. It is a list in which all insertions and deletions are made at one end, called

More information

MTH 307/417/515 Final Exam Solutions

MTH 307/417/515 Final Exam Solutions MTH 307/417/515 Final Exam Solutions 1. Write the output for the following programs. Explain the reasoning behind your answer. (a) #include int main() int n; for(n = 7; n!= 0; n--) printf("n =

More information

Single linked list. Program: #include<stdio.h> #include<conio.h> #include<alloc.h> struct node. int info; struct node *next; void main()

Single linked list. Program: #include<stdio.h> #include<conio.h> #include<alloc.h> struct node. int info; struct node *next; void main() Single linked list Program: #include #include #include struct node int info; struct node *next; ; void main() struct node *s,*start,*prev,*new1,*temp,*temp1,*ptemp; int cho,i,j,x,n,p;

More information

PESIT Bangalore South Campus

PESIT Bangalore South Campus TEST - 2 Date : 29-9-2014 Marks : 50 Subject & Code : DS(10CS35) Class : III CSE &ISE Name of faculty : Dr.JSP/Mrs.Vandana/Mrs.Renuka Time : 11.30AM to 1 PM Note: Answer any 5 Questions 1 Write a C program

More information

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING B.E SECOND SEMESTER CS 6202 PROGRAMMING AND DATA STRUCTURES I TWO MARKS UNIT I- 2 MARKS

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING B.E SECOND SEMESTER CS 6202 PROGRAMMING AND DATA STRUCTURES I TWO MARKS UNIT I- 2 MARKS DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING B.E SECOND SEMESTER CS 6202 PROGRAMMING AND DATA STRUCTURES I TWO MARKS UNIT I- 2 MARKS 1. Define global declaration? The variables that are used in more

More information

CSE101-Lec#18. Multidimensional Arrays Application of arrays. Created By: Amanpreet Kaur & Sanjeev Kumar SME (CSE) LPU. LPU CSE101 C Programming

CSE101-Lec#18. Multidimensional Arrays Application of arrays. Created By: Amanpreet Kaur & Sanjeev Kumar SME (CSE) LPU. LPU CSE101 C Programming CSE101-Lec#18 Multidimensional Arrays Application of arrays Created By: Amanpreet Kaur & Sanjeev Kumar SME (CSE) LPU Outline Defining and processing 1D array 2D array Applications of arrays 1-D array A

More information

FORTH SEMESTER DIPLOMA EXAMINATION IN ENGINEERING/ TECHNOLIGY- OCTOBER, 2012 DATA STRUCTURE

FORTH SEMESTER DIPLOMA EXAMINATION IN ENGINEERING/ TECHNOLIGY- OCTOBER, 2012 DATA STRUCTURE TED (10)-3071 Reg. No.. (REVISION-2010) Signature. FORTH SEMESTER DIPLOMA EXAMINATION IN ENGINEERING/ TECHNOLIGY- OCTOBER, 2012 DATA STRUCTURE (Common to CT and IF) [Time: 3 hours (Maximum marks: 100)

More information

MLR Institute of Technology

MLR Institute of Technology MLR Institute of Technology Laxma Reddy Avenue, Dundigal, Quthbullapur (M), Hyderabad 500 043 Phone Nos: 08418 204066 / 204088, Fax : 08418 204088 TUTORIAL QUESTION BANK Course Name : DATA STRUCTURES Course

More information

Linked Lists. .. and other linked structures. Pallab Dasgupta Professor, Dept. of Computer Sc & Engg INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR

Linked Lists. .. and other linked structures. Pallab Dasgupta Professor, Dept. of Computer Sc & Engg INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR 1 Linked Lists.. and other linked structures Pallab Dasgupta Professor, Dept. of Computer Sc & Engg INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR Dynamic memory allocation: review typedef struct { int hitemp;

More information

CS11001/CS11002 Programming and Data Structures (PDS) (Theory: 3-1-0)

CS11001/CS11002 Programming and Data Structures (PDS) (Theory: 3-1-0) CS11001/CS11002 Programming and Data Structures (PDS) (Theory: 3-1-0) The queue ADT A queue is like a "natural" queue of elements. It is an ordered list in which all insertions occur at one end called

More information

End-Term Examination Second Semester [MCA] MAY-JUNE 2006

End-Term Examination Second Semester [MCA] MAY-JUNE 2006 (Please write your Roll No. immediately) Roll No. Paper Code: MCA-102 End-Term Examination Second Semester [MCA] MAY-JUNE 2006 Subject: Data Structure Time: 3 Hours Maximum Marks: 60 Note: Question 1.

More information

DS Assignment II. Full Sized Image

DS Assignment II. Full Sized Image DS Assignment II 1. A) For the Towers of Hanoi problem, show the call tree during the recursive call Towers(3, A, C, B). In the tree, label the root node as Towers (3, A, C, B) while marking all the intermediate

More information

Linked List. April 2, 2007 Programming and Data Structure 1

Linked List. April 2, 2007 Programming and Data Structure 1 Linked List April 2, 2007 Programming and Data Structure 1 Introduction head A linked list is a data structure which can change during execution. Successive elements are connected by pointers. Last element

More information

Lecture 6 Sorting and Searching

Lecture 6 Sorting and Searching Lecture 6 Sorting and Searching Sorting takes an unordered collection and makes it an ordered one. 1 2 3 4 5 6 77 42 35 12 101 5 1 2 3 4 5 6 5 12 35 42 77 101 There are many algorithms for sorting a list

More information

Linked Lists and other Dynamic Data Structures

Linked Lists and other Dynamic Data Structures Linked Lists and other Dynamic Data Structures Arrays Fixed in size Allocated in advance within a contiguous memory block Look-up is fast Resizing and Deleting is hard (reallocate and copy) Dynamic Data

More information

Fundamentals of Programming & Procedural Programming

Fundamentals of Programming & Procedural Programming Universität Duisburg-Essen PRACTICAL TRAINING TO THE LECTURE Fundamentals of Programming & Procedural Programming Session Eight: Math Functions, Linked Lists, and Binary Trees Name: First Name: Tutor:

More information

TPCT s College of Engineering, Osmanabad. Laboratory Manual DATA STRUCTURE USING C. For. Second Year Students. Manual Prepared by. Mr. T.K.

TPCT s College of Engineering, Osmanabad. Laboratory Manual DATA STRUCTURE USING C. For. Second Year Students. Manual Prepared by. Mr. T.K. TPCT s College of Engineering, Osmanabad Laboratory Manual DATA STRUCTURE USING C For Second Year Students Manual Prepared by Mr. T.K.Takbhate Author COE, Osmanabad TPCT s College of Engineering Solapur

More information

only in the space provided. Do the rough work in the space provided for it. The question paper has total 12 pages.

only in the space provided. Do the rough work in the space provided for it. The question paper has total 12 pages. Instructions: Answer all five questions. Total marks = 10 x 2 + 4 x 10 = 60. Time = 2hrs. Write your answer only in the space provided. Do the rough work in the space provided for it. The question paper

More information