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

1st Module

The document outlines the syllabus for the Data Structure and Application course (BCS304) at Don Bosco Institute of Technology, covering various topics such as data structures, arrays, stacks, queues, linked lists, trees, graphs, and hashing over five modules. Each module includes specific teaching hours and references to textbooks and additional resources. It also provides an overview of data structure operations and memory management in C programming.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

1st Module

The document outlines the syllabus for the Data Structure and Application course (BCS304) at Don Bosco Institute of Technology, covering various topics such as data structures, arrays, stacks, queues, linked lists, trees, graphs, and hashing over five modules. Each module includes specific teaching hours and references to textbooks and additional resources. It also provides an overview of data structure operations and memory management in C programming.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 70

DON BOSCO INSTITUTE OF TECHNOLOGY

Kumbalagodu, Mysore Road, Bengaluru – 560074


Department of Information Science and Engineering
Syllabus
SUBJECT: DATA STRUCTURE AND APPLICATION SUBJECT CODE: BCS304
Topics Covered as per Syllabus Teaching Hours
MODULE-1: Introduction To Data Structures
INTRODUCTION TO DATA STRUCTURES: Data Structures, Classifications (Primitive & Non-
Primitive), Data structure Operations Review of pointers and dynamic Memory Allocation,
ARRAYS and STRUCTURES: Arrays, Dynamic Allocated Arrays, Structures and Unions,
Polynomials, Sparse Matrices, representation of Multidimensional Arrays, Strings 08 Hours
STACKS: Stacks, Stacks Using Dynamic Arrays, Evaluation and conversion of Expressions
Text Book: Chapter-1:1.2 Chapter-2: 2.1 to 2.7 Chapter-3: 3.1,3.2,3.6 Reference Book 1: 1.1 to 1.4
MODULE-2: Queues and Linked Lists
QUEUES: Queues, Circular Queues, Using Dynamic Arrays, Multiple Stacks and queues.
LINKED LISTS : Singly Linked, Lists and Chains, Representing Chains in C, Linked Stacks and
Queues, Polynomials 08 Hours
Text Book: Chapter-3: 3.3, 3.4, 3.7 Chapter-4: 4.1 to 4.4
MODULE -3:LINKED LIST (Cont.) and Trees
LINKED LISTS : Additional List Operations, Sparse Matrices, Doubly Linked List.
TREES: Introduction, Binary Trees, Binary Tree Traversals, Threaded Binary Trees. 08 Hours
Text Book: Chapter-4: 4.5,4.7,4.8 Chapter-5: 5.1 to 5.3, 5.5

MODULE-4:TREES (Cont.) and Graphs


TREES(Cont..): Binary Search trees, Selection Trees, Forests, Representation of Disjoint sets,
Counting Binary Trees,
GRAPHS: The Graph Abstract Data Types, Elementary Graph Operations 08 Hours
Text Book: Chapter-5: 5.7 to 5.11 Chapter-6: 6.1, 6.2
MODULE-5:Hashing, Priority Queues and BST
HASHING: Introduction, Static Hashing, Dynamic Hashing
PRIORITY QUEUES: Single and double ended Priority Queues, Leftist Trees 08 Hours
INTRODUCTION TO EFFICIENT BINARY SEARCH TREES: Optimal Binary Search Trees
Text Book: Chapter 8: 8.1 to 8.3 Chapter 9: 9.1, 9.2 Chapter 10: 10.1
List of Text Books
1. Ellis Horowitz, Sartaj Sahni and Susan Anderson-Freed, Fundamentals of Data Structures in C, 2nd Ed,
Universities Press, 2014
List of Reference Books
1. Seymour Lipschutz, Data Structures Schaum's Outlines, Revised 1st Ed, McGraw Hill, 2014.
2. Gilberg & Forouzan, Data Structures: A Pseudo-code approach with C, 2nd Ed, Cengage Learning,2014.
3. Reema Thareja, Data Structures using C, 3rd Ed, Oxford press, 2012.
4. Jean-Paul Tremblay & Paul G. Sorenson, An Introduction to Data Structures with Applications, 2nd Ed, McGraw
Hill, 2013
5. A M Tenenbaum, Data Structures using C, PHI, 1989
6. Robert Kruse, Data Structures and Program Design in C, 2nd Ed, PHI, 1996..
Web links and Video Lectures (e-Resources):
• http://elearning.vtu.ac.in/econtent/courses/video/CSE/06CS35.html
• https://nptel.ac.in/courses/106/105/106105171/
• http://www.nptelvideos.in/2012/11/data-structures-and-algorithms.html
• https://www.youtube.com/watch?v=3Xo6P_V-qns&t=201s
• https://ds2-iiith.vlabs.ac.in/exp/selection-sort/index.html
• https://nptel.ac.in/courses/106/102/106102064/
• https://ds1-iiith.vlabs.ac.in/exp/stacks-queues/index.html
• https://ds1-iiith.vlabs.ac.in/exp/linked-list/basics/overview.html
• https://ds1-iiith.vlabs.ac.in/List%20of%20experiments.html
• https://ds1-iiith.vlabs.ac.in/exp/tree-traversal/index.html
• https://ds1-iiith.vlabs.ac.in/exp/tree-traversal/depth-first-traversal/dft-practice.html
• https://infyspringboard.onwingspan.com/web/en/app/toc/lex_auth_013501595428077568125 59/overview
BCS304

Index

Module -1
Introduction
Teaching Hours: 08

CONTENTS
1. Introduction to Data Structures
1.1. Classification of Data Structures
1.2. Data structure Operations
1.3. Review on Pointers and Dynamic Memory Allocation
2. Arrays and Structures
2.1. Arrays, Dynamically Allocated Arrays
2.2. Structures and Unions, Polynomials, Sparse Matrices,
2.3. Representation of Multidimensional Arrays, Strings
3. Stacks
3.1 Stacks, Stacks Using Dynamic Arrays,
3.2 Evaluation and conversion of Expressions

Dept. of ISE, DBIT Page


1
BCS304

Chapter 1- Introduction to Data Structures

Data Structure is a specialized format of organizing and storing

Classification of Data Structures

Primitive data type and primitive data


A primitive data structure is the basic data types that are available in most of programming languages. The
primitive data types are used to represent the single value.
Eg: char, float ,double, int etc
char=’a’; int=10;

The data types that are derived from primitive data type are called non-primitive data types .These
data types are used to store group of values. Non-primitive data type is also called derived data types

Eg: arrays, pointers, structures, unions, Stacks, Queue, Linked List etc.

Dept. of ISE, DBIT Page


2
BCS304

1.1. Data structure Operations

The data appearing in our data structures are processed by means of certain operations

1. Traversing: Accessing each record exactly once so that certain items in the record maybe processed. (This accessing and
processing is sometimes called "visiting" the record).
2. Searching: Finding the location of the record with a given key value, or finding the locations of allrecords which satisfy
one or more conditions.
3. Inserting: Adding a new record to the structure.
4. Deleting: Removing a record from the structure.

The following two operations are used in special situations,


5. Sorting: Arranging the records in some logical order.
6. Merging: Combining the records of two different sorted files into a single sorted file.

1.2. Review on Pointers and Dynamic Memory Allocation

1. POINTERS
Pointers is a variable which hold the address of another variable

Declaration of pointer variable:


datatype *variable_name;
Eg: int *ip; /* pointer to an integer */
double *dp; /* pointer to a double*/
float *fp; /* pointer to a float */
char *ch /* pointer to a character */

Here, datatype is the basic datatype or user defined datatype.;


The asterisk * indicates variable name is a pointer variable
variable_name is the valid C identifier

Initialization of pointer variable:

Initialization of a pointer variable is the process of assigning the address of a variable to pointer variable
Eg: int a; /*interger variable a */
int *p; /*pointer variable p */
p=&a; /* address of a is assigned to p */
OR
int a; /*interger variable a */
int *p=&a; /* pointer variable p ,address of a is assigned to p* */

Dept. of ISE, DBIT Page


3
BCS304

2. Dynamic Memory Management Functions

Allocation of memory during run time or execution time is called dynamic memory allocation (DMA)

Different DMA functions used in C are as follows

malloc()
The name malloc stands for "memory allocation". The function malloc() reserves a s i n g l e block of memory
of specified size and return a pointer of type void which can be casted into pointer of any form. The prototype for this
function is available in <stdlib.h> and <alloc.h>

Syntax of malloc()
ptr=(cast-type*)malloc(byte-size)

Here, ptr is pointer variable of cast-type.


cast_type is any basic user defined data type
size is unsigned integer representing number of bytes to be allocated.
The malloc() function returns a pointer to an area of memory with size of byte size. If the space is insufficient,
allocation fails and returns NULL pointer.

Eg:ptr=(int*)malloc(100*sizeof(int));

This statement will allocate either 200bytes or 400bytes according to size of int 2 or 4 bytes respectively and the
pointer points to the address of first byte of memory.
calloc()
The name calloc stands for "contiguous allocation".
This function is used to allocate the memory during run time. The prototype for this function is available in
<stdlib.h> and <alloc.h>
The only difference between malloc() and calloc() is that, malloc() allocates single block of memory whereas
calloc() allocates multiple blocks of memory each of same size and sets all bytes to zero.

Syntax of calloc()

ptr=(cast-type*)calloc(n,element-size);

Here, ptr is pointer variable of cast-type.


element-size is unsigned integer representing the size of each element.
N is Number of blocks to be allocated
cast_type is any basic user defined data type

Dept. of ISE, DBIT Page


4
BCS304
For example: ptr=(float*)calloc(25,sizeof(float));

This statement allocates contiguous space in memory for an array of 25 elements each of size of float, i.e, 4
bytes.
realloc()
The name realloc stands for "reallocation".
If the previously allocated memory is insufficient or more than sufficient, then previously allocated memory size can
be changed by using realloc() function. The prototype for this function is available in <stdlib.h> and <alloc.h>

Syntax of realloc()
ptr=relloc(ptr,newsize);
Here ptr is pointer to a block of previously allocated memory either by using malloc() or calloc().
Newsize is new size of the block.
On Success it returns the address of first byte of allocated memory. On failure it return NULL

free()

This function is used to deallocate(or free) the allocated block of memory which is allocated dynamically by
using calloc() or malloc() or realloc().

syntax of free()

free(ptr);

Here ptr is a pointer variable pointing to the memory allocated dynamically.

Dept. of ISE, DBIT Page


5
BCS304

Chapter2- Arrays and Structures


Arrays
An array is a collection of similar type of data elements stored sequentially one after the other in memory.

Arrays are classified as two types:

1) One-dimensional arrays (Single dimensional arrays)


2) Multidimensional arrays

A Single dimensional array is a linear list consisting of related data items of same type.In memory ,all the data items are
stored in continuous memory locations one after the other.

Declaration Syntax of one-dimensional array

data_type array_name[size];

Here data_type specifies what kind of values an array can store such as int, float, char etc
array_name is the name to identify an array .
size specifies the maximum number of elements an array can store and it must be an integer(+ve).

For example: int age [5];

Total size =10 bytes

Suppose, the starting address of age[0] is 2120 and the size of int be 2 bytes. Then, the next address (address of
a[1]) will be 2122, address of a[2] will be 2124 and so on.

Initialization of one-dimensional array:

Syntax:
data_type array_name[size]={v1,v2,…..vn};

Here data_type specifies what kind of values an array can store such as int, float, char etc
array_name is the name to identify an array.
size specifies the maximum number of elements an array can store and it must be an integer(+ve).

v1,v2,…..vn are the list of values enclosed within {} and separated by comma.

Eg: 1) int age[5]={2,4,34,3,4};

Dept. of ISE, DBIT Page


6
BCS304

2) It is not necessary to define the size of arrays during

initialization. int age[]={2,4,34,3,4};

Accessing individual array elements of 1D (Single dimensional) array

For example: int a[5];

To access the 1st element a [0],2nd element a[1]……i.e using a[0] through

a[4] we can access 5 integers. In general, using a [0] through a[n-1] we can

access n data items.

Reading n elements (1D array)

int a[10] i , j , n=5; int a[10] i , j , n=5;


for(i=0;i<n;i++) for(i=0;i<=n-1;i++)
{ OR {
scanf(“%d”a[i]); scanf(“%d”a[i]);
} }

Display n elements (1D array)

int a[10] i , j , n=5; int a[10] i , j , n=5;


for(i=0;i<n;i++) for(i=0;i<=n-1;i++)
{ OR {
printf(“%d”a[i]); printf(“%d”a[i]);
} }

Example of array in C programming

/* C program to find the sum marks of n students using arrays */

#include <stdio.h>

Dept. of ISE, DBIT Page


7
BCS304
int main(){
int marks[10],i,n,sum=0;
printf("Enter number of students: ");
scanf("%d",&n);
for(i=0;i<n;++i){
printf("Enter marks of student%d: ",i+1);
scanf("%d",&marks[i]);
sum+=marks[i];
}
printf("Sum= %d",sum);
return 0;
}
Output
Enter number of students: 3
Enter marks of student1: 12
Enter marks of student2: 31
Enter marks of student3: 2
sum=45

Array with two or more dimensions are called multi-dimensional arrays.

An array with two dimensions are called two dimension array(or 2D

array).A 2D array is specified using two subscripts, where first subscript

denotes the row size and second subscript denotes the column size.

Declaration Syntax of two-dimensional array

data_type array_name[row size] [column size];

Here data_type specifies what kind of values an array can store such as int, float, char etc
array_name is the name to identify an array.
row size specifies the maximum number of rows in the array and column size specifies the maximum number of
columns in the array

For example: int a [4][3];

Dept. of ISE, DBIT Page


8
BCS304

Initialization of two-dimensional array:

Syntax:
data_type array_name[row size] [column size]={
{a1,a2,…..,an},
{b1,b2,…..,bn},
.
.
.
{z1,z2,…..,zn},
};
OR
data_type array_name[row size] [column size]={a1,a2,…..,an,b1,b2,…..,bn,z1,z2,…..,zn};

Here data_type specifies what kind of values an array can store such as int, float, char etc
array_name is the name to identify an array.
row size specifies the maximum number of rows in the array and
column size specifies the maximum number of columns in the array
Eg: 1) int a[4][3]={
{2,4,6},
{10,20,30},
{5,10,15},
{12,14,16}
};

Eg: 2) int a[4][3]={2,4,6,10,20,30,5,10,15,12,14,16};

Accessing individual array elements of 2D (Two dimensional) array

For example: int a[4][3];

To access the 1st element ie 1st row and 1st column a [0][0], to access the 2nd element ie 1st row and 2st column a[0][1]
and so on…. In general, to access the element in mth row and nth column a[m] [n], where m is the row number and n is the
column number.
To read and write all the elements in two dimensional array,2 for loops are required (nested for loops).Outer loop gives
the number of rows and inner loop gives the number of columns.
Dept. of ISE, DBIT Page
9
BCS304

To Read m x n elements (2D array)

for(i=0;i<m;i++) for(i=0;i<m-1;i++)
{ {
for(j=0;j<n;j++) for(j=0;j<=n-1;j++)
{ OR {
scanf(“%d”a[i][j]); scanf(“%d”a[i][j]);
} }
} }

To Display m x n elements (2D array)

for(i=0;i<m;i++) for(i=0;i<m-1;i++)
{ {
for(j=0;j<n;j++) for(j=0;j<=n-1;j++)
{ OR {
printf(“%d”a[i][j]); printf(“%d”a[i][j]);
} }
printf(“\n”);
printf(“\n”); }
}

Dept. of ISE, DBIT Page


10

You might also like