DEV BHOOMI INSTITUE OF TECHNOLOGY DEHRADUN Department Of Computer Application. Design and Analysis of Algorithms Lab MCA-302
|
|
- Rosamond Dennis
- 6 years ago
- Views:
Transcription
1 DEV BHOOMI INSTITUE OF TECHNOLOGY DEHRADUN Department Of Computer Application Design and Analysis of Algorithms Lab MCA-302 1
2 INDEX S.No. PRACTICAL NAME DATE PAGE NO. SIGNATURE 1. Write a Program to Implement Insertion Sort in C programming language 2. Write a Program to implement quick sort in C programming language. 3. Write a Program to Implement Merge Sort in C programming language. 4. Write a Program to Implement Heap sort in C programming language. 5. Write a Program to Implement Bubble Sort in C programming language 6. Write a Program to Implement Searching: Sequential and Binary Search. 7. Write a Program to Implement Searching: Sequential and Binary Search. 8. Write a Program to implement Dynamic programming traveling sales person problem). 9. Write a Program to implement Back tracking (nqueens problem). 10. Write a Program to implement Back tracking (Hamiltonian cycles). 2
3 EXPERIMENT NO-1 Objective:Write a Program to Implement Insertion Sort in C programming language Program: #include <stdio.h> #define MAX 7 void insertion_sort(int *); void main() int a[max], i; printf("enter elements to be sorted:"); for (i = 0;i<MAX;i++) scanf("%d", &a[i]); insertion_sort(a); printf("sorted elements:\n"); for (i = 0;i< MAX; i++) printf(" %d", a[i]); /* sorts the input */ void insertion_sort(int * x) int temp, i, j; for (i = 1;i<MAX;i++) temp = x[i]; j = i - 1; while (temp < x[j] && j >= 0) x[j + 1] = x[j]; 3
4 j = j - 1; x[j + 1] = temp; Output: enter elements to be sorted: sorted elements:
5 EXPERIMENT NO-2 Objective:Write a Program to implement quick sort in C programming language. Program: # include <stdio.h> # include <conio.h> # include <time.h> void Exch(int *p, int *q) int temp = *p; *p = *q; *q = temp; void QuickSort(int a[], int low, int high) inti, j, key, k; if(low>=high) return; key=low; i=low+1; j=high; while(i<=j) while ( a[i] <= a[key] ) i=i+1; while ( a[j] > a[key] ) j=j-1; if(i<j) Exch(&a[i], &a[j]); Exch(&a[j], &a[key]); QuickSort(a, low, j-1); QuickSort(a, j+1, high); void main() int n, a[1000],k; clock_tst,et; 5
6 double ts; clrscr(); printf("\n Enter How many Numbers: "); scanf("%d", &n); printf("\nthe Random Numbers are:\n"); for(k=1; k<=n; k++) a[k]=rand(); printf("%d\t",a[k]); st=clock(); QuickSort(a, 1, n); et=clock(); ts=(double)(et-st)/clocks_per_sec; printf("\nsorted Numbers are: \n "); for(k=1; k<=n; k++) printf("%d\t", a[k]); printf("\nthe time taken is %e",ts); getch(); OUTPUT: Enter size of the array: 5 Enter 5 elements: Sorted elements:
7 EXPERIMENT NO-3 Objective:Write a Program to Implement Merge Sort in C programming language. Program: #include<stdio.h> #include<stdlib.h> void Merge(int a[], inttmp[], intlpos, intrpos, int rend) inti, lend, n, tmppos; lend = rpos - 1; tmppos = lpos; n = rend - lpos + 1; while(lpos<= lend &&rpos<= rend) if(a[lpos] <= a[rpos]) tmp[tmppos++] = a[lpos++]; else tmp[tmppos++] = a[rpos++]; while(lpos<= lend) tmp[tmppos++] = a[lpos++]; while(rpos<= rend) tmp[tmppos++] = a[rpos++]; for(i = 0; i< n; i++, rend--) a[rend] = tmp[rend]; 7
8 void MSort(int a[], inttmp[], int left, int right) int center; if(left < right) center = (left + right) / 2; MSort(a, tmp, left, center); MSort(a, tmp, center + 1, right); Merge(a, tmp, left, center + 1, right); void MergeSort(int a[], int n) int *tmparray; tmparray = malloc(sizeof(int) * n); MSort(a, tmparray, 0, n-1); free(tmparray); main() inti, n, a[10]; printf("enter the number of elements :: "); scanf("%d",&n); printf("enter the elements :: "); 8
9 for(i = 0; i< n; i++) scanf("%d",&a[i]); MergeSort(a,n); printf("the sorted elements are :: "); for(i = 0; i< n; i++) printf("%d ",a[i]); printf("\n"); OUTPUT: Enter the number of elements :: 7 Enter the elements :: The sorted elements are ::
10 EXPERIMENT NO-4 Objective:Write a Program to Implement Heap sort in Cprogramming language. Program: #include<stdio.h> void create(int []); void down_adjust(int [],int); void main() intheap[30],n,i,last,temp; printf("enter no. of elements:"); scanf("%d",&n); printf("\nenter elements:"); for(i=1;i<=n;i++) scanf("%d",&heap[i]); //create a heap heap[0]=n; create(heap); //sorting while(heap[0] > 1) //swap heap[1] and heap[last] last=heap[0]; temp=heap[1]; 10
11 heap[1]=heap[last]; heap[last]=temp; heap[0]--; down_adjust(heap,1); //print sorted data printf("\narray after sorting:\n"); for(i=1;i<=n;i++) printf("%d ",heap[i]); void create(int heap[]) inti,n; n=heap[0]; //no. of elements for(i=n/2;i>=1;i--) down_adjust(heap,i); void down_adjust(int heap[],inti) intj,temp,n,flag=1; n=heap[0]; while(2*i<=n && flag==1) j=2*i; //j points to left child if(j+1<=n && heap[j+1] > heap[j]) 11
12 j=j+1; if(heap[i] > heap[j]) flag=0; else temp=heap[i]; heap[i]=heap[j]; heap[j]=temp; i=j; OUTPUT: Enter no. of elements:5 Enter elements: Array after sorting:
13 EXPERIMENT NO-5 Objective:Write a Program to Implement Bubble Sort in C programming language. Program: #include <stdio.h> intmain() intdata[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: "); for(i=0;i<n;++i) printf("%d ",data[i]); return 0; 13
14 OUTPUT: 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:
15 EXPERIMENT NO-6 Objective:Write a Program to Implement Searching: Sequential and Binary Search. Program: #include <stdio.h> /* Function for sequential search */ void sequential_search(int array[], int size, int n) inti; for (i = 0; i< size; i++) if (array[i] == n) printf("%d found at location %d.\n", n, i+1); break; if (i == size) printf("not found! %d is not present in the list.\n", n); /* End of sequential_search() */ /* Function for binary search */ void binary_search(int array[], int size, int n) inti, first, last, middle; first = 0; last = size - 1; middle = (first+last) / 2; while (first <= last) if (array[middle] < n) first = middle + 1; else if (array[middle] == n) printf("%d found at location %d.\n", n, middle+1); break; 15
16 else last = middle - 1; middle = (first + last) / 2; if ( first> last ) printf("not found! %d is not present in the list.\n", n); /* End of binary_search() */ /* The main() begins */ intmain() inta[200], i, j, n, size; printf("enter the size of the list:"); scanf("%d", &size); printf("enter %d Integers in ascending order\n", size); for (i = 0; i< size; i++) scanf("%d", &a[i]); printf("enter value to find\n"); scanf("%d", &n); printf("sequential search\n"); sequential_search(a, size, n); printf("binary search\n"); binary_search(a, size, n); return 0; 16
17 OUTPUT: Enter the size of the list:10 Enter 10 Integers in ascending order Enter value to find 16 sequential search 16 found at location 5. Binary search 16 found at location 5 17
18 EXPERIMENT NO-7 Objective: Write a Program to implement Greedy method Fractional knapsack problem in C. Programs: #include<stdio.h> #include<time.h> #include<conio.h> void knapsack(float capacity, int n, float weight[], float profit[]) float x[20], totalprofit,y; inti,j; y=capacity; totalprofit=0; for(i=0;i <n;i++) x[i]=0.0; for(i=0;i <n;i++) if(weight[i] > y) break; else x[i]=1.0; totalprofit=totalprofit+profit[i]; y=y-weight[i]; if(i< n) x[i]=y/weight[i]; totalprofit=totalprofit+(x[i]*profit[i]); printf("the selected elements are:-\n "); for(i=0;i <n;i++) if(x[i]==1.0) printf("\nprofit is %f with weight %f ", profit[i], weight[i]); else if(x[i] > 0.0) 18
19 printf("\n%f part of Profit %f with weight %f", x[i], profit[i], weight[i]); printf("\ntotal profit for %d objects with capacity %f = %f\n\n", n, capacity,totalprofit); void main() float weight[20],profit[20],ratio[20], t1,t2,t3; int n; time_tstart,stop; float capacity; clrscr(); inti,j; printf("enter number of objects: "); scanf("%d", &n); printf("\nenter the capacity of knapsack: "); scanf("%f", &capacity); for(i=0;i <n;i++) printf("\nenter %d(th) profit: ", (i+1)); scanf("%f", &profit[i]); printf("enter %d(th) weight: ", (i+1)); scanf("%f", &weight[i]); ratio[i]=profit[i]/weight[i]; start=time(null); for(i=0;i <n;i++) for(j=0;j <n;j++) if(ratio[i] > ratio[j]) t1=ratio[i]; ratio[i]=ratio[j]; ratio[j]=t1; t2=weight[i]; weight[i]=weight[j]; weight[j]=t2; 19
20 t3=profit[i]; profit[i]=profit[j]; profit[j]=t3; knapsack(capacity,n,weight,profit); stop=time(null); printf("\nknapsack = %f\n", difftime(stop,start)); getch(); OUTPUT: Enter number of objects: 5 Enter the capacity of knapsack: 10 Enter 1(th) profit: 9 Enter 1(th) weight: 6 Enter 2(th) profit: 15 Enter 2(th) weight: 3 Enter 3(th) profit: 20 Enter 3(th) weight: 2 Enter 4(th) profit: 8 Enter 4(th) weight: 4 Enter 5(th) profit: 10 Enter 5(th) weight: 3 The selected elements are:- Profit is with weight Profit is with weight Profit is with weight part of Profit with weight Total profit for 5 objects with capacity 10 = Knapsack =
21 EXPERIMENT NO-8 Objective:Write a Program to implement Dynamic programming traveling sales person problem). Programs: #include<stdio.h> intary[10][10],completed[10],n,cost=0; void takeinput() inti,j; printf("enter the number of villages: "); scanf("%d",&n); printf("\nenter the Cost Matrix\n"); for(i=0;i <n;i++) printf("\nenter Elements of Row: %d\n",i+1); for( j=0;j <n;j++) scanf("%d",&ary[i][j]); completed[i]=0; printf("\n\nthe cost list is:"); for( i=0;i <n;i++) printf("\n"); for(j=0;j <n;j++) printf("\t%d",ary[i][j]); void mincost(int city) inti,ncity; completed[city]=1; printf("%d--->",city+1); ncity=least(city); if(ncity==999) 21
22 ncity=0; printf("%d",ncity+1); cost+=ary[city][ncity]; return; mincost(ncity); intleast(int c) inti,nc=999; int min=999,kmin; for(i=0;i <n;i++) if((ary[c][i]!=0)&&(completed[i]==0)) if(ary[c][i]+ary[i][c] < min) min=ary[i][0]+ary[c][i]; kmin=ary[c][i]; nc=i; if(min!=999) cost+=kmin; return nc; intmain() takeinput(); printf("\n\nthe Path is:\n"); mincost(0); //passing 0 because starting vertex printf("\n\nminimum cost is %d\n ",cost); return 0; 22
23 OUTPUT: Enter the number of villages: 4 Enter the Cost Matrix Enter Elements of Row: Enter Elements of Row: Enter Elements of Row: Enter Elements of Row: The cost list is: The Path is: 1 >3 >2 >4 >1 Minimum cost is 71 23
24 EXPERIMENT NO-9 Objective:Write a Program to implement Back tracking (n-queens problem). Programs: #include<stdio.h> #include<math.h> char a[10][10]; int n; void printmatrix() inti, j; printf("\n"); for (i = 0; i< n; i++) for (j = 0; j < n; j++) printf("%c\t", a[i][j]); printf("\n\n"); intgetmarkedcol(int row) inti; for (i = 0; i< n; i++) if (a[row][i] == 'Q') return (i); break; intfeasible(int row, int col) inti, tcol; for (i = 0; i< n; i++) tcol = getmarkedcol(i); if (col == tcol abs(row - i) == abs(col - tcol)) return 0; return 1; void nqueen(int row) inti, j; if (row < n) 24
25 for (i = 0; i< n; i++) if (feasible(row, i)) a[row][i] = 'Q'; nqueen(row + 1); a[row][i] = '.'; else printf("\nthe solution is:- "); printmatrix(); intmain() inti, j; printf("\nenter the no. of queens:- "); scanf("%d", &n); for (i = 0; i< n; i++) for (j = 0; j < n; j++) a[i][j] = '.'; nqueen(0); return (0); OUTPUT: Enter the no. of queens:- 4 The solution is:-. Q..... Q Q..... Q. The solution is:-.. Q. Q Q. Q.. 25
26 EXPERIMENT NO-10 Objective:Write a Program to implement Back tracking (Hamiltonian cycles). Programs: #include<stdio.h> #include<conio.h> #define MAX 25 int x[max]; void Next_Vertex(int G[MAX][MAX],intn,int k) int j; while(1) x[k]=(x[k]+1)%(n+1); if(x[k]==0) return; if(g[x[k-1]][x[k]]!=0) for(j=1;j<=k-1;j++) if(x[j]==x[k]) break; if(j==k) if((k<n) ((k==n)&&(g[x[n]][x[1]]!=0))) return; void H_Cycle(int G[][MAX],intn,int k) inti; while(1) Next_Vertex(G,n,k); if(x[k]==0) return; if(k==n) printf("\n"); 26
27 for(i=1;i<=n;i++) printf(" %d",x[i]); printf(" %d",x[1]); else H_Cycle(G,n,k+1); void main() inti,j,v1,v2,edges,n,g[max][max]; clrscr(); printf("\n\t Program for Hamiltonian Cycle "); printf("\n Enter the number of vertices of graph: "); scanf("%d",&n); for(i=1;i<=n;i++) for(j=1;j<=n;j++) G[i][j]=0; x[i]=0; printf("\n Enter the total number of edges: "); scanf("%d",&edges); for(i=1;i<=edges;i++) printf("\n Enter the edge: "); scanf("%d%d",&v1,&v2); G[v1][v2]=1; G[v2][v1]=1; x[1]=1; printf("\n Hamiltonian cycle...\n"); H_Cycle(G,n,2); getch(); 27
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 informationUNIT 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 informationAlgorithms Lab (NCS 551)
DRONACHARYA GROUP OF INSTITUTIONS, GREATER NOIDA Affiliated to Utter Pradesh Technical University Noida Approved by AICTE Algorithms Lab (NCS 551) SOLUTIONS 1. PROGRAM TO IMPLEMENT INSERTION SORT. #include
More informationArrays 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 informationPROGRAMMING 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 informationUnit 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 informationDEV BHOOMI INSTITUTE OF TECHNOLOGY Department of Computer Science and Engineering. Algorithm lab- PCS-553 LAB MANUAL
DEV BHOOMI INSTITUTE OF TECHNOLOGY Department of Computer Science and Engineering Year: 3rd Semester: 5th Algorithm lab- PCS-553 LAB MANUAL Prepared By: HOD (CSE) 1 DEV BHOOMI INSTITUTE OF TECHNOLOGY DEV
More informationStructured programming
Exercises 6 Version 1.0, 25 October, 2016 Table of Contents 1. Arrays []................................................................... 1 1.1. Declaring arrays.........................................................
More informationBITS 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 informationStructured programming
Exercises 9 Version 1.0, 13 December, 2016 Table of Contents 1. Remainders from lectures.................................................... 1 1.1. What is a pointer?.......................................................
More information'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 informationList 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 informationProgramming 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 informationDEV BHOOMI INSTITUTE OF TECHNOLOGY
DEV BHOOMI INSTITUTE OF TECHNOLOGY Department of Computer Science and Engineering Year: 2rd Semester: 3rd CBNST Lab-PCS-302 LAB MANUAL Prepared By: HOD (CSE) DEV BHOOMI INSTITUTE OF TECHNOLOGY Department
More informationKareemNaaz Matrix Divide and Sorting Algorithm
KareemNaaz Matrix Divide and Sorting Algorithm Shaik Kareem Basha* Department of Computer Science and Engineering, HITAM, India Review Article Received date: 18/11/2016 Accepted date: 13/12/2016 Published
More informationContents. Sr. No. Title of the Practical: Page no Signature. Gate. OR gate. EX-OR gate. gate. identifying ODD and EVEN number.
Contents Sr. No. Title of the Practical: Page no Signature 01. To Design and train a perceptron for AND Gate. 02. To design and train a perceptron training for OR gate. 03. To design and train a perceptron
More informationArrays in C. By Mrs. Manisha Kuveskar.
Arrays in C By Mrs. Manisha Kuveskar. C Programming Arrays An array is a collection of data that holds fixed number of values of same type. For example: if you want to store marks of 100 students, you
More informationChapter 7 Solved problems
Chapter 7 7.4, Section D 20. The coefficients of a polynomial function are stored in a single-dimensional array. Display its derivative. If the polynomial function is p(x) = a n x n + a n-1 x n-1 + + a
More informationGovernment Polytechnic Muzaffarpur.
Government Polytechnic Muzaffarpur. Name of the Lab: COMPUTER PROGRAMMING LAB (MECH. ENGG. GROUP) Subject Code: 1625408 Experiment: 1 Aim: Programming exercise on executing a C program. If you are looking
More informationInitialisation of an array is the process of assigning initial values. Typically declaration and initialisation are combined.
EENG212 Algorithms & Data Structures Fall 08/09 Lecture Notes # 2 OUTLINE Review of Arrays in C Declaration and Initialization of Arrays Sorting: Bubble Sort Searching: Linear and Binary Search ARRAYS
More informationonly 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 informationPROGRAM 1 AIM: Write a program to find the number of vertices, even vertices, odd vertices and the number of edges in a graph.
PROGRAM 1 AIM: Write a program to find the number of vertices, even vertices, odd vertices and the number of edges in a graph. CODE: #include using namespace std; #include #define MAX
More informationC Language Part 2 Digital Computer Concept and Practice Copyright 2012 by Jaejin Lee
C Language Part 2 (Minor modifications by the instructor) 1 Scope Rules A variable declared inside a function is a local variable Each local variable in a function comes into existence when the function
More informationWhat 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 informationLECTURE 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 informationLab Manual B.Tech 1 st Year
Lab Manual B.Tech 1 st Year Fundamentals & Computer Programming Lab Dev Bhoomi Institute of Technology Dehradun www.dbit.ac.in Affiliated to Uttrakhand Technical University, Dehradun www.uktech.in CONTENTS
More informationUnit 5. Decision Making and Looping. School of Science and Technology INTRODUCTION
INTRODUCTION Decision Making and Looping Unit 5 In the previous lessons we have learned about the programming structure, decision making procedure, how to write statements, as well as different types of
More informationWAP 10. WAP 11. WAP 12. WAP 13. WAP 14. WAP 15. WAP 16. WAP 1. : 17. WAP 18. WAP 19. WAP 20. WAP 21. WAP 22. WAP 23. WAP & 24. WAP
Contents 1. WAP to accept the value from the user and exchange the values.... 2 2. WAP to check whether the number is even or odd.... 2 3. WAP to Check Odd or Even Using Conditional Operator... 3 4. WAP
More information/* Area and circumference of a circle */ /*celsius to fahrenheit*/
/* Area and circumference of a circle */ #include #include #define pi 3.14 int radius; float area, circum; printf("\nenter radius of the circle : "); scanf("%d",&radius); area = pi
More informationF.Y. Diploma : Sem. II [CO/CD/CM/CW/IF] Programming in C
F.Y. Diploma : Sem. II [CO/CD/CM/CW/IF] Programming in C Time : 3 Hrs.] Prelim Question Paper Solution [Marks : 70 Q.1 Attempt any FIVE of the following : [10] Q.1 (a) List any four relational operators.
More informationPESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of Basic Science and Humanities
PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of Basic Science and Humanities Continuous Internal Evaluation Test 2 Date: 0-10- 2017 Marks: 0 Subject &
More informationLecture 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 informationQ 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 informationIntroduction to Computing Lecture 07: Repetition and Loop Statements (Part II)
Introduction to Computing Lecture 07: Repetition and Loop Statements (Part II) Assist.Prof.Dr. Nükhet ÖZBEK Ege University Department of Electrical & Electronics Engineering nukhet.ozbek@ege.edu.tr Topics
More informationData 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 informationSearching an Array: Linear and Binary Search. 21 July 2009 Programming and Data Structure 1
Searching an Array: Linear and Binary Search 21 July 2009 Programming and Data Structure 1 Searching Check if a given element (key) occurs in the array. Two methods to be discussed: If the array elements
More informationMTH 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 informationCS11001/CS11002 Programming and Data Structures (PDS) (Theory: 3-1-0) Introduction to arrays
CS11001/CS11002 Programming and Data Structures (PDS) (Theory: 3-1-0) Introduction to arrays 1 What are Arrays? Arrays are our first example of structured data. Think of a book with pages numbered 1,2,...,400.
More informationSRI CHANDRASEKHARENDRA SARASWATHI VISWA MAHAVIDYALAYA (UNIVERSITY ESTABLISHED UNDER SECTION 3 OF UGC ACT 1956) ENATHUR - KANCHIPURAM
SRI CHANDRASEKHARENDRA SARASWATHI VISWA MAHAVIDYALAYA (UNIVERSITY ESTABLISHED UNDER SECTION 3 OF UGC ACT 1956) ENATHUR - KANCHIPURAM 631 561 DATA STRUCTURES LAB LABORATORY RECORD Name : Register. No :
More informationCSCI 2132 Software Development Lecture 18: Implementation of Recursive Algorithms
Lecture 18 p.1 Faculty of Computer Science, Dalhousie University CSCI 2132 Software Development Lecture 18: Implementation of Recursive Algorithms 17-Oct-2018 Location: Chemistry 125 Time: 12:35 13:25
More informationAPS105. Collecting Elements 10/20/2013. Declaring an Array in C. How to collect elements of the same type? Arrays. General form: Example:
Collecting Elements How to collect elements of the same type? Eg:., marks on assignments: APS105 Arrays Textbook Chapters 6.1-6.3 Assn# 1 2 3 4 5 6 Mark 87 89 77 96 87 79 Eg: a solution in math: x 1, x
More informationProgram. SUBJECT: ACP (C - Programming) Array Program. // Find the minimum number from given N element. Prepared By : Dhaval R.
Program // Find the minimum number from given N element. #include #include void main() int a[50],i,n,min; clrscr(); printf("\n Enter array size : "); scanf("%d",&n); printf("\n Enter
More informationF.E. Sem. II. Structured Programming Approach
F.E. Sem. II Structured Programming Approach Time : 3 Hrs.] Mumbai University Examination Paper Solution - May 14 [Marks : 80 Q.1(a) What do you mean by algorithm? Which points you should consider [4]
More informationF.E. Sem. II. Structured Programming Approach
F.E. Sem. II Structured Programming Approach Time : 3 Hrs.] Mumbai University Examination Paper Solution - May 13 [Marks : 80 Q.1(a) Explain the purpose of following standard library functions : [3] (i)
More informationCSE101-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 informationMAHARASHTRA 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 informationC 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 informationCSCI 2132 Software Development. Lecture 19: Generating Permutations
CSCI 2132 Software Development Lecture 19: Generating Permutations Instructor: Vlado Keselj Faculty of Computer Science Dalhousie University 19-Oct-2018 (19) CSCI 2132 1 Previous Lecture Mergesort implementation
More informationJawaharlal Nehru Engineering College
Jawaharlal Nehru Engineering College Laboratory Manual ADVANCED ALGORITHM For Final Year Students CSE Dept: Computer Science & Engineering (NBA Accredited) Author JNEC, Aurangabad 1 FOREWORD It is my great
More informationAPPLIED GRAPH THEORY FILE. 7 th Semester MCE MCDTU.WORDPRESS.COM
APPLIED GRAPH THEORY FILE 7 th Semester MCE MCDTU.WORDPRESS.COM INDEX S.No. TOPIC DATE TEACHER S SIGNATURE 1. Write a program to find the number of vertices, even vertices, odd vertices and the number
More informationChapter4: Data Structures. Data: It is a collection of raw facts that has implicit meaning.
Chapter4: s Data: It is a collection of raw facts that has implicit meaning. Data may be single valued like ID, or multi valued like address. Information: It is the processed data having explicit meaning.
More informationLAB MANUAL. ANTC Lab (ME-321- F) DEPARTMENT OF APPLIED SCIENCE AND HUMINITIES
LAB MANUAL ANTC Lab (ME-321- F) DEPARTMENT OF APPLIED SCIENCE AND HUMINITIES 1 Check list for Lab Manual S. No. Particulars Page Number 1 Mission and Vision 3 2 Guidelines for the student 4 3 List of Programs
More informationClassification s of Data Structures
Linear Data Structures using Sequential organization Classification s of Data Structures Types of Data Structures Arrays Declaration of arrays type arrayname [ arraysize ]; Ex-double balance[10]; Arrays
More informationInternal Sort by Comparison II
DS: CS 11002 Computer Sc & Engg: IIT Kharagpur 1 Internal Sort by Comparison II DS: CS 11002 Computer Sc & Engg: IIT Kharagpur 2 Merge Sort Algorithm This internal sorting algorithm by comparison was invented
More information1) Write a C Program to check whether given year is Leap year or not. AIM: A C Program to check whether given year is Leap year or not.
1) Write a C Program to check whether given year is Leap year or not. AIM: A C Program to check whether given year is Leap year or not. #include int year; printf("enter a year:"); scanf("%d",&year);
More informationCS11001/CS11002 Programming and Data Structures (PDS) (Theory: 3-0-0)
CS11001/CS11002 Programming and Data Structures (PDS) (Theory: 3-0-0) Sudeshna Sarkar Department of Computer Science and Engineering Indian Institute of Technology Kharagpur Euclid s Algorithm Basic Observation:
More informationTwo Dimensional Array - An array with a multiple indexs.
LAB5 : Arrays Objectives: 1. To learn how to use C array as a counter. 2. To learn how to add an element to the array. 3. To learn how to delete an element from the array. 4. To learn how to declare two
More informationTo store the total marks of 100 students an array will be declared as follows,
Chapter 4 ARRAYS LEARNING OBJECTIVES After going through this chapter the reader will be able to declare and use one-dimensional and two-dimensional arrays initialize arrays use subscripts to access individual
More information/*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 informationPrepared 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 informationCSE101-lec#19. Array searching and sorting techniques. Created By: Amanpreet Kaur & Sanjeev Kumar SME (CSE) LPU. LPU CSE101 C Programming
CSE101-lec#19 Array searching and sorting techniques Created By: Amanpreet Kaur & Sanjeev Kumar SME (CSE) LPU Outline Introduction Linear search Binary search Bubble sort Introduction The process of finding
More informationC programming Lecture 15. School of Mathematics Trinity College Dublin. Marina Krstic Marinkovic
C programming 5613 Lecture 15 Marina Krstic Marinkovic mmarina@maths.tcd.ie School of Mathematics Trinity College Dublin Marina Krstic Marinkovic 1 / 14 5613 - C programming In a rucksack (knapsack) problem
More informationDEV 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 information1. Write a C program that receives 10 float numbers from the console and sort them in nonascending order, and prints the result
Solutions 1. Write a C program that receives 10 float numbers from the console and sort them in nonascending order, and prints the result #include int main() //Program Start float numbers[10],result;
More informationInternal Sort by Comparison II
C Programming Computer Sc & Engg: IIT Kharagpur 1 Internal Sort by Comparison II C Programming Computer Sc & Engg: IIT Kharagpur 2 Merge Sort Algorithm This internal sorting algorithm by comparison was
More informationDESIGN AND ANALYSIS OF ALGORITHMS LABORATORY (Common to CSE & ISE)
DESIGN AND ANALYSIS OF ALGORITHMS LABORATORY (Common to CSE & ISE) Subject Code: 10CSL47 I.A. Marks : 25 Hours/Week : 03 Exam Hours: 03 Total Hours : 42 Exam Marks: 50 Design, develop and implement the
More informationEXNO:9 IMPLEMENTATION OF HASHING TECHNIQUES
EXNO:9 IMPLEMENTATION OF HASHING TECHNIQUES AIM:- To Implement the hashing techniques using C. ALGORITHM:- 1. Start the program 2. Get the array size. 3. Get the elements of the array. 4. Get the key value
More informationInternal Sort by Comparison II
PDS: CS 11002 Computer Sc & Engg: IIT Kharagpur 1 Internal Sort by Comparison II PDS: CS 11002 Computer Sc & Engg: IIT Kharagpur 2 Merge Sort Algorithm This internal sorting algorithm by comparison was
More informationLinked 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 informationMGM S JAWAHARLAL NEHRU ENGINEERING COLLEGE N-6, CIDCO, AURANGABAD LAB MANUALS SUB: COMPUTER LAB-II CLASS: S.E.CIVIL
MGM S JAWAHARLAL NEHRU ENGINEERING COLLEGE N-6, CIDCO, AURANGABAD LAB MANUALS (Procedure for conduction of Practical/Term Work) SUB: COMPUTER LAB-II CLASS: S.E.CIVIL Prepared by Ms.V.S.Pradhan Lab In charge
More informationSearching Elements in an Array: Linear and Binary Search. Spring Semester 2007 Programming and Data Structure 1
Searching Elements in an Array: Linear and Binary Search Spring Semester 2007 Programming and Data Structure 1 Searching Check if a given element (called key) occurs in the array. Example: array of student
More informationSubject: Fundamental of Computer Programming 2068
Subject: Fundamental of Computer Programming 2068 1 Write an algorithm and flowchart to determine whether a given integer is odd or even and explain it. Algorithm Step 1: Start Step 2: Read a Step 3: Find
More informationBCSE1002: Computer Programming and Problem Solving LAB MANUAL
LABMANUAL BCSE1002: Computer Programming and Problem Solving LAB MANUAL L T P Course Type Semester Offered Academic Year 2018-2019 Slot Class Room Faculty Details: Name Website link Designation School
More informationLab 10: Disk Scheduling Algorithms
1. Objective Lab 10: Disk Scheduling Algorithms Understand Disk Scheduling Algorithm and read its code for SSTF, SCAN, CSCAN in C, 2. Syllabus try to write other kinds of disk scheduling algorithms such
More informationMAHARASHTRA 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 informationContents ARRAYS. Introduction:
UNIT-III ARRAYS AND STRINGS Contents Single and Multidimensional Arrays: Array Declaration and Initialization of arrays Arrays as function arguments. Strings: Initialization and String handling functions.
More informationSOFTWARE TESTING LABORATORY. Subject Code: 10ISL68 I.A. Marks: 25 Hours/Week: 03 Exam Hours: 03 Total Hours: 42 Exam Marks: 50
SOFTWARE TESTING LABORATORY Subject Code: 10ISL68 I.A. Marks: 25 Hours/Week: 03 Exam Hours: 03 Total Hours: 42 Exam Marks: 50 1. Design and develop a program in a language of your choice to solve the Triangle
More informationMODULE 1. Introduction to Data Structures
MODULE 1 Introduction to Data Structures Data Structure is a way of collecting and organizing data in such a way that we can perform operations on these data in an effective way. Data Structures is about
More informationUNIVERSITY OF WINDSOR Fall 2007 QUIZ # 2 Solution. Examiner : Ritu Chaturvedi Dated :November 27th, Student Name: Student Number:
UNIVERSITY OF WINDSOR 60-106-01 Fall 2007 QUIZ # 2 Solution Examiner : Ritu Chaturvedi Dated :November 27th, 2007. Student Name: Student Number: INSTRUCTIONS (Please Read Carefully) No calculators allowed.
More informationTHE BAPATLA ENGINEERING COLLEGE:: BAPATLA DEPARTMENT OF MCA. Subject name: C programing Lab. Subject code: MCA 107. LAB manual of c programing lab
THE BAPATLA ENGINEERING COLLEGE:: BAPATLA DEPARTMENT OF MCA Subject name: C programing Lab Subject code: MCA 107 LAB manual of c programing lab 1. Write a C program for calculating compound interest. #include
More informationName Roll No. Section
Indian Institute of Technology, Kharagpur Computer Science and Engineering Department Class Test I, Autumn 2012-13 Programming & Data Structure (CS 11002) Full marks: 30 Feb 7, 2013 Time: 60 mins. Name
More informationFrequently 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 informationCS101 Computer Programming Quiz for Wednesday Batch 8 October 2014
CS101 Computer Programming Quiz for Wednesday Batch 8 October 2014 Q1. Consider the following variation of Merge Sort to sort the array in descending order. In the version of Merge Sort discussed in class,
More informationSRI VIDYA COLLEGE OF ENGINEERING & TECHNOLOGY, VIRUDHUNAGAR Department of CSE & IT Internal Test I
SRI VIDYA COLLEGE OF ENGINEERING & TECHNOLOGY, VIRUDHUNAGAR Department of CSE & IT Internal Test I Year & Sem: I B.E (CSE) & II Date of Exam: 21/02/2015 Subject Code & Name: CS6202 & Programming & Data
More informationMAHARASHTRASTATE 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 informationProgramming & Data Structure Laboratory. Arrays, pointers and recursion Day 5, August 5, 2014
Programming & Data Structure Laboratory rrays, pointers and recursion Day 5, ugust 5, 2014 Pointers and Multidimensional rray Function and Recursion Counting function calls in Fibonacci #include
More informationOne Dimension Arrays 1
One Dimension Arrays 1 Array n Many applications require multiple data items that have common characteristics In mathematics, we often express such groups of data items in indexed form: n x 1, x 2, x 3,,
More informationTwo Dimensional Array - An array with a multiple indexs.
LAB5 : Arrays Objectives: 1. To learn how to use C array as a counter. 2. To learn how to add an element to the array. 3. To learn how to delete an element from the array. 4. To learn how to declare two
More informationYour favorite blog : (popularly known as VIJAY JOTANI S BLOG..now in facebook.join ON FB VIJAY
Course Code : BCS-042 Course Title : Introduction to Algorithm Design Assignment Number : BCA(IV)-042/Assign/14-15 Maximum Marks : 80 Weightage : 25% Last Date of Submission : 15th October, 2014 (For July
More information-2017-18 1. a.. b. MS-Paint. Ex.No 1 Windows XP c. 23,, d. MS-Dos DIR /W /P /B /L. Windows Xp, MS-Paint, Dir ; 1. Properties 23 10111 23 27 23 17 2. Display Properties MS-Paint ok 1. Start All program
More informationComputer Programming Unit 3
POINTERS INTRODUCTION Pointers are important in c-language. Some tasks are performed more easily with pointers such as dynamic memory allocation, cannot be performed without using pointers. So it s very
More informationMake sure the version number is marked on your scantron sheet. This is Version 1
Last Name First Name McGill ID Make sure the version number is marked on your scantron sheet. This is Version 1 McGill University COMP 208 -- Computers in Engineering Mid-Term Examination Tuesday, March
More informationCS 310 Advanced Data Structures and Algorithms
CS 310 Advanced Data Structures and Algorithms Sorting June 13, 2017 Tong Wang UMass Boston CS 310 June 13, 2017 1 / 42 Sorting One of the most fundamental problems in CS Input: a series of elements with
More informationFundamental of Programming (C)
Borrowed from lecturer notes by Omid Jafarinezhad Fundamental of Programming (C) Lecturer: Vahid Khodabakhshi Lecture 8 Array typical problems, Search, Sorting Department of Computer Engineering Outline
More informationSorting. Bubble Sort. Pseudo Code for Bubble Sorting: Sorting is ordering a list of elements.
Sorting Sorting is ordering a list of elements. Types of sorting: There are many types of algorithms exist based on the following criteria: Based on Complexity Based on Memory usage (Internal & External
More informationIntroduction to Arrays
Introduction to Arrays One Dimensional Array. Two Dimensional Array. Inserting Elements in Array. Reading Elements from an Array. Searching in Array. Sorting of an Array. Merging of 2 Arrays. What is an
More informationUNIT 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//2D TRANSFORMATION TRANSLATION, ROTATING AND SCALING. #include<stdio.h> #include<conio.h> #include<graphics.h> #include<math.h> #include<stdlib.
//2D TRANSFORMATION TRANSLATION, ROTATING AND SCALING #include #include #include #include #include void main() int gd=detect,gm,i,x[10],y[10],a,b,c,d,n,tx,ty,sx,sy,ch;
More informationProgramming and Data Structures Mid-Semester - Solutions to Sample Questions Dept. of Computer Science and Engg. IIT Kharagpur Spring
Programming and Data Structures Mid-Semester - s to Sample Questions Dept. of Computer Science and Engg. IIT Kharagpur Spring 2015-16 February 15, 2016 1. Tick the correct options. (a) Consider the following
More informationUnit-4 Sorting PROGRAM:
Unit-4 Sorting : Sorting Techniques- Sorting by Insertion: Straight Insertion sort- List insertion sort- Binary insertion sort- Sorting by selection: Straight selection sort- Heap Sort- Sorting by Exchange-
More information