DATA STRUCTURE AND ALGORITHMS
(CSA2101)
Presidency School of Computer Science and
Engineering
Assessment Schedule
Course Duratio
S. Assessment Mark Weighta
Contents Outcome n In DATE
No type s ge
Number Hours
Continuous
1 Assessment 1
Module 1 CO1 55 Mins 10 5% 09.02.25
Continuous
2 Assessment 2 Module 2 CO2 55 Mins 10 5% 28.02.25
3 Assignment 1 Module 1 & 2 CO1 & CO2 One Week 5 2.5% 03.03.25
17.03.25 to
4 Mid Term Module 1 & 2 CO1 & CO2 90 Mins 50 25%
21.03.25
Continuous
5 Assessment 3
Module 3 CO3 55 Mins 10 5% 25.03.25
Continuous
6 Assessment 4
Module 4 CO4 55 Mins 10 5% 12.04.25
7 Assignment 2 Module 3 & 4 CO3 & CO4 One Week 5 2.5% 30.04.25
CO1, CO2, 26.05.25 to
8 End Term Module 1 to 4
CO3,CO4
180 Mins 100 50%
06.06.25
Module - 1
Introduction to Data Structure and Linear
data structure – Stacks and Queues
Introduction – Revision of C Concepts (Branching Statements, Looping
Statements and Functions) Introduction to Data Structures, Types, concept of
Arrays. Stack - Concepts and representation, Stack operations, stack
implementation using array and Applications of Stack. Queues - Representation
of queue, Queue Operations, Queue implementation using array, Types of
Queue and Applications of Queue.
Control Structures (Revision of C Concepts)
There may be situations where the programmer requires to alter normal flow of
execution of program or to perform the same operation a no. of times.
Various control statements supported by c are-
Decision control statements
Loop control statements
Following are the decision-making statements available in C:
if Statement
if-else Statement
Nested if Statement
if-else-if Ladder
switch Statement
Conditional Operator
Jump Statements:
break
continue
goto
return
Decision Control Statements (Revision of C Concepts)
Decision control statements alter the normal sequential execution of the statements of the
program depending upon the test condition to be carried out at a particular point in program.
Decision control statements supported by c are:-
if statement
if-else statement
Else if Ladder
if statement (Revision of C Concepts)
Most simple and powerful decision control statement. It executes a statement or
block of statements only if the condition is true.
Syntax:
if (condition) if (condition)
{
{ statement (s);
statement 1; }
statement 2;
} Next Statement
statement 3;
In above syntax : if condition is true only then the statements within the block
are executed otherwise next statement in sequence is executed.
if statement flowchart /* Program to check whether a no. is even */
# include<stdio.h>
# include<conio.h>
void main()
False {
Condition int num;
clrscr();
True printf(“enter the number”);
scanf(“%d”,&num)
Block of
if(num%2==0)
if
{
Next printf(“\n Number is even”);
statement }
printf(“ End of program”);
STOP getch();
}
if – else statement (Revision of C Concepts)
In case of if statement, the block of statements is executed only when the condition is true
otherwise the control is transferred to the next statement following if block.
But if specific statements are to be executed in both cases (either condition is true or false) then if –
else statement is used.
In if – else statement a block of statements are executed if the condition is true but a different block
of statements is executed when the condition is false.
Syntax:
if (condition)
{
False
statement 1; Test
statement 2; Condition
}
else
True
{
statement 3; Block of if Block of else
}
Next statement
STOP
if else example(Revision of C Concepts)
#include <stdio.h>
int main()
{ int n = 10;
if (n > 5)
{
printf("%d is greater than 5",n);
}
else
{
printf("%d is less than 5",n);
}
return 0;
}
If- else- if ladder (Revision of C Concepts)
In a program involving multiple conditions, the nested if else statements makes the program very difficult
to write and understand if nested more deeply.
For this ,we use if-else-if ladder.
Syntax:
if (condition1)
statement1;
else if(condition2)
false
statement2;
condition 1
else if(condition3)
false
statement 3;
condition 2
else true
false
default statement;
Statement 1 true condition 3
Statement 2 true
Statement 3
Default statemen
Next statement
if else ladder example(Revision of C Concepts)
#include <stdio.h> else if (marks >= 70)
int main() {
{ printf("C\n");
} else if (marks >= 60)
int marks = 85;
{
// Assign grade based on marks
printf("D\n");
if (marks >= 90)
} else
{ {
printf("A\n"); printf("F\n");
} else if (marks >= 80) }
{ return 0;
printf("B\n"); }
}
Looping Structures (Revision of C Concepts)
There are mainly two types of loops in C Programming:
1.Entry Controlled loops: In Entry controlled loops the test condition is checked before
entering the main body of the loop. For Loop and While Loop is Entry-controlled loops.
2.Exit Controlled loops: In Exit controlled loops the test condition is evaluated at the
end of the loop body. The loop body will execute at least once, irrespective of whether
the condition is true or false. do-while Loop is Exit Controlled loop.
Looping Structures (Revision of C Concepts)
When we want to repeat a group of statements a no. of times, loops are used.
These loops are executed until the condition is true.
When condition becomes false, control terminates the loop and moves on to next
instruction immediately after the loop.
Various looping structures are-
While
do – while
for
Looping Statements (Revision of C Concepts)
Loop is divided into two parts:
Body of the loop
Control of loop
Mainly control of loop is divided into two parts:
Entry Control loop (while, for)
Exit Control loop (do-while)
while statement(Revision of C Concepts)
While loop is used to execute set of statements as long as condition evaluates to true.
It is mostly used in those cases where the programmer doesn’t know in advance how
many times the loop will be executed.
Syntax:
while (condition)
{
Statement 1 ;
Statement 2 ;
}
condition true statement
Statement after while loop
while statement example(Revision of C Concepts)
#include <stdio.h>
int main()
{
int i = 1;
// Condition for the loop
while (i <= 5)
{
printf(“I Love Presidency University\n");
// Increment i after each iteration
i++;
}
return 0;
}
do- while (Revision of C Statements)
do-while is similar to while except that its test condition is evaluated at the end of the loop
instead at the beginning as in case of while loop.
So, in do-while the body of the loop always executes at least once even if the test
condition evaluates to false during the first iteration.
Syntax:
do
{
statement 1;
statement 2;
}while (condition); Body of loop
statement;
true
Test condition
false
Next statement
do- while example (Revision of C Statements)
#include <stdio.h>
int main()
{
int i = 0;
// do while loop
do
{
printf("Geeks\n");
i++;
}
while (i < 3);
return 0;
}
for loop (Revision of C Concepts)
Most versatile and popular of three loop structures.
Is used in those situations when a programmer knows in advance the number of times a
statement or block will be executed.
It contains loop control elements all at one place while in other loops they are scattered over
the program and are difficult to understand.
Syntax:-
for (initialization; condition; increment/decrement)
{
Statement( s);
}
Various other ways of writing same for loops(Revision of C
Concepts)
for (i=1; ;i++) for (i=1;i<=15;)
{ {
i=1 ………
………….
for (; i<=15;i ++) if (i>15)
{ i++;
break;
…….. }
……
} }
for loop example (Revision of C Concepts)
// Print numbers from 1 to 10
#include <stdio.h>
int main()
{
int i;
for (i = 1; i < 11; ++i)
{
printf("%d ", i);
}
return 0;
}
What is C Function? (Revision of C Concepts)
A function in C is a set of statements that when called perform some specific tasks. C
function contains set of instructions enclosed by “{ }” which performs specific
operation in a C program.
A function will carry out its intended task whenever it is called or invoked
n be called multiple times
Example
A function to add two numbers
A function to find the largest of n numbers
What is C Function? (Revision of C Concepts)
Every C program consists of one or more functions
One of these functions must be called main
Execution of the program always begins by carrying out the instructions in main
Functions call other functions as instructions
Function Declaration, Function Call and Function Definition
(Revision of C Concepts)
There are 3 aspects in every C function. They are:-
Function declaration or prototype – This informs compiler about the function name,
function parameters and return value’s data type.
Function call – This calls the actual function
Function definition – This contains all the statements to be executed
Function Declarations
Function Definition
Function Call
A function call is a statement that instructs the compiler to execute the
function. We use the function call is a statement that instructs the compiler to
execute the function. We use the function name and parameters in the
function call.
In the below example, the first sum function is called and 10,30 are passed to
the sum function. After the function call sum of a and b is returned and control
is also returned back to the main function of the program.
Note: Function call is necessary to bring the program control to the function
definition. If not called, the function statements will not be executed.
Note: A function in C must always be declared globally before calling it.
#include <stdio.h>
// Function declaration
int add(int a, int b);
int main() {
int num1, num2, result;
printf("Enter two numbers: ");
scanf("%d %d", &num1, &num2);
// Function calling
result = add(num1, num2);
printf("The sum is: %d\n", result);
return 0;
}
// Function definition
int add(int a, int b) {
return a + b;
}
Example of Function for addition of two numbers
(Revision of C Concepts)
// C program to show function
// call and definition
#include <stdio.h>
// Function that takes two parameters a and b as inputs and returns their sum
int sum(int a, int b)
{
return a + b;
}
// Driver code
int main()
{
// Calling sum function and storing its value in add variable
int add = sum(10, 30);
printf("Sum is: %d", add);
return 0;
}
Explanation:
Function declaration: int add(int a, int b);
Function definition: Logic for addition is
written in the add() function.
Function calling: Called from main().
Conditions of Return Types and
Arguments
In C programming language, functions can be called either with or
without arguments and might return values. They may or might not
return values to the calling functions.
1.Function with no arguments and no return value
2.Function with no arguments and with return value
3.Function with argument and with no return value
4.Function with arguments and with return value
Function Declaration, Function Call and Function Definition
(Revision of C Concepts) : Syntax of Functions in C
C functions aspects syntax
Return_type function_name (arguments list)
function definition {
Body of function;
}
function call function_name (arguments list);
function declaration return_type function_name (argument list);
Function Declaration, Function Call and Function
Definition (Revision of C Concepts)
Calling function (Caller)
Called function (Callee) parameter
void main() float cent2fahr(float
{ float cent, fahr; data)
scanf(“%f”,¢); {
fahr = float result;
cent2fahr(cent); result = data*9/5 +
printf(“%fC = %fF\n”, 32;
cent, fahr); Parameterreturn
passed result;
Returning value
} Calling/Invoking the cent2fahr function
}
What is Data Structure?
WHAT IS Data Structure?
The scientific process of transforming data
into insight for making better decisions,
offering new opportunities for a
competitive advantage
Data on its own is useless unless you can make sense of it!
What is Data Structure?
Wikipedia: In computer science, a data structure is a data
organization, management, and storage format that
enables efficient access and modification.
More precisely, a data structure is a collection of data values, the relationships
among them, and the functions or operations that can be applied to the data.
Data Structure= Related Data + Operations
Operation include, Storing, Searching, Deleting, Updating, Comparing, Analyzing,
Sorting…
Classification of Data Structure
Data structure
Primitive DS Non-Primitive DS
Integer Float Character Pointer
Classification of Data Structure
Non-Primitive DS
Linear List Non-Linear List
Array Queue Graph Trees
Link List Stack
Common Data Structures
List (Array, Linked List)
Stack
Queue
Tree
Heap
Hash Table
Priority Queue
Why Study Algorithms and Data Structures?
Job Descriptions on Data Structures : August 2020