0% found this document useful (0 votes)
140 views

EC8381 - Fundamentals of Data Structures in C Laboratory Manual - by LearnEngineering - in

The document outlines the syllabus for a course on fundamentals of data structures in C. The course objectives are to understand and implement basic and advanced data structures using C. The list of experiments includes programs involving arrays, strings, structures, pointers, dynamic memory allocation, and implementing various data structures like stacks, queues, trees, and searching/sorting algorithms like linear search, binary search, and sorting algorithms. The course outcomes are to write basic and advanced C programs, implement functions and data structures in C, and choose appropriate sorting algorithms for applications.

Uploaded by

Angeline Jeba
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
140 views

EC8381 - Fundamentals of Data Structures in C Laboratory Manual - by LearnEngineering - in

The document outlines the syllabus for a course on fundamentals of data structures in C. The course objectives are to understand and implement basic and advanced data structures using C. The list of experiments includes programs involving arrays, strings, structures, pointers, dynamic memory allocation, and implementing various data structures like stacks, queues, trees, and searching/sorting algorithms like linear search, binary search, and sorting algorithms. The course outcomes are to write basic and advanced C programs, implement functions and data structures in C, and choose appropriate sorting algorithms for applications.

Uploaded by

Angeline Jeba
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 60

Visit For More : www.LearnEngineering.

in

EC8381 - FUNDAMENTALS OF DATA STRUCTURES IN C


SYLLABUS

COURSE OBJECTIVES

 To understand and implement basic data structures using C


 To apply linear and non-linear data structures in problem solving.
 To learn to implement functions and recursive functions by means of data structures
 To implement searching and sorting algorithms

n
LIST OF EXPERIMENTS:

g.i
1. Basic C Programs – looping, data manipulations, arrays

rin
2. Programs using strings – string function implementation
ee
3. Programs using structures and pointers
gin

4. Programs involving dynamic memory allocations

5. Array implementation of stacks and queues


En

6. Linked list implementation of stacks and queues


arn

7. Application of Stacks and Queues


Le

8. Implementation of Trees, Tree Traversals


w.

9. Implementation of Binary Search trees


ww

10. Implementation of Linear search and binary search

11. Implementation Insertion sort, Bubble sort, Quick sort and Merge Sort

12. Implementation Hash functions, collision resolution technique

Visit For More : www.LearnEngineering.in


Visit For More : www.LearnEngineering.in

COURSE OUTCOMES

 To Write basic and advanced programs in c.


 To Implement functions and recursive functions in c.
 To Implement data structures using c.
 To choose appropriate sorting algorithm for an application and implement it in a modularized
way.

n
g.i
rin
ee
gin
En
arn
Le
w.
ww

Visit For More : www.LearnEngineering.in


Visit For More : www.LearnEngineering.in

EC8381 - FUNDAMENTALS OF DATA STRUCTURES IN C


SYLLABUS

CONTENTS

Sl. No. Name of the Experiment Page No.

1 Basic C Programs – looping, data manipulations, arrays 7

Programs using strings – string function implementation 13


2

n
g.i
3 Programs using structures and pointers 15

Programs involving dynamic memory allocations

rin
4 20

5 Array implementation of stacks and queues


ee 22
6 Linked list implementation of stacks and queues 29
7 Application of Stacks and Queues 35
gin

8 Implementation of Trees, Tree Traversals 39


9 Implementation of Binary Search trees 41
En

10 Implementation of Linear search and binary search 46


Implementation Insertion sort, Bubble sort, Quick sort and Merge Sort
arn

11 50
Implementation Hash functions, collision resolution technique
12 58
Le
w.
ww

Visit For More : www.LearnEngineering.in


Visit For More : www.LearnEngineering.in

EXPT. NO. 1a BASIC C PROGRAM – LOOPING

Aim:

To write a C program to calculate the sum of first n natural numbers using for loop statements

Software requirements:
C compiler
Hardware requirements:

n
Server with supporting 30 terminals

g.i
Algorithm :

rin
1. Start the program.
2. Read the variables.
ee
3. The initialization statement is executed.
gin
4. The test expression is evaluated, if it is false for loop is terminated, test expression is true (nonzero),
codes inside the body of loop is executed and the update expression is updated.
5. This process repeats until the test expression is false.
En

6. Stop the program.


arn
Le
w.
ww

Visit For More : www.LearnEngineering.in


Visit For More : www.LearnEngineering.in

Output

Enter a positive integer: 10

Sum = 55

Result:

Thus the program to find the sum of n natural numbers was executed successfully.

n
g.i
rin
ee
gin
En
arn
Le
w.
ww

Visit For More : www.LearnEngineering.in


Visit For More : www.LearnEngineering.in

EXP 1 b. BASIC C PROGRAM – DATA MANIPULATIONS

Aim:
To write a C program for data manipulations using the bitwise operators

Software requirements:
C compiler
Hardware requirements:
Server with supporting 30 terminals

n
Algorithm :

g.i
1. Start the program.

rin
2. Declare the variables.
3. Use the required bitwise operators for the given input.
ee
4. Display the result.
gin
5. Stop the program.
En
arn
Le
w.
ww

Visit For More : www.LearnEngineering.in


Visit For More : www.LearnEngineering.in

Sample Output :

A = 10
B = 25
Bitwise AND operator & = 8

A = 10
B = 25
Bitwise OR operator | = 29

n
A= 10

g.i
B = 25
Bitwise XOR (exclusive OR) operator ^ = 21

rin
ee
complement = ~35
complement = ~-12
gin

complement = -36
Output = 11
En

Shift Operator ( >> and <<)


Num = 212
arn

Right Shift by 0: 212


Right Shift by 1: 106
Right Shift by 2: 53
Le

Left Shift by 0: 212


Left Shift by 1: 424
w.

Left Shift by 2: 848

Result :
ww

Thus the program for data manipulations using the bitwise operators is executed successfully.

10

Visit For More : www.LearnEngineering.in


Visit For More : www.LearnEngineering.in

EXP 1 c BASIC C PROGRAM – ARRAYS

Aim:

To write a C program using Arrays

Software requirements:
C compiler
Hardware requirements:

n
Server with supporting 30 terminals

g.i
Algorithm :

rin
1. Start the program. ee
2. Declare the array and the variables required for the program.
3. Get the values .
gin

4. Perform the operation based on the program inputs.


5. Display the output.
En

6. Stop the program.


arn
Le
w.
ww

11

Visit For More : www.LearnEngineering.in


Visit For More : www.LearnEngineering.in

Sample Output :
Enter n: 5
Enter number1: 45
Enter number2: 35
Enter number3: 38
Enter number4: 31
Enter number5: 49

Average = 39
Result :

Thus the program using arrays is executed successfully.

n
g.i
Outcome :

Thus the basic c programs for looping, Data manipulations and arrays is attained.

 C language is used to creating computer application


rin
ee
 Used in writing embedded software
gin
 Firmware for various electronics ,industrial product which uses micro controller
 Developing verifications of software code ,simulator.
En

VIVA - VOCE
arn

1. What is Decision making and Branching ?

2. What are all the different types of control flow statements ?


Le

3. Mention the different types of looping statements.


w.

4. What is the difference between while and do while loop statement ?


ww

5. What is an operator ?

6. Mention the bitwise operators.

7. What is an array ?

8 What is the use of array ?

9. What is multi dimensional array ?

10. How to access the elements in the array.

12

Visit For More : www.LearnEngineering.in


Visit For More : www.LearnEngineering.in

EXP NO 2 : PROGRAMS USING STRINGS FUNCTION

AIM:

To write a c program to perform string manipulation function.

Software requirements:
C compiler
Hardware requirements:
Server with supporting 30 terminals

n
g.i
Algorithm :
1. Start the program.

2. Declare the variables.


rin
ee
3. Get the string by using gets() function.
gin

4. Call the required string manipulation function.

5. Display the results by using the puts() function.


En
arn
Le
w.
ww

13

Visit For More : www.LearnEngineering.in


Visit For More : www.LearnEngineering.in

Sample Output :

Enter string: String


Length of string = 6

Result :
Thus the program for string manipulation is executed successfully.
Outcome :
Thus the programs using strings- string function implementation is attained.

n
Applications:

g.i
 String are used in spell checker, spam filter, intrusion detection

VIVA - VOCE
rin
ee
gin

1. What is a function ?
2. Mention the types of function.
En

3. What is a character ?
4. What is a string ?
arn

5. Difference between character and string.


6. What are the different types of string handling functions are available.
7. Which header file is to be included while using the string functions.
Le

8. How to declare a string and character.


w.
ww

14

Visit For More : www.LearnEngineering.in


Visit For More : www.LearnEngineering.in

EXP NO 3 a : PROGRAMS USING POINTERS

Aim:

To write a c program to perform swapping operation using pointers.

Software requirements:
C compiler
Hardware requirements:

n
Server with supporting 30 terminals

g.i
Algorithm :

rin
1. Start the program.

2. Declare the pointer variables.


ee
3. Initialise the pointer variable with an appropriate address.
gin

4. If the content of the address stored in the pointer is required, the indirection operator * is used to
obtain the value.
En

5. Stop the program.


arn
Le
w.
ww

15

Visit For More : www.LearnEngineering.in


Visit For More : www.LearnEngineering.in

Sample Output :

Before Swapping : A = 10 B = 20

After Swapping : A = 20 B = 10

Result :

Thus the program to swap two numbers using pointers is executed successfully.

n
g.i
rin
ee
gin
En
arn
Le
w.
ww

16

Visit For More : www.LearnEngineering.in


Visit For More : www.LearnEngineering.in

EXP NO 3 b : PROGRAMS USING STRUCTURES

Aim:

To write a c program using structures.

Software Requirements:
C compiler
Hardware Requirements:

n
Server with supporting 30 terminals

g.i
Algorithm :

1. Start the program.


rin
ee
2. Declare the structure and mention the structure variables inside the structure.
gin
3. In the main program access the member of the structure using the dot operator.

4. Call the required functions inside the main function.


En

5. Display the output.


arn

6. Stop the program.


Le
w.
ww

17

Visit For More : www.LearnEngineering.in


Visit For More : www.LearnEngineering.in

Sample Output :

Enter No. of Employees : 2


Enter Employee Details
Enter Employee Id : 436
Enter Employee Name :Gopal
Enter Basic Salary : 10000
Enter Employee Details
Enter Employee Id : 463

n
Enter Employee Name :Rajesh
Enter Basic Salary : 22000

g.i
XYZ & Co. Payroll

rin
********************************************************************************
EmpId Name Basic HRA DA IT Gross Net Pay
ee
********************************************************************************
436 Gopal 10000 200.00 100.00 500.00 10300.00 9800.00
gin

463 Rajesh 22000 440.00 220.00 1100.00 22660.00 21560.00


********************************************************************************
En

Result :
arn

Thus the program using structure is executed successfully.

Outcome :
Le

Thus the programs using structures and pointers is attained.


w.

Applications:
ww

 The C pointer are used to track read /write position in files in Linux/Unix OS.

VIVA - VOCE

1. What is meant by pointers?


2. What is meant by structure?
3. What is the advantage of structure?
4. What is meant by address operator?

18

Visit For More : www.LearnEngineering.in


Visit For More : www.LearnEngineering.in

5. What are the usages of pointers?


6. Why you need pointers in C?
7. What is meant by referencing operator?
8. What are the ways to declare the structure?
9. What is meant by structure operator and arrow operator?
10.How to pass function to pointers?

n
g.i
rin
ee
gin
En
arn
Le
w.
ww

19

Visit For More : www.LearnEngineering.in


Visit For More : www.LearnEngineering.in

Expt. No. 4 PROGRAMS INVOLVING DYNAMIC MEMORY


ALLOCATION

Aim:
To write a c program to perform dynamic memory allocation.
Software requirements:

n
g.i
C compiler
Hardware requirements:

rin
Server with supporting 30 terminals
ee
Algorthim:
1. Start the program.
gin

2. Include the required header file for using the memory allocation function.
3. Declare the required variables for the program.
En

4. Cal the required Dynamic Memory Allocation function depending upon the program.
5. Display the result.
arn

6. Stop the program.


Le
w.
ww

20

Visit For More : www.LearnEngineering.in


Visit For More : www.LearnEngineering.in

Sample Output :
Enter integer value: 100
Enter character value: x
Enter float value: 123.45
Inputted value are: 100, x, 123.45

Result:
Thus the program to perform dynamic memory allocation is executed successfully.
Outcome:
Thus the programs involving dynamic memory allocations are attained.

n
Applications:

g.i
The memory allocation concepts are used in operating systems present in embedded

rin
software .
ee
1. What is memory allocation? VIVA - VOCE
gin
2. What is meant by dyanamic memory allocation?
3. Differentiate static memory allocation from dynamic memory allocation?
En

4. Give some examples for memory allocation?


5. What is the syntax for malloc()?
arn

6. What is difference between malloc() and realloc()?


7. What is the function of calloc()?
Le

8. What is meant by free() and what is the purpose of using free() fuction?
9.What is the significance of calloc()?
w.

10.What is syntax for calloc()?


ww

21

Visit For More : www.LearnEngineering.in


Visit For More : www.LearnEngineering.in

Expt. No. 5 a ARRAY IMPLEMENTATION OF STACK

Aim:

To write a C program to perform array implementation of stack.

Software Requirements:
C compiler
Hardware Requirements:
Server with supporting 30 terminals

n
g.i
Algorithm :

1. Start the program.

2.
rin
Include all the header files which are used in the program and define a
ee
constant 'SIZE' with specific value.
gin

3. Declare all the functions used in stack implementation.


En

4. Create a one dimensional array with fixed size (int stack[SIZE])


arn

5. Define a integer variable 'top' and initialize with '-1'. (int top = -1)

6. In main method display menu with list of operations and make suitable function calls to
Le

perform operation selected by the user on the stack.


w.

PUSH OPERATION
ww

1. Check whether stack is FULL. (top == SIZE-1)

2. If it is FULL, then display "Stack is FULL!!! Insertion is not possible!!!" and terminate
the function.

3. If it is NOT FULL, then increment top value by one (top++) and set stack[top] to value
(stack[top] = value).

POP OPERATION
22

Visit For More : www.LearnEngineering.in


Visit For More : www.LearnEngineering.in

1. Check whether stack is EMPTY. (top == -1)

2. If it is EMPTY, then display "Stack is EMPTY!!! Deletion is not possible!!!" and


terminate the function.

3. If it is NOT EMPTY, then delete stack[top] and decrement top value by one (top--)

DISPLAY

n
1.Check whether stack is EMPTY. (top == -1)

g.i
2. If it is EMPTY, then display "Stack is EMPTY!!!" and terminate the function.

rin
3. If it is NOT EMPTY, then define a variable 'i' and initialize with top. Display stack[i] value
ee
and decrement i value by one (i--).
gin

4. Repeat above step until i value becomes '0'.


En
arn
Le
w.
ww

23

Visit For More : www.LearnEngineering.in


Visit For More : www.LearnEngineering.in

Sample Output :

STACK OPERATION
1.PUSH 2.POP 3.VIEW 4.QUIT Enter Choice : 1
Enter Stack element : 12

STACK OPERATION
1.PUSH 2.POP 3.VIEW 4.QUIT Enter Choice : 1
Enter Stack element : 23

STACK OPERATION

n
.PUSH 2.POP 3.VIEW 4.QUIT Enter Choice : 1

g.i
Enter Stack element : 34

STACK OPERATION

rin
1.PUSH 2.POP 3.VIEW 4.QUIT
Enter Choice : 1
ee
Enter Stack element : 45
gin
STACK OPERATION
1.PUSH 2.POP 3.VIEW 4.QUIT
Enter Choice : 3
En

Top--> 45 34 23 12
STACK OPERATION
arn

1.PUSH 2.POP 3.VIEW 4.QUIT


Enter Choice : 2
Le

Popped element is 45
STACK OPERATION
w.

1.PUSH 2.POP 3.VIEW 4.QUIT


Enter Choice : 3
ww

Top--> 34 23 12
STACK OPERATION
1.PUSH 2.POP 3.VIEW 4.QUIT
Enter Choice : 4

Result :
Thus the program for array implementation of stack is executed successfully.

24

Visit For More : www.LearnEngineering.in


Visit For More : www.LearnEngineering.in

Expt. No. 5 b ARRAY IMPLEMENTATION OF QUEUE

Aim:

To write a C program to perform array implementation of queue.

Software Requirements:
C compiler
Hardware Requirements:

n
Server with supporting 30 terminals

g.i
Algorithm :

rin
1. Start the program.
ee
2. Include all the header files which are used in the program and define a constant 'SIZE' with specific
gin
value.

3. Declare all the user defined functions which are used in queue implementation.
En

4. Create a one dimensional array with above defined SIZE (int queue[SIZE])
arn

5. Define two integer variables 'front' and 'rear' and initialize both with '-1'. (int front = -1, rear = -1)
Le

6. Then implement main method by displaying menu of operations list and make suitable function calls
to perform operation selected by the user on queue.
w.
ww

ENQUEUE OPERATION

1. Check whether queue is FULL. (rear == SIZE-1)

2. If it is FULL, then display "Queue is FULL!!! Insertion is not possible!!!" and terminate the
function.

3. If it is NOT FULL, then increment rear value by one (rear++) and set queue[rear] = value.
25

Visit For More : www.LearnEngineering.in


Visit For More : www.LearnEngineering.in

DEQUEUE OPERATION

1. Check whether queue is EMPTY. (front == rear)

2. If it is EMPTY, then display "Queue is EMPTY!!! Deletion is not possible!!!" and terminate the
function.

3. If it is NOT EMPTY, then increment the front value by one (front ++). Then display queue[front] as
deleted element. Then check whether both front and rear are equal (front == rear), if it TRUE, then set

n
both front and rear to '-1' (front = rear = -1).

g.i
DISPLAY OPERATION

1. Check whether queue is EMPTY. (front == rear)


rin
ee
2. If it is EMPTY, then display "Queue is EMPTY!!!" and terminate the function.
gin

3. If it is NOT EMPTY, then define an integer variable 'i' and set 'i = front+1'.
En

4. Display 'queue[i]' value and increment 'i' value by one (i++). Repeat the same until 'i' value is equal
arn

to rear (i <= rear)


Le
w.
ww

26

Visit For More : www.LearnEngineering.in


Visit For More : www.LearnEngineering.in

Sample Output :

QUEUE OPERATION
1.INSERT 2.DELETE 3.VIEW 4.QUIT Enter Choice : 1
Enter element to be inserted : 12

QUEUE OPERATION
1.INSERT 2.DELETE 3.VIEW 4.QUIT Enter Choice : 1

n
Enter element to be inserted : 23

g.i
QUEUE OPERATION

rin
1.INSERT 2.DELETE 3.VIEW 4.QUIT Enter Choice : 1
Enter element to be inserted : 34 ee
QUEUE OPERATION
1.INSERT 2.DELETE 3.VIEW 4.QUIT Enter Choice : 1
gin

Enter element to be inserted : 45

QUEUE OPERATION
En

1.INSERT 2.DELETE 3.VIEW 4.QUIT Enter Choice : 1


Enter element to be inserted : 56
arn

QUEUE OPERATION
1.INSERT 2.DELETE 3.VIEW 4.QUIT Enter Choice : 1
Le

Queue Full

QUEUE OPERATION
w.

1.INSERT 2.DELETE 3.VIEW 4.QUIT Enter Choice : 3


Front--> 12 23 34 45 56 <--Rear
ww

27

Visit For More : www.LearnEngineering.in


Visit For More : www.LearnEngineering.in

Result :

Thus the program for array implementation of Queue is executed successfully.

Outcome:

Thus the program for array implementation of stack and queue is attained.

VIVA - VOCE
1. What is meant by data structure?

n
2. What are the types of data structure?

g.i
3. What is meant by stack?
4. What is meant by queue?
5. State the working principle of stack and queue?
rin
ee
6. What is difference between stack and queue?
7. What are the function of stack and queue?
gin

8. What is the task of push and pop()?


9. Give some application of stack and queue?
En

10. What is stack overflow?


arn
Le
w.
ww

28

Visit For More : www.LearnEngineering.in


Visit For More : www.LearnEngineering.in

Expt. No. 6 a LINKED LIST IMPLEMENTATION OF


STACK

Aim:

To write a C program to perform Linked List implementation of stack.

Software Requirements:
C compiler
Hardware Requirements:

n
Server with supporting 30 terminals

g.i
rin
Algorithm :

1. Start the program.


ee
2. Include all the header files which are used in the program. And declare all the user defined
gin

functions.
En

3. Define a 'Node' structure with two members data and next.


arn

4. Define a Node pointer 'top' and set it to NULL.

5. Implement the main method by displaying Menu with list of operations and make suitable function
Le

calls in the main method.


w.

PUSH OPERATION
ww

1. Create a newNode with given value.

2. Check whether stack is Empty (top == NULL)

3. If it is Empty, then set newNode → next = NULL.

4. If it is Not Empty, then set newNode → next = top.

5. Finally, set top = newNode.

29

Visit For More : www.LearnEngineering.in


Visit For More : www.LearnEngineering.in

POP OPERATION

1. Check whether stack is Empty (top == NULL).

2. If it is Empty, then display "Stack is Empty!!! Deletion is not possible!!!" and terminate the
function

3. If it is Not Empty, then define a Node pointer 'temp' and set it to 'top'.

4. Then set 'top = top → next'.

n
g.i
5. Finally, delete 'temp' (free(temp)).

rin
DISPLAY OPERATION

1. Check whether stack is Empty (top == NULL).


ee
gin
2. If it is Empty, then display 'Stack is Empty!!!' and terminate the function.

3. If it is Not Empty, then define a Node pointer 'temp' and initialize with top.
En

4. Display 'temp → data --->' and move it to the next node. Repeat the same until temp reaches to the
arn

first node in the stack (temp → next != NULL).


Le

5. Finally! Display 'temp → data ---> NULL'.


w.
ww

30

Visit For More : www.LearnEngineering.in


Visit For More : www.LearnEngineering.in

Sample Output :

Stack using Linked List


1->Push 2->Pop 3->View 4->Exit Enter your choice : 1
Enter label for new node : 23 New node added
Stack using Linked List
1->Push 2->Pop 3->View 4->Exit Enter your choice : 1
Enter label for new node : 34

n
Stack using Linked List

g.i
1->Push 2->Pop 3->View 4->Exit Enter your choice : 3
HEAD -> 34 -> 23 -> NULL

rin
Result : ee
Thus the program for Linked List implementation of Stack is executed successfully.
gin
En
arn
Le
w.
ww

31

Visit For More : www.LearnEngineering.in


Visit For More : www.LearnEngineering.in

Expt. No. 6 b LINKED LIST IMPLEMENTATION OF QUEUE

Aim:

To write a C program to perform Linked List implementation of Queue.

Software Requirements:
C compiler
Hardware requirements:
Server with supporting 30 terminals

n
g.i
Algorithm :

rin
1. Start the program.
ee
2. Include all the header files which are used in the program. And declare all the user defined functions.
gin

3. Define a 'Node' structure with two members data and next.


En

4. Define two Node pointers 'front' and 'rear' and set both to NULL.
arn

5. Implement the main method by displaying Menu of list of operations and make suitable function calls
in the main method to perform user selected operation.
Le

enQueue OPERATION
w.

1. Create a newNode with given value and set 'newNode → next' to NULL.
ww

2. Check whether queue is Empty (rear == NULL)

3. If it is Empty then, set front = newNode and rear = newNode.

4. If it is Not Empty then, set rear → next = newNode and rear = newNode.

32

Visit For More : www.LearnEngineering.in


Visit For More : www.LearnEngineering.in

dEQueue OPERATION

1. Check whether queue is Empty (front == NULL).

2. If it is Empty, then display "Queue is Empty!!! Deletion is not possible!!!" and terminate from the
function

3. If it is Not Empty then, define a Node pointer 'temp' and set it to 'front'.

4. Then set 'front = front → next' and delete 'temp' (free(temp)).

n
g.i
DISPLAY OPERATION

1. Check whether queue is Empty (front == NULL).


rin
ee
2. If it is Empty then, display 'Queue is Empty!!!' and terminate the function.
gin

3. If it is Not Empty then, define a Node pointer 'temp' and initialize with front.
En

4. Display 'temp → data --->' and move it to the next node. Repeat the same until 'temp' reaches to
arn

'rear' (temp → next != NULL).

5. Finally! Display 'temp → data ---> NULL'.


Le
w.
ww

33

Visit For More : www.LearnEngineering.in


Visit For More : www.LearnEngineering.in

Sample Output

Queue using Linked List


1->Push 2->Pop 3->View 4->Exit Enter your choice : 1
Enter label for new node : 23 New node added
Stack using Linked List
1->Push 2->Pop 3->View 4->Exit Enter your choice : 1
Enter label for new node : 34
Stack using Linked List
1->Push 2->Pop 3->View 4->Exit Enter your choice : 3
HEAD -> 34 -> 23 -> NULL

n
g.i
rin
Result :

Thus the program for Linked List implementation of Queue is executed successfully.
ee
Outcome :
gin

Thus the program for Linked List implementation of stack and queue is attained.
En

Applications:
 Thread scheduler which maintains process in the memory .Linked list implementation is used
arn

move running process in queue which is used thread scheduler.

VIVA - VOCE
Le

1. What is the meant by linear data structure?


w.

2. What is meant by linked list?


3. What is stack implementation of linked list?
ww

4. What is meant by node?


5. What are the operations of stack in the linked list?
6. How to add the node and delete the node in the linked list using stack?
7. How to access the element from the stack in linked list?
8. What are the operations of queue using linked list?
9. How to allocate and deallocate the memory for linked list?
10. What is meant by singly linked list?

34

Visit For More : www.LearnEngineering.in


Visit For More : www.LearnEngineering.in

Expt. No. 7 a APPLICATION OF STACKS

Aim:

To write a C program to perform infix to postfix expression

Software Requirements:
C compiler
Hardware Requirements:

n
Server with supporting 30 terminals

g.i
Algorithm :

rin
1. Start the program.

2. Read all the symbols one by one from left to right in the given Infix Expression.
ee
3. If the reading symbol is operand, then directly print it to the result (Output).
gin

4. If the reading symbol is left parenthesis '(', then Push it on to the Stack.
En

5. If the reading symbol is right parenthesis ')', then Pop all the contents of stack until respective left
parenthesis is poped and print each poped symbol to the result.
arn

6. If the reading symbol is operator (+ , - , * , / etc.,), then Push it on to the Stack. However, first pop the
operators which are already on the stack that have higher or equal precedence than current operator
and print them to the result.
Le
w.
ww

35

Visit For More : www.LearnEngineering.in


Visit For More : www.LearnEngineering.in

Sample Output :

INFIX EXPRESSION : ( A + B ) * ( C - D )
POSTFIX EXPRESSION : A B + C D - *

Result :

Thus the program for performing infix expression to postfix expression is executed successfully.

n
g.i
rin
ee
gin
En
arn
Le
w.
ww

36

Visit For More : www.LearnEngineering.in


Visit For More : www.LearnEngineering.in

Expt. No. 7 b APPLICATION OF STACKS

Aim:

To write a C program to perform postfix to infix expression

Software Requirements:
C compiler
Hardware Requirements:

n
g.i
Server with supporting 30 terminals

rin
Algorithm :

1. Start the program.


ee
2. Read all the symbols one by one from left to right in the given Postfix Expression
gin

3. If the reading symbol is operand, then push it on to the Stack.


En

4. If the reading symbol is operator (+ , - , * , / etc.,), then perform TWO pop operations and store the
two popped oparands in two different variables (operand1 and operand2). Then perform reading
symbol operation using operand1 and operand2 and push result back on to the Stack.
arn

5. Finally! perform a pop operation and display the popped value as final result.
Le
w.
ww

37

Visit For More : www.LearnEngineering.in


Visit For More : www.LearnEngineering.in

Sample Output :

POSTFIX EXPRESSION : (5+3)*(8-2)


INFIX EXPRESSION : 53+82-*

Result :

Thus the program for performing postfix expression to infix expression is executed successfully.

n
g.i
Outcome :

Thus the program for application of stack and queue is attained.

Applications:
rin
ee
 In high level programming language, the arithmetic expressions are calculated. The stacks are
used to convert the expression which is understood by the computer.
gin
En

VIVA - VOCE
arn

1. What are the applications of stack?


2. What is meant by infix expression, Give example?
Le

3. Give some real application of stack?


w.

4. What is the procedure to evaluate the infix to postfix using stack?


5. Which data structure is needed to convert infix notation to postfix notation?
ww

6. What is the result of Top (Push (S, X))?


7. Whether Linked List is linear or Non-linear data structure?
8. What is linked list?
9. List out the types of linked list.
10. What is circular linked list?

38

Visit For More : www.LearnEngineering.in


Visit For More : www.LearnEngineering.in

Expt. No. 8 IMPLEMENTATION OF TREES, TREE


TRAVERSALS

Aim:

To write a C program for performing Binary Tree Traversal.

Software Requirements:
C compiler

n
g.i
Hardware Requirements:
Server with supporting 30 terminals

Algorithm :
rin
ee
1. Start the program.
gin

PREORDER TRAVERSAL
2. Process the root node (N).
En

3. Traverse the left subtree of N (L).


4. Traverse the right subtree of N (R).
arn

INORDER TRAVERSAL
Le

5. Traverse the left subtree of N (L).


6. Process the root node (N).
w.

7. Traverse the right subtree of N (R).


ww

POSTORDER TRAVERSAL
8. Traverse the left subtree of N (L).
9. Traverse the right subtree of N (R).
10. Process the root node (N).

39

Visit For More : www.LearnEngineering.in


Visit For More : www.LearnEngineering.in

Sample Output :

In order traversal sequence : I - D - J - B - F - A - G - K - C - H

n
Post order traversal sequence : I - J - D - F - B - K - G - H - C - A

g.i
Pre order traversal sequence : A - B - D - I - J - F - C - G - K - H

Result :
rin
ee
Thus the program for performing binary tree traversal is executed successfully.
gin

Outcome :
Thus the program for implementation of Trees, Tree Traversals is attained.
En
arn

Applications:
 Manipulate hierarchical data
 Manipulate sorted list of data
Le

 As a workflow for computing digital image for visual effects


w.
ww

40

Visit For More : www.LearnEngineering.in


Visit For More : www.LearnEngineering.in

Expt. No. 9 IMPLEMENTATION OF BINARY SEARCH


TREES

Aim:

To write a C program to performing Binary Search Tree Operations.

Software Requirements:

n
C compiler

g.i
Hardware Requirements:
Server with supporting 30 terminals

rin
Algorithm :
ee
1. Start the program.
gin

Search Operation in BST


En

2. Read the search element from the user


arn

3. Compare, the search element with the value of root node in the tree.
Le

4. If both are matching, then display "Given node found!!!" and terminate the function
w.

5. If both are not matching, then check whether search element is smaller or larger than that
node value.
ww

6. If search element is smaller, then continue the search process in left subtree.

7. If search element is larger, then continue the search process in right subtree.

8. Repeat the same until we found exact element or we completed with a leaf node

9. If we reach to the node with search value, then display "Element is found" and terminate
the function.
41

Visit For More : www.LearnEngineering.in


Visit For More : www.LearnEngineering.in

10. If we reach to a leaf node and it is also not matching, then display "Element not found"
and terminate the function.

Insertion Operation in BST

1. Create a newNode with given value and set its left and right to NULL.

2. Check whether tree is Empty.

3. If the tree is Empty, then set set root to newNode.

n
g.i
4. If the tree is Not Empty, then check whether value of newNode is smaller or larger than
the node (here it is root node).

rin
5. If newNode is smaller than or equal to the node, then move to its left child. If newNode
ee
is larger than the node, then move to its right child.
gin

6. Repeat the above step until we reach to a leaf node (e.i., reach to NULL).
En

7. After reaching a leaf node, then isert the newNode as left child if newNode is smaller or
equal to that leaf else insert it as right child.
arn

Deletion Operation in BST


Le

Case 1: Deleting a Leaf node (A node with no children)


w.

Case 2: Deleting a node with one child


ww

Case 3: Deleting a node with two children

Case 1: Deleting a leaf node

1. Find the node to be deleted using search operation

2. Delete the node using free function (If it is a leaf) and terminate the function.
42

Visit For More : www.LearnEngineering.in


Visit For More : www.LearnEngineering.in

Case 2: Deleting a node with one child

1. Find the node to be deleted using search operation

2. If it has only one child, then create a link between its parent and child nodes.

3. Delete the node using free function and terminate the function.

n
Case 3: Deleting a node with two children

g.i
1. Find the node to be deleted using search operation

rin
2. If it has two children, then find the largest node in its left subtree (OR)
ee
the smallest node in its right subtree.
gin

3. Swap both deleting node and node which found in above step.
En

4. Then, check whether deleting node came to case 1 or case 2 else goto steps 2

5. If it comes to case 1, then delete using case 1 logic.


arn

6. If it comes to case 2, then delete using case 2 logic.


Le

7. Repeat the same process until node is deleted from the tree.
w.
ww

43

Visit For More : www.LearnEngineering.in


Visit For More : www.LearnEngineering.in

Sample Output :

Select an option
1- insert.
2- Search.
3- Delete.
4 – Display.
5 - Exit

n
Enter your choice : 1

g.i
Enter the node value : 6

Enter your choice : 1

rin
Enter the node value : 1

Enter your choice : 1


ee
Enter the node value : 5
gin
Enter your choice : 1
Enter the node value : 2

Enter your choice : 1


En

Enter the node value : 4


arn

Enter your choice : 1


Enter the node value : 3

Select an option
Le

1- insert.
2- Search.
3- Delete.
w.

4 – Display.
5 - Exit
ww

Enter your choice : 4


1
2
3
4
5
6

44

Visit For More : www.LearnEngineering.in


Visit For More : www.LearnEngineering.in

Result :

Thus the program for performing Binary Search Tree Operations is executed successfully.

Outcome :

Thus the program for implementation of Binary Search Trees is attained.

Applications:

n
 Used in search application where data is constantly entered and stored

g.i
 Binary search partition used in 3D video game.
 Binary tries – Used in high bandwidth router for storing routing data.
 Syntax tree- Used for construction of compiler and calculator to parse expression

rin
ee
gin
En
arn
Le
w.
ww

45

Visit For More : www.LearnEngineering.in


Visit For More : www.LearnEngineering.in

Expt. No. 10 a IMPLEMENTATION OF LINEAR SEARCH

Aim:

To write a C program to perform Linear Search Operation.

Software Requirements:
C compiler

n
Hardware Requirements:

g.i
Server with supporting 30 terminals

rin
Algorithm :

1. Start the program.


ee
2. Read the search element from the user
gin

3. Compare, the search element with the first element in the list.
En

4. If both are matching, then display "Given element found!!!" and terminate the function
arn

5. If both are not matching, then compare search element with the next element in the list.
Le

6. Repeat steps 3 and 4 until the search element is compared with the last element in the list.
w.

7. If the last element in the list is also doesn't match, then display "Element not found!!!" and terminate
the function.
ww

46

Visit For More : www.LearnEngineering.in


Visit For More : www.LearnEngineering.in

Sample Output :

Enter number of elements : 7


Enter Array Elements :
23 6 12 5 0 32 10
Enter element to locate : 5
Element found at position 3

n
g.i
Result :

rin
Thus the program to perform Linear search operation is executed successfully.
ee
gin
En
arn
Le
w.
ww

47

Visit For More : www.LearnEngineering.in


Visit For More : www.LearnEngineering.in

Expt. No. 10 b IMPLEMENTATION OF BINARY SEARCH

Aim:

To write a C program to perform Binary Search Operation.

Algorithm :

n
1. Start the program.

g.i
2. Read the search element from the user

rin
3. Find the middle element in the sorted list ee
4. Compare, the search element with the middle element in the sorted list.
gin

5. If both are matching, then display "Given element found!!!" and terminate the function
En

6. If both are not matching, then check whether the search element is smaller or larger than middle
element.
arn

7. If the search element is smaller than middle element, then repeat steps 2, 3, 4 and 5 for the left
sublist of the middle element.
Le

8. If the search element is larger than middle element, then repeat steps 2, 3, 4 and 5 for the right
w.

sublist of the middle element.


ww

9. Repeat the same process until we find the search element in the list or until sublist contains only one
element.

10. If that element also doesn't match with the search element, then display "Element not found in the
list!!!" and terminate the function.

48

Visit For More : www.LearnEngineering.in


Visit For More : www.LearnEngineering.in

Sample Output :

Enter array size : 10


Elements in Sorted Order
0 2 4 6 8 10 12 14 16 18
Enter element to locate : 16
Found at index 8 in 2 attempts

n
g.i
Result :

rin
Thus the program to perform binary search operation is executed successfully.
ee
Outcome :
gin

Thus the implementation of Linear search and Binary search is attained.

Applications:
En

 Searching used in information retrieval.


arn
Le
w.
ww

49

Visit For More : www.LearnEngineering.in


Visit For More : www.LearnEngineering.in

Expt. No. 11 a IMPLEMENTATION OF INSERTION SORT

Aim:

To write a C program to perform Insertion Sorting.

Software Requirements:
C compiler

n
Hardware Requirements:

g.i
Server with supporting 30 terminals

rin
Algorithm : ee
1. Start the program.
gin

2. Asume that first element in the list is in sorted portion of the list and remaining all elements are in
unsorted portion.
En

3. Consider first element from the unsorted list and insert that element into the sorted list in order
arn

specified.

4. Repeat the above process until all the elements from the unsorted list are moved into the sorted list.
Le
w.
ww

50

Visit For More : www.LearnEngineering.in


Visit For More : www.LearnEngineering.in

Sample Output :

Enter total elements: 6


Enter array elements: 34 8 64 51 32 21
After Pass 1: 8 34 64 51 32 21
After Pass 2: 8 34 64 51 32 21

n
After Pass 3: 8 34 51 64 32 21
After Pass 4: 8 32 34 51 64 21

g.i
After Pass 5: 8 21 32 34 51 64
Sorted List : 8 21 32 34 51 64

Result :
rin
ee
Thus the program to perform insertion sort is executed successfully.
gin
En
arn
Le
w.
ww

51

Visit For More : www.LearnEngineering.in


Visit For More : www.LearnEngineering.in

Expt. No. 11 b IMPLEMENTATION OF BUBBLE SORT

Aim:

To write a C program to perform Bubble Sorting.

Software Requirements:
C compiler
Hardware Requirements:

n
Server with supporting 30 terminals

g.i
Algorithm :

rin
1. Start the program.

2. Set the size of the array and declare the variables.


ee
3. Repeat the steps 4 – 9 while i > 1
gin

4. set j=0.
En

5. Repeat steps 6 – 8 while j < i-1.

6. if arr[j] is greater than arr[j+1] goto step 7 else goto step 8.


arn

7. Swap the elements stored at arr[j] and arr[j+1] and perform the operations.
Le

8. set j=j + 1.

9. set i= i -1.
w.

10. stop.
ww

52

Visit For More : www.LearnEngineering.in


Visit For More : www.LearnEngineering.in

Sample Output :

Enter the number of elements in the array :


5

Enter the 5 elements to sort :


18
3
2
33
21

n
g.i
The sorted elements are :

rin
3
18
21
ee
33
gin
Result :

Thus the program to perform bubble sort is executed successfully.


En
arn
Le
w.
ww

53

Visit For More : www.LearnEngineering.in


Visit For More : www.LearnEngineering.in

Expt. No. 11 c IMPLEMENTATION OF QUICK SORT

Aim:

To write a C program to perform Quick Sorting.

Software Requirements:
C compiler
Hardware Requirements:

n
g.i
Server with supporting 30 terminals

rin
Algorithm :

1. Start the program.


ee
2. 1. If n < = 1, then return.
gin

2. Pick any element V in a[]. This is called the pivot.


En

3. Rearrange elements of the array by moving all elements xi > V right of V and all elements xi < = V
left of V. If the place of the V after re-arrangement is j, all elements with value less than V, appear in
a[0], a[1] . . . . a[j – 1] and all those with value greater than V appear in a[j + 1] . . . . a[n – 1].
arn

4. Apply quick sort recursively to a[0] . . . . a[j – 1] and to a[j + 1] . . . . a[n – 1].
Le

5. Stop the program.


w.
ww

54

Visit For More : www.LearnEngineering.in


Visit For More : www.LearnEngineering.in

Sample Output :

Enter the number of elements in the array :


6

Enter the 6 elements to sort :


34
99
5
2

n
57

g.i
40

The sorted elements are :

rin
2
5
ee
34
40
gin
57
99

Result :
En

Thus the program to perform Quick sort is executed successfully.


arn
Le
w.
ww

55

Visit For More : www.LearnEngineering.in


Visit For More : www.LearnEngineering.in

Expt. No. 11 d IMPLEMENTATION OF MERGE SORT

Aim:

To write a C program to perform Merge Sorting.

Algorithm :

1. Start the program.

n
2. Divide the unsorted list into N sublists, each containing 1 element.

g.i
3. Take adjacent pairs of two singleton lists and merge them to form a list of 2 elements. N will
now convert into N/2 lists of size 2.

rin
4. Repeat the process till a single sorted list of obtained.
ee
gin
En
arn
Le
w.
ww

56

Visit For More : www.LearnEngineering.in


Visit For More : www.LearnEngineering.in

Sample Output :
Enter the number of elements in the array :
8

Enter the 6 elements to sort :


34
99
5
2
57
40
8

n
29

g.i
The sorted elements are :

rin
2
5
8
ee
29
34
gin
40
57
99
En

Result :
arn

Thus the program to perform Merge sort is executed successfully.

Outcome :
Le

Thus the implementation of Insertion sort, Bubble sort, Quick sort, Merge sort is attained.
w.

Applications:
ww

 Merge sort – Merge sort are used in external database.


 Bubble Sort-Used in programming for TV remote application
 Heap sort –Used in reading bar codes in plastic cards
 Quick Sort –Sports scores are organized by quick sort.

57

Visit For More : www.LearnEngineering.in


Visit For More : www.LearnEngineering.in

Expt. No. 12 a IMPLEMENTATION OF HASH FUNCTION

Aim:

To write a C program to perform Hash Functions.

Software Requirements:
C compiler

n
Hardware Requirements:

g.i
Server with supporting 30 terminals

Algorithm :

1. Start the program.


rin
ee
2. Declare the variables.
gin

3. An element is converted into an integer by using a hash function. This element can be used as an
index to store the original element, which falls into the hash table.
En

4. The element is stored in the hash table where it can be quickly retrieved using hashed key.

hash = hashfunc(key)
arn

index = hash % array_size


Le
w.
ww

58

Visit For More : www.LearnEngineering.in


Visit For More : www.LearnEngineering.in

Sample Output :

Enter the next key : 10765

The hash key generarted for the key 10765 is 765.

Result :
Thus the program to perform hash function is executed successfully.

n
g.i
rin
ee
gin
En
arn
Le
w.
ww

59

Visit For More : www.LearnEngineering.in


Visit For More : www.LearnEngineering.in

Expt. No. 12 a COLLISION RESOLUTION TECHNIQUES

Aim:
To write a C program to perform Linear probing.

Software Requirements:
C compiler
Hardware Requirements:

n
Server with supporting 30 terminals

g.i
Algorithm :

rin
1. Start the program. ee
2. Create an array of structure (i.e a hash table).
gin
3. Take a key and a value to be stored in hash table as input.

4. Corresponding to the key, an index will be generated i.e every key is stored in a particular array
index.
En

5. Using the generated index, access the data located in that array index.
arn

6. In case of absence of data, create one and insert the data item (key and value) into it and increment
the size of hash table.
Le

7. In case the data exists, probe through the subsequent elements (looping back if necessary) for free
space to insert new data item.
Note: This probing will continue until we reach the same element again (from where we began probing)
w.

8. To display all the elements of hash table, element at each index is accessed (via for loop).
ww

9. To remove a key from hash table, we will first calculate its index and delete it if key matches, else
probe through elements until we find key or an empty space where not a single data has been entered
(means data does not exist in the hash table).

10. Exit

60

Visit For More : www.LearnEngineering.in


Visit For More : www.LearnEngineering.in

Sample Output :

MENU-:
1. Inserting item in the Hashtable
2. Removing item from the Hashtable
3. Check the size of Hashtable
4. Display Hashtable

Please enter your choice-: 3


Size of Hashtable is-: 0

Do you want to continue-:(press 1 for yes) 1


Implementation of Hash Table in C with Linear Probing

n
MENU-:

g.i
1. Inserting item in the Hashtable
2. Removing item from the Hashtable
3. Check the size of Hashtable

rin
4. Display Hashtable

Please enter your choice-: 1


ee
Inserting element in Hashtable
Enter key and value-: 12 10
gin

Key (12) has been inserted

Do you want to continue-:(press 1 for yes) 1


En

Implementation of Hash Table in C with Linear Probing


MENU-:
1. Inserting item in the Hashtable
arn

2. Removing item from the Hashtable


3. Check the size of Hashtable
4. Display Hashtable
Le

Please enter your choice-: 1


Inserting element in Hash table
w.

Enter key and value-: 122 4


ww

Key (122) has been inserted

Do you want to continue-:(press 1 for yes) 1


Implementation of Hash Table in C with Linear Probing
MENU-:
1. Inserting item in the Hashtable
2. Removing item from the Hashtable
3. Check the size of Hashtable
4. Display Hashtable

Please enter your choice-: 3


Size of Hashtable is-: 2

61

Visit For More : www.LearnEngineering.in


Visit For More : www.LearnEngineering.in

Do you want to continue-:(press 1 for yes) 1


Implementation of Hash Table in C with Linear Probing
MENU-:
1. Inserting item in the Hashtable
2. Removing item from the Hashtable
3. Check the size of Hashtable
4. Display Hashtable

Please enter your choice-: 4


Array[0] has no elements

Array[1] has no elements

n
Array[2] has elements-:
12 (key) and 10 (value)

g.i
Array[3] has elements-:

rin
122(key) and 5(value)

Array[4] has no elements


ee
Array[5] has no elements
gin

Array[6] has no elements

Array[7] has no elements


En

Array[8] has no elements


arn

Array[9] has no elements


Le

Do you want to continue-:(press 1 for yes) 1


Implementation of Hash Table in C with Linear Probing
MENU-:
w.

1. Inserting item in the Hashtable


2. Removing item from the Hashtable
3. Check the size of Hashtable
ww

4. Display Hashtable

Please enter your choice-: 2


Deleting in Hashtable
Enter the key to delete-: 122

Key (122) has been removed

Do you want to continue-:(press 1 for yes) 1


Implementation of Hash Table in C with Linear Probing
MENU-:
1. Inserting item in the Hashtable
62

Visit For More : www.LearnEngineering.in


Visit For More : www.LearnEngineering.in

2. Removing item from the Hashtable


3. Check the size of Hashtable
4. Display Hashtable

Please enter your choice-: 2


Deleting in Hashtable
Enter the key to delete-: 56

This key does not exist

Do you want to continue-:(press 1 for yes) 2

Result :

n
g.i
Thus the program to perform linear probing is executed successfully.

Outcome :

rin
Thus the implementation of Hash functions, collision resolution techniques is initiated.
ee
Applications:
gin

 Constructs a message Authentication code


 Used to construct digital signature
 Used in message digest as a cryptographic function
En

 Time stamping
arn
Le
w.
ww

63

Visit For More : www.LearnEngineering.in

You might also like