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

Data structures

Uploaded by

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

Data structures

Uploaded by

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

Savitribai Phule Pune University

S. Y. B. B. A. (C. A.) Semester-III


(CBCS 2019 Pattern)

Data Structure, Angular JS, PHP, Big


Data and Block Chain
CA-306: Lab Book

Student Name: ____________________________________________________

College Name: ____________________________________________________

Roll No.: ______________ Division: ____________ Seat No: _____________

Academic Year: ________________________________


CERTIFICATE

This is to certify that Mr./Ms.__________________________________

Seat Number ___________ of S.Y.B.B.A. (C.A) Sem-III has


successfully completed Laboratory course (Data structure, Angular
JS/PHP, Big Data/ Block Chain) in the year ____________________ .

He/She has scored _____mark out of 10 (For Lab Book).

Subject Teacher H.O.D./Coordinator

Internal Examiner External Examiner


Editorial Board: Dr. D. Y. Patil ACS College, Pimpri, Pune

Section-I: Data Structure


Mrs. Madhuri Darekar.
Mrs. Ashwini Patil.
Section-II: Angular JS
Mr. BhushanNikam.
Mr. Satish Mulgi.
Section-III: PHP
Ms. Neeta Takawale.
Mrs. Sunayna Shivthare.
Section-IV: Big Data
Mrs. Sonali Nemade.
Mr. Yogesh Ingale.
Section-V: Block Chain
Mrs. Malati Tribhuwan.
Mr. Satyavan Kunjir.
Reviewed By:
Dr. Ranjit Patil.
Mrs. Sujata Patil.
Mrs. Sangeeta Nimbalkar.
Mrs. Leena Bhat.
Mr. Sudarshan Lakhdive.
Mrs. Shakila Siddavatam.
Mr. Shivendu Bhushan.
Introduction

1. About the work book:

This workbook is intended to be used by S.Y.B.B.A. (C.A.) Semester-III students for


Data structure, Angular JS, PHP, Big data, Block chain Practical assignments. This
workbook is designed by considering all the practical topics mentioned in syllabus.

2. The objectives of this workbook are:

• Defining the scope of the course.


• To bring the uniformity in the practical conduction and implementation in all colleges
affiliated to SPPU.
• To have continuous assessment of the course and students.
• Providing ready reference for the students during practical implementation.
• Provide more options to students so that they can have good practice before facing the
examination.
• Catering to the demand of slow and fast learners and accordingly providing the
practice assignments to them.

3. How to use this workbook:

The workbook is divided into five sections. Section-I is related to Data Structure
assignments, Section-II is related to Angular JS assignments, Section-III is related to
PHP assignments, Section-IV is related to Big Data assignments and Section-V is
related to Block Chain assignments.
Section-I: Data Structure is divided into nine assignments.
Section-II: Angular JS is divided into assignments.
Section-III: PHP is divided into assignments.
Section-IV: Big Data divided into assignments
Section-V: Block Chain divided into assignments.
Students have to perform practical assignment of selected elective subject both from
Section-II or Section-III and from Section IV or Section V.
Each assignment of all sections has three SETs-A, B and C. It is mandatory for students
to complete SET A and SET B in lab. It also includes practice programs which are
expected to be solved by students as home assignments and to be evaluated by subject
teachers.

4. Instructions to the students

Please read the following instructions carefully and follow them during practical.
• Students are expected to carry this workbook every time they come to the lab for
computer practical.
• Students should prepare for the assignment by reading the relevant material which is
mentioned in ready reference and the concepts taught in class.
• Instructor will specify which problems to solve in the lab during the allotted slot and
student should complete them and get verified by the instructor. However, student
should spend additional hours in Lab and at home to cover all workbook assignments
if needed.
• Students will be assessed for each exercise on a scale from 0 to 5.

Notdone 0
Incomplete 1
Late Complete 2
Needs improvement 3
Complete 4
WellDone 5

5. Instruction to the Instructors

Make sure that students should follow above instructions.


• Explain the assignment and related concepts in around ten minutes using
whiteboard if required or by demonstrating the software.
• Evaluate each assignment carried out by a student on a scale of 5 as specified
above by ticking appropriate box.
• The value should also be entered on assignment completion page of the
respective Lab course.

6. Instructions to the Lab administrator

You have to ensure appropriate hardware and software is made available to each
student.
The operating system and software requirements on server side and also client side are
as given below:
• Operating System - Windows
• Turbo C
• Java script
• WampServer
• RStudio
Assignment Completion Sheet

Section-I: Data Structure


Sr. Assignment Name Marks Teacher’s
No. (out of 5) Sign
1 Array

2 Sorting Techniques (Non Recursive)

3 Sorting Techniques (Recursive)

4 Searching Techniques

5 Linked List

6 Stack

7 Queue

8 Trees

9 Graph

Total ( Out of 45 )

Total (Out of 4)

Instructor Signature:
Section-II: Angular JS
Sr. Assignment Name Marks Teacher’s
No. (out of 5) Sign
1 Introduction to Angular JS, AngularJS Directives ,
Expressions, Events
2 AngularJS Modules, Controller, View and Scope
3 Filter, Forms Validation

4 AngularJS Services

Total ( Out of 20 )

Total (Out of 3)

‘OR’

Section-III: PHP
Sr. Assignment Name Marks Teacher’s
No. (out of 5) Sign
1 Basics in PHP

2 Control Structures and Loops

3 Arrays and Strings

4 Functions, Class, and Object

5 Working With Form and form element

6 Session and Cookies

7 Database

Total ( Out of 35 )

Total (Out of 3)

Instructor Signature:
Section-IV: Big Data
Sr. No. Assignment Name Marks Teacher’s
(out of 5) Sign
1 Basic R Programming

2 Decision making and loop control structures

3 Sting and Function in R Programming

4 Vector and List in R Programming

5 Array and Matrices in R Programming

6 Factor and Data Frame in R Programming

7
Data Analysis
8
Data Visualization

Total ( Out of 40 )

Total (Out of 3)
‘OR’
Section-V: Block Chain
Sr. No. Assignment Name Marks Teacher’s
(out of 5) Sign

1 Working with Blockchain

Implementation of Smart Contracts and


2
Hyperledger
Total ( Out of 10 )
Total (Out of 3)

Instructor Signature:
Section-I

Data Structure
Assignment No 1: Array (One Dimensional Array)
ARRAY
➢ An array is a finite ordered collection of homogeneous data elements which provide
random access to the elements.
Finite: - There are specific no. of elements in the array.
Ordered: - The elements are arranged one by one i.e. first then second and so on.
Homogeneous: - All the elements are of same type.

WHAT IS POYNOMIAL
➢ A polynomial p(x) is the expression in variable x which is in the form (axn + bxn-1 + …. +
jx+ k), where a, b, c …., k fall in the category of real numbers and 'n' is non negative
integer, which is called the degree of polynomial.
➢ An essential characteristic of the polynomial is that each term in the polynomial
expression consists of two parts:
• one is the coefficient
• other is the exponent

EXAMPLE:
➢ 10x2 + 26x, here 10 and 26 are coefficients and 2, 1 is its exponential value.

Practice Program:
1) Write a menu driven C program to perform the following operation on an integer array:
a) Display the sum of elements at even subscript position of array
b) Display the sum of elements at odd subscript position of array
2) Write a C Program to find the largest pair sum in an unsorted array.(hint: find 2 maximum
elements from array and then find the sum of both numbers.)
3) Write a C Program to calculate Median of two sorted arrays of different sizes.

SET A:
1) Write a C Program to Count number of occurrences (or frequency) in a given sorted array

Input: arr[] = {1, 1, 2, 2, 2, 2, 3,}, x = 2


Output: 4 // x (or 2) occurs 4 times in arr[]
2) Write a C program to accept n elements, store those elements in array and store the square
of these numbers in another array and display both the array.
3) Write a C program to Copy one array into another array.

SET B:
1) Write a C program accept the polynomial and display it in format e.g. 6x^4+2x^2+5x^1+3
2) Write a ‘C’ program to accept n elements store those elements in array and find and replace
a given number.
3) Write a ‘C’ program to accept two polynomials and find the addition of accepted
polynomials.

1
SET C:
1) Write a ‘C’ program to accept two polynomials and find the Multiplication of accepted
polynomials.

Assignment Evaluation

0: Not Done [ ] 1: Incomplete [ ] 2: Late Complete [ ]


3: Needs Improvement [ ] 4: Complete [ ] 5: Well Done [ ]

Signature of Instructor

2
Assignment No 2: Sorting Techniques (Non Recursive)
SORTING
➢ Sorting means arranging a set of data in some given order or ordering a list of items.
‘Or’
Sorting is a process of ordering a list of elements in either ascending or descending
order.
➢ List is a collection of record each contains one or more fields. The field which contains
unique value for each record is called key field.
➢ Definition:-
Sorting is the operation of arranging the records of a table according to the key value of
each record
e.g. consider a telephone directory which consists of 4 field phone number, name,
address, pin code .
So a large data is maintained in the form of records. If we want to search a phone no
and name it should be alphabetically sorted then we can search easily. It would be very
difficult if records were unsorted.
➢ The sorting algorithm are divided into two categories
1) Internal sorting-
Sorting is done on data which is sorted in main memory.
2) External sorting –
Sorting is done on data which is stored on auxiliary storage device.
e.g. hard disk, floppy, tape etc.

• BUBBLE SORT
➢ This is one of the simplest and most popular sorting methods. The basic idea is to pass
through the file sequentially several times.
➢ In each pass we compare successive pairs of elements(x[i] with x[i+1]) and interchange
the two if they are not in the required order.
➢ One element is placed in its correct position in each pass.
➢ In first pass, the largest element will sink to the bottom, second largest in the second
pass and so on. Thus a total of n-1 passes are required to sort n keys
➢ Time Complexity: Base Case: O(n), Worst Case: O(n2 ), Average Case: O(n2 )

Algorithm for Bubble sort:


Step1: Start
Step2: Accept ‘n’ numbers in array ‘A’
Step3: set i=0
Step4: set j=0
Step5: if j<n-i-1 then go to next stepelse go to step 8
Step 6: if i A[j+1] then interchange A[j] and A[j+1]
Step7: j=j+1 and goto step 5
Step8: i=i+1 and goto step 4
Step9:Stop

3
• INSERTION SORT
➢ Insertion sort inserts each item into its proper place in the final list
➢ In this the first iteration starts with comparison of 1st element with 0th
➢ In second iteration 2nd element is compared with the 0th and 1st element and so on.
➢ In every iteration an element is compared with all elements
➢ The basic idea of this method is to place an unsorted element into its correct position in
a growing sorted list of data. We select one element from the unsorted data at a time
and insert it into its correct position in the sorted set.
➢ E.g. in order to arrange playing cards we pick one card at a time and insert this card
hold in the hand.
➢ Time Complexity: Base Case: O(n) Worst Case: O(n2 ) Average Case: O(n2 )

Algorithm for Insertion Sort:


Step1: Start
Step2: Accept ‘n’ numbers and store all in array ‘A’
Step3: set i=1
Step4: if i<=n-1 then goto next step else goto step 10
Step5: set Temp=A[i] and j=i-1
Step6: if Temp < A[j] && j>=0 then goto next step else goto step 9
Step7: set A[j+1]=A[j]
Step8: set j=j-1
Step9: set A[j+1]=Temp
Step10: Stop

• SELECTION SORT
➢ It is also called pushdown sort.
➢ In this the largest or smallest element is selected by placing it repeatedly till it reaches
its proper position.
➢ The 0th element is compared with all other elements, if the 0th is found to be greater
than the compared element then they are interchanged . In this way after first iteration
the smallest element is placed at 0th position. The Procedure is repeated for 1st element
and so on.
➢ It is Simple to implement.
➢ The main advantage is that data movement is very less
➢ It is not stable so. It is an in-place sort
➢ Time Complexity: Base Case: O(n2 ) Worst Case: O(n2 ) Average Case: O(n2 )

Algorithm for Selection Sort


Step1: Start
Step2: Accept ‘n’ numbers and store all in array ‘A’
Step3: set i=0
Step4: if i <n-1 then goto next step else goto step 11
Step5: set min=i and j=i+1

4
Step6: if j< n then goto next step else goto step 9
Step7: if A[j]< A[min] then min=j
Step8: set j=j+1 and goto step 7
Step9: if(min not equal to i) then interchange A[i] and A[min]
Step10: i=i+1 and goto step 4
Step11: Stop
Practice Programs:
1) Write a C program to create a integer array with elements {56,23,11,67,12,89,2} and sort
the given array using bubble sort.
2) Write a C program to sort a random array of n integers (value of n accepted from user) by
using Bubble Sort / Insertion Sort algorithm in ascending order.
3) Write a C program to create a string array with 5 elements which contains word starting
with vowel and sort them using Selection sort.

SET A:
1) Write a C program to accept and sort n elements in ascending order by using bubble sort.
2) Write a C program to accept and sort n elements in ascending order by using insertion sort.
3) Write a ‘C’ program to accept and sort n elements in ascending order using Selection sort
method.
SET B:
1) Write a C program to create a string array with day of week and sort them using Insertion
sort.
2) Write a ‘C’ program to accept names from the user and sort in alphabetical order using
bubble sort.
3) Write a C program to accept and sort n elements in ascending order by using bubble sort
and also count the number of swaps. Display the sorted list and total no of swap count.

SET C:
1) Write a C program to read the data from the file “employee.txt” which contains empno and
empname and sort the data on names alphabetically (use strcmp) using Bubble Sort.
2) Write a C program to read the data from the file “person.txt” which contains personno and
personage and sort the data on age in ascending order using insertion Sort / Selection Sort.
3) Modify the bubble sort, insertion sort and selection sort program of Set A to sort the
integers in descending order?

Assignment Evaluation

0: Not Done [ ] 1: Incomplete [ ] 2: Late Complete [ ]


3: Needs Improvement [ ] 4: Complete [ ] 5: Well Done [ ]

Signature of Instructor

5
Assignment No 3: Sorting Techniques (Recursive)
QUICK SORT
➢ It is also called “partition Exchange sort. The strategy used here is “divide and
conquer” i.e we successively partition the list in smaller lists and apply the same
procedure to the sub-list. The procedure is as follows:-
Procedure –
➢ We will consider one element at a time (pivot) and place it in its correct position.
➢ The pivot is placed in a position such that all elements to the left of the pivot are less
than the pivot and all elements to the right are greater.
➢ The array is partitioned into two parts:- left partition and right partition.
➢ The same method is applied for each of the partition.
➢ The process continues till no more partition can be made. We shall be considering the
first element of the partition as the pivot element.

Algorithm:
Step 1: start.
Step 2: A is an array of n element.
Step 3: lb=0 lb = lower bound
ub = n-1 ub = upper bound.
Step 4: if(lb<ub)
i.e. if the array can be partitioned
j=partition(A,lb,ub) // j is the pivot position

quicksort(A,lb,j-1);
quicksort(A,j+1,ub);

➢ Now, we must write the function to partition the array. There are many methods to do the
partitioning depending upon which element is chosen as the pivot.
➢ We will be selecting the first element as the pivot element and do the partitioning
accordingly.
➢ We shall choose the first element of the sub- array as the pivot and find its correct position
in the sub- array.
➢ We will be using two variables down and up for moving down and up array.

Algorithm for partitioning


Step 1: down=lb+1
Step 2: up=ub
Step 3: pivot=A[lb]
Step 4: perform step 5 to 7 as long as down<up else go to step 8.
Step 5: while (A[down]<=pivot && down<ub) down++;
Step 6: while (A[up]>pivot) up--;
Step 7: if (down<up) interchange A[down] and A[up]
Step 8: interchange A[up] and pivot, j=up, i.e. pivot position=up

6
Step 9: return up
Step 10: stop.

➢ In this algorithm we want to find the position of pivot i.e. A[lb].


➢ We use two pointers up and down initialized to the first and last elements respectively.
➢ We repeatedly increase down as long as the element is < pivot.
➢ We repeatedly decrease up as long as the element is > pivot.
➢ If up and down cross each other i.e. up<=down, the correct position of the pivot is up and
A[up and pivot are interchanged.
➢ If up and down do not cross A[up] and A[down] are interchanged and process is repeated
till they do not cross or coincide.
➢ Efficiency of quick sort.
Best case = average case = O(nlogn)
Worst case = O(n2)

MERGE SORT.
➢ Merging is the process of combining two or more sorted data lists into a third list such
that it is also sorted.
➢ Merge sort follows Divide and Conquer strategy.
- Divide :- divide an n element sequence into n/2 subsequence.
- Conquer :- sort the two sequences recursively.
- Combine :- merge the two sorted sequence into a single sequence.
➢ In this two list are compared and the smallest element is stored in the third array.
Algorithm:-
Step 1: start
Step 2: initially the data is considered as a single array of n element .
Step 3: divide the array into n/2 sub-array each of length 2i (I is 0 for 0th iteration). i.e. array is
divided into n sub-arrays each of 1 element.
Step 4: merge two consecutive pairs of sub-arrays such that the resulting sub-array is also
sorted.
Step 5: The sub-array having no pairs is carried a sit is
Step 6: step 3 and 4 are repeated till there is only one sub-array remaining of size n.
Step 7: stop.

Practice Programs:
1) Write a C program to create a integer array with elements {888,111,666,444,222,999,333}
and sort the given array using Merge sort.
2) Write a C program to sort a random array of n integers (value of n is accepted from user)
by using quick Sort algorithm in ascending order.
3) Write a C program to sort a random array of n integers (value of n accepted from user) by
using merge Sort algorithm in ascending order

SET A:
1) Write a C program to accept and sort n elements in ascending order by using merge sort.
2) Write a C program to accept and sort n elements in ascending order by using quick sort.

7
3) Modify the Quick sort program of SET A to sort the integers in descending order?

SET B:
1) Write a C program to create a string array with months (accept atleast 6 month) and sort
them using Quick sort.
2) Write a C program to create a string array with atlaest 5 elements which contains word
ending with ‘at’ and ‘an’ sound and sort them using Merge sort.
3) Modify the Merge sort program of Set B to sort the integers in descending order?

SET C:
1) Write a C program to read the data from the file “person.txt” which contains personno,
name and personage and sort the data on age in ascending order using merge Sort.
2) Write a C program to read the data from the file “student.txt” which contains rollno, name
and age and sort the data on age in ascending order using quick Sort.
3) Read the data from the file student.txt and sort on names in alphabetical order (use strcmp)
using Merge sort / Quick sort. Write the sorted data to another file 'sortstudentname.txt'.

Assignment Evaluation

0: Not Done [ ] 1: Incomplete [ ] 2: Late Complete [ ]


3: Needs Improvement [ ] 4: Complete [ ] 5: Well Done [ ]

Signature of Instructor

8
Assignment No 4: Searching Techniques
Searching is the process of finding a value in a list of values. The commonly used searching
methods used are linear search and Binary search.

LINEAR SEARCH
➢ In Linear search, we search an element or value in a given array by traversing the array
from the starting, till the desired element or value is found.
➢ Time Complexity: Base Case: O(1) Worst Case: O(n) Average Case: O(n)

Algorithm for Linear Search:


Step 1: Start
Step 2: Accept n numbers in an array num and a number to be searched
Step 3: set i=0 and flag=0
Step 4: if i< n the goto next step else goto
Step 5: Compare num[i] and number If equal then set flag=1 and goto step 7
Step 6: i=i+1 and goto step 4
Step 7: if (flag=1) then Print “Required number is found at location i+1” else Print “Require data
not found”
Step 8: Stop
BINARY SEARCH
➢ Binary Search is used with sorted array or list. So a necessary condition for Binary search
to work is that the list/array should be sorted. It works by repeatedly dividing in half the
portion of the list that could contain the item.
➢ Time Complexity: Base Case: O(1) Worst Case: O(log n) Average Case: O(log n)

Algorithm for Binary search:


Step 1: Start
Step 2: Accept n numbers in an array num and a number to be searched
Step 3: set low=0, high=n-1 and flag=0
Step 4: if low <= high then middle=(low+high)/2 else goto step 7.
Step 5: if (num[middle]=number) position=middle, flag=1 goto step 7. else if (number<
num[middle]) high=middle-1 else low=middle+1
Step 6: goto step 4
Step 7: if flag=1 Print “Required number is found at location position+1” Else Print “Required
number is not found.
Step 8: Stop

Practice Programs:
1) Write a C program to linearly search an element in a given array. (Use Recursion).
2) Read the data from file ‘employee.txt’ containing names of n employees, their qualification
and salary. Accept a name of the employee from the user and by using linear search
algorithm check whether the name of employee is present in the file or not if present
display salary of that employee, otherwise display “Employee not found”.

9
3) Read the data from file ‘player.txt’ containing names of n Player, their game_played and
age. Accept a name of the player from the user and by using binary search algorithm check
whether the name of player is present in the file or not if present display game_played and
age of that player, otherwise display “player not found”.

SET A:
1) Write a C program to accept n elements from user store it in an array. Accept a value from
the user and use linear/Sequential search method to check whether the value is present in
array or not. Display proper message.
2) Write a C program to accept n elements from user store it in an array. Accept a value from
the user and use binary search method to check whether the value is present in array or not.
Display proper message. (Students should accept sorted array and use Recursive function).
3) Write a ‘C’ program to create a random array of n integers. Accept a value of n from user
and use Binary search algorithm to check whether the number is present in array or not.
(Students should accept sorted array and use Non-Recursive function also use random
function).

SET B:
1) Write a ‘C’ program to accept the names of cities and store them in array. Accept the city
name from user and use linear search algorithm to check whether the city is present in array
or not.
2) Write a C program to accept n elements from user store it in an array. Accept a value from
the user and use recursive binary search method to check whether the value is present in
array or not. Display proper message. (use any sorting method to sort the array)
3) Read the data from file ‘sortedcities.txt’ containing sorted names of n cities and their STD
codes. Accept a name of the city from user and use linear search algorithm to check
whether the name is present in the file and output the STD code, otherwise output “city not
in the list”.

SET C:

1) Write a C program to read the data from file 'cities.txt' containing names of 10 cities and
their STD codes. Accept a name of the city from user and use Binary search algorithm to
check whether the name is present in the file and output the STD code, otherwise output
“city not in the list”.
2) Write a C program to read the data from file 'student.txt' containing names of 10 students
and their roll no. Accept a name of the student from user and use Binary search algorithm
to check whether the name is present in the file and output the roll no, otherwise output
“Student name not in the list”.

Assignment Evaluation

0: Not Done [ ] 1: Incomplete [ ] 2: Late Complete [ ]


3: Needs Improvement [ ] 4: Complete [ ] 5: Well Done [ ]

Signature of Instructor

10
Assignment No 5: Linked List

• Linked list:-
A linked list is an ordered collection of items which is dynamic in nature i.e. its size varies and
each item is ‘linked” or connected to another item. It is a linear collection of data elements
called nodes.

• LINKED LIST IMPLEMENTATION-:


A linked list may be implemented in two ways:
1) Static representation
2) Dynamic representation.

1) Static representation:-
An array is used to store the elements of the list. The elements may not be stored in a
sequential order. The correct order can be stored in another array called “link”
The values in this array are pointers to elements in the disk array.

Data array Link array


0 Blue 0 4
1 Red 1 -1
2 2
3 Violet 3 0
4 Green 4 6
5 5
6 Orange 6 1

Data[3] = violet Link[3] = 0


Data[0] = Blue Link[0] = 4
Data[4] = Green Link[4] = 6
Data[6] = Orange Link[6] = 1
Data[1] = Red Link[1] = -1 list end

2) Dynamic Representation:-

➢ The static representation uses arrays which is a static data structure and has its own
limitations.
➢ A linked list is a dynamic data structure i.e. the size should increase and when elements are
deleted, its size should decrease.
➢ This cannot be possible using an array which uses static memory allocation i.e. memory is
allocated during compile time. Hence we have to use “dynamic memory allocation” where
memory can be allocated and de-allocated during run-time.
➢ Another way of storing a list in memory is by dynamically allocating memory for each
node and linking them by means of pointers since each node will be at random memory
location. We will need a pointer to store the address of the first node.

11
list=3
violet 0 Blue 4 Green 6 orange 1

red NULL

List is an external pointer which stores the address of the first node of the list.

• TYPES OF LINKED LIST

1) Singly Linked list


2) Circular linked list
3) Doubly linked list
4) Circular doubly linked list

Linked list

Linear Circular

Singly linked list Doubly linked list Singly linked list Doubly linked list

1) Linear linked list


In this list the elements are organized in a linear fashion and list terminates at some point
i.e. the last node contains a NULL pointer.

list
Data next Data next Data NULL
NULL
node node node

➢ Singly linked list-


Each node in this list contains only one pointer which points to the next node.
Data next

list
Data next Data next Data NULL
NULL

➢ Doubly linked list


Each node in this contains two pointers, one pointing to the previous node and the other
pointing to the next node. This list is used when traversing in both directions is required.
Prev data next

12
Prev data next Prev data next Prev data next
NULL 10 200 100 20 300 200 30 NULL
list NULL
100 200 300

2) Circular list

In this list, the last node does not contain a NULL pointer but points back to the first node
i.e. it contains the address of the first node. Each of these lists can be either a singly linked or a
doubly list.

Circular singly linked list


Data next Data next Data next

Prev data next

List

Circular doubly linked list

• OPERATIONS ON A LIST
The following are some of the basic list operations:-
1) Traversing a list:-
Visiting each node of the list is called traversal
2) Insertion:-
A node can be inserted at the beginning, end or in between two nodes of the list.
3) Deletion:-
Deletion from a list may be done either position-wise or element-wise
4) Display:-
Display each element of the list.
5) Searching:-
This process searches for a specific element in the list.
6) Reversing or inversion:-
This process reverses the order of nodes in the list
7) Concatenation:-
This process appends the nodes of the second list at the end of the first list i.e. it joins two
lists.
8) Computation of length:-
Count the total no. of nodes in the list
9) Creating a linked list
10) Intersection, union, difference.
13
Practice Programs:
1) Write a C Program to find largest element of doubly linked list.
2) Write a C Program to interchange the two adjacent nodes in given circular linked list.
3) Write C Program to find length of linked list without using recursion.
4) Write C Program to print alternative nodes in linked list using recursion.

SET A:
1) Write a C program to implement a singly linked list with Create and Display operation.
2) Write a C program to implement a Circular Singly linked list with Create and Display
operation.
3) Write a C program to implement a doubly linked list with Create and Display operation.
4) Write a C program to implement a Circular doubly linked list with Create and Display
operation
SET B:
1) Implement the following programs by adding the functions one by one in SET A(Question1)
i) To count total number of nodes and display the count.
ii) To insert node at the start.
iii) To reverse the Linked List and display both the list.
2) Write a Menu driven program in C to implement the following functions:
i) To search the number in the list. If the number is present display the Position of
node .If number not present print the message “Number not Found”
ii) To swap mth and nth element of linked list.
iii) To delete node from specific position of linked list.
3) Write a ‘C’ program to sort elements of a singly linked list in ascending order and display
the sorted List.
4) Write a ‘C’ program to create doubly link list and display nodes having odd value.
SET C:
1) Write a C program to find intersection of two singly linked lists.
2) Write a C program to divide a singly linked list into two almost equal size lists.
Assignment Evaluation

0: Not Done [ ] 1: Incomplete [ ] 2: Late Complete [ ]


3: Needs Improvement [ ] 4: Complete [ ] 5: Well Done [ ]

Signature of Instructor

14
Assignment No 6: Stack
A stack is an ordered collection of items into which items may be inserted and deleted from
one end called the top of the stack.
The stack operates in a LIFO (last in first out) manner. i.e. the element which is put in last is the
first to come out. That means it is possible to remove elements from stack in reverse order from the
insertion of elements into the stack.
The real life e.g. of the stack are stack of coins, stack of dishes etc. only the topmost plate can be
taken and any new plates has to be put at the top.
• PRIMITIVE OPERATIONS ON A STACK.
1) Create
2) Push
3) Pop
4) Isempty
5) Isfull
6) Peek

• STACK IMPLEMENTATION:-
The stack implementation can be done in two ways:-
1) Static implementation:-
➢ It can be achieved using arrays. Though it is very simple method it has few limitations.
➢ Once a size of an array is declared, its size cannot be modified during program execution.
➢ The vacant space of stack also occupies memory space.
➢ In both cases, if we store less argument than declared, memory is wasted and if we want to
store more elements than declared array cannot be expanded. It is suitable only when we
exactly know the number of elements to be stored.
➢ Operations on static stack:-
1) Declaring of a stack :-
A stack to be implemented using an array will require.
- An array of a fixed size.
- An integer called top which stored the index or position of the topmost element.
We can use a structure for the above purpose.
2) Creating a stack:-
This declaration only specifies the template. The actual stack can be declared as-
STACK s1;
3) initialize a stack:-
When a stack variable is declared the integer top has to be initialized to indicate an empty
stack. Since we are using an array the first element will occupy position 0. Hence to
indicate an empty stack top has to be initialized to -1
4) Checking whether stack is empty:-
An empty stack can be tested from the value contained in top. If top contains -1 it
indicates an empty stack.
5) Checking whether stack is full:-
If the value of top reaches the maximum array index i.e. MAX-1 no more elements can be
pushed into the stack.
6) The push operation:-

15
The element can be pushed into the stack only if it is not full. In such case the top has to be
incremented first and the element has to be put in this position.
7) The pop operation:
An element can be removed from the stack if it is not empty. The topmost element can be
removed after which top has to decremented
8) The peek operation:
It displays the topmost element of the stack without decrementing the top.
2) Dynamic implementation:-
➢ Pointers are used for implementation of stack. The linked list is an e.g. of this
implementation.
➢ The limitations noticed in static implementation can be removed using dynamic
implementation. The dynamic implementation is achieved using pointers.
➢ Using pointer implementation at runtime there is no restriction on the no. of elements. The
stack may be expandable.
➢ The memory is efficiently utilized with pointers.
➢ Memory is allocated only after element is pushed to the stack
➢ In static representation there is a limitation on the size of the array if less elements are
stored, memory will be wasted. To overcome the program the stack can be implemented
using linked list.
➢ In the linked organization
- The stack can grow to any size.
- We need not have prior knowledge of the number of elements.
➢ When an element is popped the memory can be freed. Thus memory is not unnecessary
occupied.
➢ Since random access to any element is not required in a stack, the linked representation is
preferred over the sequential organization.

Applications of Stack
1) Inter conversion between infix, postfix and prefix expression.
2) Evaluating the postfix expression.
3) Reversing a string.
4) Reversing each word of the string and many more

There are 3 notations for specifying the operands:-

1) Infix :- if the operator symbols are placed between the operands then the expression
is in the infix notation (a+b)*c
2) Postfix :- if the operator symbols are placed after its operands, then the expression is
in postfix notation. ab+c*
3) Prefix :- if the operator symbols are placed before its operands, then the expression is
in prefix notation. *+abc

16
Associativity and Precedence rule

Operator Precedence Associativity

{},[].() High L-R

^ exponent High R-L e.g. 3^2^2


=3^4=81

Mul/div *,/ Intermediate L-R

+,- Low L-R

EVALUATE POSTFIX EXPRESSION:

Algorithme
1) Scan the string from Left to right
2) If symbol = = digit then push symbol in the stack.
3) If symbol = = operator then pop 2 elements from stack
Put first pop element in operand2
Put second pop element in operand1
Evaluate the value (operand1 operator operand2) and put the evaluated answer
in result
4) Push the result in the stack
5) After all the symbol are finished from symbol column pop the last element from the stack
which will be the final result of the postfix expression

INFIX TO POSTFIX CONVERSION


Algorithm
1) Scan the string from left to right
2) If symbol = = opening bracket push in stack
3) If symbol = = closing bracket pop all the elements from stack till we get opening bracket,
pop the opening bracket also and then put the pop elements in the postfixstring leaving
opening bracket.
4) If symbol = = alphabet/ digit then put the symbol in postfixstring
5) If symbol = = operator check priority of top element in the stack.
If priority( top element)>= priority(symbol operator) then pop top element and put it in
postfixstring
If priority( top element)< priority(symbol operator) then push the symbol in the stack
6) Repeat steps 2-5 until infix expression is scanned.
7) Print the output i.e. postfixstring

INFIX TO PREFIX CONVERSION


Algorithm
1) Scan the string from right to left
2) If symbol = = Closing bracket push in stack

17
3) If symbol = = opening bracket pop all the elements from stack till we get opening bracket,
pop the closing bracket also and then put the pop elements in the Prefixstring leaving
closing bracket.
4) If symbol = = alphabet/ digit then put the symbol in Prefixstring
5) If symbol = = operator check priority of top element in the stack.
If priority( top element)> priority(symbol operator) then pop top element and put it in
Prefixstring
If priority( top element)<= priority(symbol operator) then push the symbol in the stack
6) Repeat steps 2-5 until infix expression is scanned.
7) Print the output i.e. print Prefixstring in reverse

STRING REVERSE AND CHECKING PALINDROME STRING:


A string of characters can be reversed by reading each character from a string starting from the
first index and pushing it on a stack. Once all the characters have been read, the characters can be
popped one at a time from the stack and then stored in the another string starting from the first
index.
Algorithm to reverse the string:
1) Read the string character by character.
2) Push every character into the stack of characters.
3) When string becomes empty pop every character from stack and attach to the new string.
Algorithm to check palindrome of string:
1) Read the string character by character.
2) Push every character into the stack of characters.
3) When string becomes empty pop every character from stack and attach to the new string.
4) Compare original and reversed string if it matches string is palindrome else it is not
palindrome

Practice Programs:
1) Let stack_ptr be a pointer to stack of integers and item be an integer variable.
Write function like Push, Pop, Initialize, Empty, and Full for doing the following tasks.
[You may declare additional variable in your functions in needed].
a. Return the top element of stack and leave the top element unchanged. If the stack is
empty, return INT_MAX.
b. Return the third element from the top of the stack, provided that the stack contains
at least three integers. If not, return INT_MAX. Leave the stack unchanged.
c. Return the bottom element of stack (or INT_MAX if stack empty), and leave the
stack unchanged.

2) Given an expression string exp, write a C program to examine whether the pairs and the
orders of “{“, “}”, “(“, “)”, “[“, “]” are correct in exp.
Example:
Input: exp = “[()]{}{[() ()]()}”
Output: Balanced

18
Input: exp = “[(])”
Output: Not Balanced
3) Write a C Program to solve Tower Of Hanoi Problem (Use Recursion).
4) Write a C Program to sort a stack using temporary stack.

SET A:
1) Write a C program to implement Static implementation of stack of integers with following
operation:
-Initialize(), push(), pop(), isempty(), isfull(), display()
2) Write a C program to implement Dynamic implementation of stack of integers with
following operation:
-Initialize(), push(), pop(), isempty(), display().
3) Write a C program to reverse each word of the string by using static and dynamic
implementation of stack.
Example: Input - This is an input string
Output – sihT si na tupni gnirts

SET B :
1) Write a ‘C’ program which accepts the string and check whether the string is Palindrome or
not using stack. (Use Static/Dynamic implementation of Stack).
2) Write a ‘C’ program to read a postfix expression, evaluate it and display the result. (Use
Static/Dynamic implementation of Stack).
3) Write a ‘C’ program to accept an infix expression, convert it into its equivalent postfix
expression and display the result. (Use Static/Dynamic implementation of Stack).

SET C:
1) Write a program to check whether the contents of two stacks are identical.
2) Write a program that copies the contents of one stack into another. The order of two stacks
must be identical.(Hint: Use a temporary stack to preserve the order).
3) Write a ‘C’ program to accept an infix expression, convert it into its equivalent prefix
expression and display the result. (Use Static/Dynamic implementation of Stack).

Assignment Evaluation

0: Not Done [ ] 1: Incomplete [ ] 2: Late Complete [ ]


3: Needs Improvement [ ] 4: Complete [ ] 5: Well Done [ ]

Signature of Instructor

19
Assignment No 7: Queue
A queue is an ordered collection of items from which items may be deleted from (or removed
from ) one end called the front and into which items may be inserted at the other end called rear.

➢ BASIC OPERATIONS ON QUEUE


1) Create:
Create a new queue. This operation creates an empty queue.
2) Add or insert:
Add an element to the queue. A new element can be added to the queue at
the rear.
3) Delete:
Remove an element from the queue. This operation removes the elements,
which is at the front of the queue. This operation can only be performed if the queue is
not empty.
The result of an illegal attempt to remove an element from an empty queue
is called underflow.
4) isempty:
Check whether a queue is empty. The operation return true if the queue
isempty and false otherwise
5) isfull:
Check whether a queue is full. The operation return true if the queue isfull and
false otherwise

➢ REPRESENTATION OF LINEAR QUEUES.


There are two ways to represent a queue in memory.
1) Static (using an array)
2) Dynamic (using an linked list)
1) Static implementation of queue
Static implementation or array representation of queue requires three
entities-
- An array to hold queue elements.
- A variable to hold the index of the front element.
- A variable to hold the index of the rear element.
The implementation of a queue using sequential representation is done by using
some size MAX and two integer variable front and rear. Initially front and rear is
set to -1. Whenever new element is added it is added from the rear and whenever an
element is to be removed from the front. The queue full condition is when rear
reaches to MAX - 1. Queue empty condition is when front is equal to rear.

2) Dynamic implementation of linear queue (using an linked list)


A queue can be considered as a list in which all insertions are made at one end called the
rear and all deletions from the other end from front.

20
A queue can be easily represented using a linked list. The front and rear will be two
pointers pointing to the first and last node respectively.

Practice Programs:

1) Write a C program to Implement Static implementation of circular queue of integers which


includes operation as: a) Initialize() b) insert() c) delete() d) isempty() e) isfull() f) display()
g) peek()
2) Write a C program to Implement Dynamic implementation of circular queue of integers
includes operation as : a)Initialize() b) insert() c)delete() d) isempty() e)display() f) peek()
3) Write a C Program to implement Deque using doubly linked list

SET A:
1) Write a C program to Implement Static implementation of Queue of integers with
following operation:
-Initialize(), insert(), delete(), isempty(), isfull(), display(), peek()

2) Write a program to reverse the elements of a queue (Use Static implementation of Queue)
SET B:
1) Write a C program to Implement Dynamic implementation of Queue of integers with
following operation:
-Initialize(), insert(), delete(), isempty(), display(), peek()

2) Write a program to reverse the elements of a queue (Use Dynamic implementation of


Queue)
3) Write a C program to Implement Static implementation of circular queue of integers with
following operation:
-Initialize(), insert(), delete(), isempty(), isfull(), display(), peek()
SET C:
1) Write a c program to simulate waiting list operations of railway reservation system.
2) Implement a priority of integers using a static implementation of the queue and
implementing the below two operations. Write a menu driven program
a) Add an element with its priority into the queue.
b) Delete an element from queue according to its priority.
3) A doubly ended queue allows additions and deletions from both the ends that is front and
rear. Initially additions from the front will not be possible. To avoid this situation, the array
can be treated as if it were circular. Implement a queue library (dstqueue.h) of integers
using a static implementation of the circular queue and implementing the nine operations :
1)init(Q), 2) isempty(Q) 3) isFull(Q) 4)getFront(Q), 5)getRear(Q), 6)addFront(Q,x),
7)deleteFront(Q) 8) addRear(Q,x) 9)deleteRear(Q)

Assignment Evaluation
0: Not Done [ ] 1: Incomplete [ ] 2: Late Complete [ ]
3: Needs Improvement [ ] 4: Complete [ ] 5: Well Done [ ]

Signature of Instructor

21
Assignment No 8: Tree
Definition of tree:-
A tree is a finite set of one or more nodes such that:- there is a specially designated node
called the root. The remaining nodes are partitioned into n>=0 disjoint sets T1……Tn
where each of these sets is a tree. T1…..Tn are called as sub-trees of the root.

Binary Search Tree (BST) is a tree in which all the nodes follow the below-mentioned properties-
• The value of the key of the left sub-tree is less than the value of its parent (root) node's key.
• The value of the key of the right sub-tree is greater than or equal to the value of its parent
(root) node's key.
• The left and right sub tree each must also be a binary search tree.
Thus, BST divides all its sub-trees into two segments; the left sub-tree and the right sub-tree and
can be defined as – left_subtree (keys) < node (key) ≤ right_subtree (keys)

The operations on binary search tree are


init (T) – creates an empty Binary search tree by initializing T to NULL
insert (T, x) – inserts the value x in the proper position in the Binary search tree
search (T, x) – searches if the value x is present in the search tree
inOrder (T) – displays the node using inorder traversal of binary search tree
postOrder (T) – displays the node using postorder traversal of binary search tree
preOrder (T) – displays the node using preorder traversal of binary search tree

Practice Programs:
1) Write a C program to find all the ancestors of a given node in a binary tree.
2) Write a C program to implement binary search tree so that it handles duplicate keys
properly. That is, if a key is already in the tree then the new value should replace the old
rather than adding another node with the same key.
3) Write a C program to create binary search tree of integers and perform following
operations using non- recursive functions
- Preorder traversal
- Inorder traversal
- Postorder traversal

SET A:
1) Write C programs to implement create and display operation for binary tree.
2) Write C programs to implement create and display operation for binary search tree.
3) Write a C Program to find the product of all leaf nodes of a binary tree

SET B:
1) Write a C Program to implement the following functions on Binary Search Tree
- To insert a new element in the tree.
- To search an element in tree and give the proper message.
2) Write a C Program to implement the following functions on Binary Search Tree
- To create mirror image of the tree.

22
- To count non-leaf nodes.
3) Write a C Program to implement the following functions on Binary Search Tree
- To count leaf nodes.
- To count total number of nodes.

SET C:
1) Write C programs to create and display the elements using Inorder traversal.
2) Write a C program to create binary search tree of integers and perform following operations: -
- Preorder traversal
- Postorder traversal

Assignment Evaluation

0: Not Done [ ] 1: Incomplete [ ] 2: Late Complete [ ]


3: Needs Improvement [ ] 4: Complete [ ] 5: WellDone [ ]

Signature of Instructor

23
Assignment No 9: Graph
A graph consists of a set of vertices and a set of edges. The two main ways of representing
graphs are adjacency matrix representation and adjacency list representation. In adjacency matrix
representation of a Graph with n vertices and e edges, a two dimensional nxn array , say a , is used
, with the property that a[i,j] equals 1 if there is an edge from i to j and a[i,j] equals 0 if there is no
edge from i to j.
In adjacency list representation of a graph with n vertices and e edges, there are n linked
lists, one list for each vertex in the graph.

The usual operations on graph are:


Indegree(i) – returns the indegree (the number of edges ending on) of the ith vertex
Outdegree(i) – returns the outdegree(the number of edges moving out) of the ith vertex
displayAdjMatrix – displays the adjacency matrix for the graph

Practice Programs:
1) Write a C Program to count the number of edges in an undirected graph.
2) Write a C Program to trace all the paths of a directed graph from the given source node to
the destination node .Given the adjacency representation of a directed graph, find all the
paths of the graph from source to destination.
3) Write a c program to find whether cycle in present in graph (use Directed graph)

SET A:
1) Write a C program to read a graph as adjacency matrix and display the adjacency matrix.
2) Write a C program to display total degree of each vertex.
3) Write a C program to display Indegree and outdgree degree of each vertex.

SET B:
1) Write a C program to convert adjacency matrix into adjacency list. Display the adjacency
list.
2) Write a C program to traverse graph by using BFS.
3) Write a C program to traverse graph by using DFS.

SET C:

1) Implement a program to read a graph as adjacency matrix. Find the transpose of the matrix
for display accepted adjacency Matrix and Adjacency Matrix and List of transpose of the
matrix.
Assignment Evaluation

0: Not Done [ ] 1: Incomplete [ ] 2: Late Complete [ ]


3: Needs Improvement [ ] 4: Complete [ ] 5: WellDone [ ]

Signature of Instructor

24

You might also like