25 views

Uploaded by Taimoor Shakeel

abc

abc

© All Rights Reserved

- Data Structures VIVA Questions and Answers
- Lect Plan DS
- Data Structures Using ‘c’ Language
- Cse IV Design and Analysis of Algorithms 10cs43 Notes
- Sorting
- CS_F111_1008
- This is My Technical Interview Cheat Sheet
- Space & Time Complexity Chart
- Algorithm Sample
- A reversible data hiding based on adaptive prediction technique and histogram shifting
- multi-tier
- CS301-Lec02 handout
- Daa
- draisbach_icde12
- a6r4
- Studying for a Tech Interview Sucks
- SKEW Hospital Reception
- Various Computational Models
- Paper 2
- Discovering_Computer_Science_Interdiscip.pdf

You are on page 1of 28

LABORATORY MANUAL

II - CSE

III - SEMESTER

ACADEMIC YEAR: 2012-2013

SRM UNIVERSITY,

SRM NAGAR, KATTANKULATHUR-603203.

KANCHEEPURAM DISTRICT.

SRM UNIVERSITY,

SRM NAGAR, KATTANKULATHUR-603203.

SUBJECT : DATA STRUCTURES AND ALGORITHM SUBJECT CODE : CS0213

SEMESTER : III

CLASS

: II CSE

EX. NO

1

2

3

4

5

6

7

8

9

10

11

12

PAGE NO

LINEAR SEARCH

BINARY SEARCH

SELECTION SORT

BUBBLE SORT

INSERTION SORT

11

MERGE SORT

13

QUICK SORT

15

STACKS

17

QUEUES

19

21

KNAPSACK PROBLEM

23

25

LINEAR SEARCH

AIM:

To find a given target number using linear search from the list of numbers.

ALGORITHM:

Step 1: Initialize the integer variables

Step 2: Get the target number from user

Step 3: Get the list of numbers to be searched

Step 4: If the counter is equal to target the print the location

Step 5: If it is not equal to then print that the location is not found

INPUT:

Enter the number to be found: 25

Enter the number of elements in the list: 5

Enter the elements: 12 22 37 25 61

OUTPUT:

The number is found in location: 4

RESULT:

The target number is found using linear search successfully

4

BINARY SEARCH

AIM:

To find a given target number using Binary Search from the list of number.

ALGORITHM:

Step 1: Initialize the integer variables

Step 2: Get the values from the list

Step 3: Sorted List of numbers is got as input.

Step 4: Get the target number from the user.

Step 5: Initialize first value as zero and last as n-1;

Step 6: The mid value is found.

Step 7: If the target is greater than mid then first is mid + 1 if not last is mid -1.

Step 8: First is last +1

Step 9: The target is found, if its equal to a(mid) otherwise target is not

found.

INPUT:

Enter the number of elements in the list: 5

Enter the sorted list: 11 22 33 44 55

Enter the target: 33

OUTPUT:

The target is found in location: 3

RESULT:

The target number is found using Binary Search successfully

SELECTION SORT

AIM:

To sort the given data using selection sort.

ALGORITHM:

Step 1: Initialize the integer variables.

Step 2: Get the total number of values from the user.

Step 3: Get the numbers to be sorted.

Step 4: Initialize i to current

Step 5: If current is less than j ,then initialize j to current.

Step 6: Assign j to temp, current to i and temp to current for swapping

Step 7: print the sorted data

INPUT

Enter the number of elements: 5

Enter the Numbers to be sorted: 31 21 77 62 45

OUTPUT

Sorted Data: 21 31 45 62 77

RESULT:

The given data is sorted and printed using selection sort.

8

BUBBLE SORT

AIM:

To sort the given data using Bubble sort.

ALGORITHM:

Step 1: Initialize the variables i,j,n, and temp.

Step 2: Get the number of elements.

Step 3: Get the numbers to be sorted.

Step 4; Assign a[i] to temp

Step 5: Assign a[i+1] to a[i]

Step 6: Assign Temp to a[i+1]

Step 7: The data is sorted.

INPUT

Enter the number of elements: 6

Enter the numbers to be sorted: 22 66 11 99 33 77

OUTPUT

Sorted Data: 11 22 33 66 77 99

RESULT:

The given data is sorted and printed using Bubble sort.

10

INSERTION SORT

AIM:

To sort the given data using Insertion sort.

ALGORITHM:

Step 1: Initialize the variables i,j,n, curr and temp.

Step 2: Get the number of elements.

Step 3: Get the numbers to be sorted.

Step 4: If the second element is less than the first element then assign it to

temp.

Step 5: Assign the first element to second element.

Step 6: Assign Temp to first element.

Step 7: The swapping is done

Step 8: The data is sorted.

11

INPUT

Enter the number of entries: 5

Enter the list of no to be sorted: 25 15 35 05 45

OUTPUT

The sorted list: 05 15 25 35 45

RESULT:

The given data is sorted and printed using Insertion Sort.

12

MERGE SORT

AIM:

To sort the given data using Merge sort.

ALGORITHM:

Step 1: Initialize the variables i,j,n,h,k,low,high.

Step 2: Get the number of elements.

Step 3: Get the numbers to be sorted.

Step 4: If low is less than high then find the mid value.

Step 5: Initialize h and i to low.

Step 6: Initialize a[h] to b[i] else a[j] to b[i].

Step 7: If h is greater than mid then a[k] == b[i] else b[k] == a[k]

Step 8 The data is sorted and printed.

13

INPUT

Enter the number of elements: 7

The elements: 22 66 11 44 99 33 77

OUTPUT

Sorted Data: 11 22 33 44 66 77 99

RESULT:

The given data is sorted and printed using Merge Sort.

14

QUICK SORT

AIM:

To sort the given data using Quick Sort.

ALGORITHM:

Step 1: Initialize the variables i,j,n,r,p,q.

Step 2: Get the number of elements.

Step 3: Get the numbers to be sorted.

Step 4: If p is less than q then the function is called.

Step 5: If i is less than j, then interchange them.

Step 6: If I is less than pivort interchange them.

Step 7: The data is sorted and printed.

15

INPUT

Enter the number of elements: 5

Enter the unsorted list: 39 62 57 41 21

OUTPUT

The sorted list is: 21 41 39 57 62

RESULT:

The given data is sorted and printed using Quick Sort.

16

STACKS

AIM:

To perform all stacks operation.

ALGORITHM:

Step 1: Initialize the integer variables.

Step 2: In a switch case, in case 1 the number to be pushed is got

Step 3:Top is now equal to top+1

Step 4: Else the stack is full

Step 5: In case 2 the number to be deleted is got

Step 6: Top is now equal to top-1

Step 7: Else the stack is empty

Step 8: In case 3 if the top is less than 0 the stack is full

Step 9: Else the stack is printed

Step 10: Default is no such choice

INPUT / OUTPUT

17

1

Enter the number to be Added: 11

Enter the operation to be performed: 1) push 2) pop 3) display 4) exit

1

Enter the number to be Added: 22

Enter the operation to be performed: 1) push 2) pop 3) display 4) exit

1

Enter the number to be Added: 33

Enter the operation to be performed: 1) push 2) pop 3) display 4) exit

1

Enter the number to be Added: 44

Enter the operation to be performed: 1) push 2) pop 3) display 4) exit

2

Enter the number to be Added: 44

Enter the operation to be performed: 1) push 2) pop 3) display 4) exit

3

The stack is 11 22 33

Enter the operation to be performed: 1) push 2) pop 3) display 4) exit

4

RESULT:

All the stack operations are performed using the switch case

18

QUEUES

AIM:

To perform all the queue operations

ALGORITHM:

Step 1:Initialize the integer variables

Step 2:In a switch case in case 1 get the number to be added in the queue

Step 3: Else the queue is full

Step 4: In case 2 get the number to be deleted from the queue

Step 5: Else the queue is full

Step 6: If tail and head are less than 0 then in case 3 the queue is full

Step 7: Else the queue is printed

Step 8: The default case is no such choice

19

INPUT / OUTPUT:

Enter the operation to be performed: 1)Enqueue 2)Dequeue 3)Display 4)Exit

1

Enter the number to be added 11

Enter the operation to be performed: 1)Enqueue 2)Dequeue 3)Display 4)Exit

1

Enter the number to be added 22

Enter the operation to be performed: 1)Enqueue 2)Dequeue 3)Display 4)Exit

1

Enter the number to be added 33

Enter the operation to be performed: 1)Enqueue 2)Dequeue 3)Display 4)Exit

1

Enter the number to be added 44

Enter the operation to be performed: 1)Enqueue 2)Dequeue 3)Display 4)Exit

2

The number to be deleted is 11

Enter the operation to be performed: 1)Enqueue 2)Dequeue 3)Display 4)Exit

3

The queue is 22 33 44

RESULT:

All the queue operations are performed

20

AIM:

To find the maximum and minimum value in a given list of numbers

ALGORITHM:

Step 1:Initialise the variables in the main function

Step 2: Get the total number of items

Step 3: Get the numbers from the user

Step 4: The function is called.

If there is only one element then the max and min is the same element

Step 5: If there is two element then check if a[x] is less than a[y] then a[x] is

min and a[y] is max

Step 6: If there is more number of items mid value is found

Step 7: Now max is assigned to t1 and min to t2

Step 8: If the max is less than t1 the max is t1,if min is greater than t2 the

min t2

Step 9: The min and max values are found and printed

21

INPUT

Enter the no of numbers: 6

Enter the numbers: 33 59 11 67 92 05

OUTPUT

Maximum Number = 92

Minimum Number = 05

RESULT:

The maximum and minimum number is found and printed.

22

KNAPSACK PROBLEM

AIM:

To find the maximum profit from the items in the bag.

ALGORITHM:

Step 1: Initialize the variables, profit, weight, p/w and maxprofit.

Step 2: Get the number of elements.

Step 3: Get the capacity of the bag.

Step 4: Get the profit of items in the bag.

Step 5: Get the weight of each item in the bag.

Step 7: Assign pw[j] to t1, p[j] to t2 and w[j] to t3.

Step 8: If w[i] > capacity then find the ratio of capacity to weight of each item.

Step 9: Else subtract the weight of the item from the total capacity.

Step 10: Solution vector is found and printed.

Step 11: The maximum profit is found and printed.

23

INPUT/OUTPUT:

4

Enter the capacity:

4

Enter the profit:

5

9

4

8

Enter the weight:

1

3

2

2

Enter the p/w ratio:

5

3

2

4

Solution vector:

13

15

16

Profit: 16

RESULT:

The maximum profit is found and printed on the screen.

24

AIM:

To perform all the singly linked list operations

ALGORITHM:

Step 1: Declare the functions to create,display,count.

Step 2: Declare the variables in the main function.

Step 3: In a switch case get each functions number.

Step 4: To append the list create the memory by using malloc function.

Step 5: Assign a variable temp using pointers.

Step 6: To delete a node create a dummy variable.

Step 7: Check if the list is empty otherwise display the list using for

statement.

Step 8: To insert a node in middle, allocate memory using malloc function

25

INPUT / OUTPUT:

Singly Linked List:

1. Create or Append List

2. Insert in Beginning

3. Insert in Middle

4. Remove from the List

5. Count

6. Display

7. Quit

Enter your Choice: 1

Enter any number: 12

Enter more(y/n): y

Enter any number: 13

Enter more(y/n): n

Singly Linked List:

1. Create or Append List

2. Insert in Beginning

3. Insert in Middle

4. Remove from the List

5. Count

6. Display

7. Quit

Enter your Choice: 2

Enter the Data to be inserted at Beginning: 11

Singly Linked List:

1. Create or Append List

2. Insert in Beginning

3. Insert in Middle

4. Remove from the List

5. Count

6. Display

7. Quit

26

Enter the Position to be Inserted: 2

Enter the Data: 14

Singly Linked List:

1. Create or Append List

2. Insert in Beginning

3. Insert in Middle

4. Remove from the List

5. Count

6. Display

7. Quit

Enter your Choice: 4

Enter the Data to be Deleted: 12

Singly Linked List:

1. Create or Append List

2. Insert in Beginning

3. Insert in Middle

4. Remove from the List

5. Count

6. Display

7. Quit

Enter your Choice: 5

The Number of Nodes: 3

27

1. Create or Append List

2. Insert in Beginning

3. Insert in Middle

4. Remove from the List

5. Count

6. Display

7. Quit

Enter your Choice: 6

11 14 13

RESULT:

All the Singly Linked List operations are performed.

28

- Data Structures VIVA Questions and AnswersUploaded byAchyuth Koteswarao
- Lect Plan DSUploaded byapi-3747330
- Data Structures Using ‘c’ LanguageUploaded bySaurabh Kumar
- Cse IV Design and Analysis of Algorithms 10cs43 NotesUploaded bymamudu francis
- SortingUploaded bychanderbal
- CS_F111_1008Uploaded byroshanscientistgotra
- This is My Technical Interview Cheat SheetUploaded byAshish
- Space & Time Complexity ChartUploaded bymanan00
- Algorithm SampleUploaded byTiatemsu
- A reversible data hiding based on adaptive prediction technique and histogram shiftingUploaded bySakthi Velan
- multi-tierUploaded byInternational Journal of Innovative Science and Research Technology
- CS301-Lec02 handoutUploaded byDrHappy NK Yadav
- DaaUploaded byAnkitKoshti
- draisbach_icde12Uploaded byRizki Okta
- a6r4Uploaded byGhanshyam Sharma
- Studying for a Tech Interview SucksUploaded byJoy Rahman
- SKEW Hospital ReceptionUploaded byAvinash Potnuru
- Various Computational ModelsUploaded bygurusodhii
- Paper 2Uploaded bytareshsharma
- Discovering_Computer_Science_Interdiscip.pdfUploaded byPaul Divac
- MC116.pdfUploaded bysasidhar reddy kothapalli
- CS6711 Security Lab Manual (1)Uploaded byAathi Lin
- GENEREAL QA.odtUploaded byMary Jansi
- jhtp5_19Uploaded byErick Martinez
- Tb40laan SortUploaded byGilmer Calderon Quispe
- C interview questionsUploaded byJohn Walker
- Python Linked ListsUploaded byEisen Ed Briones
- 03-Lecture.pdfUploaded byinbasaat talha
- HpsUploaded byAfeefa
- Problem Set 1 GettingStartedUploaded byPhan.Huy.Cong

- Opencv BeginnersUploaded byRishabh Mehan
- Example Phd ProposalUploaded byTaimoor Shakeel
- Example Phd Proposal.pdfUploaded bycb67
- 901470_genetic22Uploaded byTaimoor Shakeel
- Transformer Less Power Supplies Resistive and CapacitiveUploaded bychatmar-thailand-3038
- Genetic AlgorithmsUploaded byluffydmon
- Job Ad for Data ScientistsUploaded byTaimoor Shakeel
- CS0213-Data structures and algorithms lab using c & c++ (1)Uploaded byTaimoor Shakeel
- qcf.pdfUploaded byJuan Bernardo Delgadillo Gallardo
- 09-kalman2Uploaded byTaimoor Shakeel
- On the Simulation of Quantum SystemsUploaded byTaimoor Shakeel
- 09 Genetic AlgorithmsUploaded byTaimoor Shakeel
- LAB 8 uc 2014Uploaded byTaimoor Shakeel
- cprogramminglevel1-140123053043-phpapp02Uploaded byTaimoor Shakeel
- GSMUploaded byTaimoor Shakeel
- 4thWCSQ1Uploaded byTaimoor Shakeel
- 04 JenniferUploaded byTaimoor Shakeel
- 0 CSEP 545 SyllabusUploaded byTaimoor Shakeel
- Lecture 3 COAUploaded byTaimoor Shakeel
- Coa Lab ProjectUploaded byTaimoor Shakeel
- COA Lab ProblemsUploaded byTaimoor Shakeel

- 208-ymb3Uploaded byoceanback1
- Unisoft GST India Questionnaire 20170227Uploaded bynagesh99
- 32388ff4472e92c17753e8689ac56ff85bc1Uploaded byAkhsan Ab GH
- D67234GC10_ag.pdfUploaded bycristian_master
- Online Exam system(shoyab siddiquee)End Term Project ReportUploaded byshoyab17
- vs1200Uploaded byLeandro Galarza
- QUIBELL, RAMESSEUM 1896Uploaded byFred Vink
- Howto InstrumentationUploaded byPavan Kalyan
- SNMP4J-Agent-1.4-InstrumentationGuideUploaded byshekhar_who
- Convert a PDF Into a Series of Images Using C# and GhostScriptUploaded bycafjnk
- Applicant ResumeUploaded bySaleh Ahmad
- Engine FlyerUploaded byPradip Jagadale
- Special Characters in BIUploaded byPrasad Raju
- NAVUploaded byelmer
- G4000 BrochureUploaded byunlockvn
- Cisco - Himawan Nugroho CCIE 8171 - How to Pass CCIE Lab - Insider TipsUploaded byjoejones555
- Solution GraphUploaded bydua_manas
- 12 Creating and Deploying Administrative TemplatesUploaded byAlexandreAntunes
- L06Uploaded byAliya Sarun
- Globe.pdfUploaded bymanguel1980
- Pharmaceutical and Software Development ProjectsUploaded byAlexandar123
- Nested VlansUploaded byericlmarxx
- Cisco Ios Router BenchmarkUploaded byapi-3726247
- DFC_53_SP_devUploaded byPrakash Ramalingam
- microsoftUploaded byprajanikanth1
- Thesis StrijkerUploaded byLina Lalouta Saadi
- VPN TroubleshootingUploaded bymyreza123
- Bsc Cbc IntegrationUploaded byAlex Andwanda
- Log Structured File SystemUploaded byPayal Sharma
- CAD - CAMUploaded byCad Camacademy