Lec-1 DSA 2002
Lec-1 DSA 2002
Lecture-1
Definition
A data structure is a way of organizing and storing data in a computer so that it can be accessed
and used efficiently. It refers to the logical or mathematical representation of data, as well as
the implementation in a computer program.
It can hold value but not data. It can hold multiple types of data
Therefore, it is dataless. within a single object.
Data type examples are int, float, Data structure examples are stack,
double, etc. queue, tree, etc.
Linear data structure: Data structure in which data elements are arranged
sequentially or linearly, where each element is attached to its previous and next
adjacent elements, is called a linear data structure.
Examples of linear data structures are array, stack, queue, linked list, etc.
Static data structure: Static data structure has a fixed memory size. It is
easier to access the elements in a static data structure.
An example of this data structure is an array.
Dynamic data structure: In the dynamic data structure, the size is not fixed.
It can be randomly updated during the runtime which may be considered
efficient concerning the memory (space) complexity of the code.
Examples of this data structure are queue, stack, etc.
Non-linear data structure: Data structures where data elements are not placed
sequentially or linearly are called non-linear data structures. In a non-linear data
structure, we can’t traverse all the elements in a single run only.
Examples of non-linear data structures are trees and graphs.
#include <stdio.h>
#include <time.h>
void fun()
while(1)
if (getchar())
break;
// The main program calls fun() and measures time taken by fun()
int main()
clock_t t;
t = clock();
fun();
t = clock() - t;
return 0;
Program-1
/* Program to demonstrate time taken by function fun() */
#include <stdio.h>
#include <time.h>
int findSum(int n)
int sum = 0;
sum = sum + i;
return sum;
// The main program calls fun() and measures time taken by fun()
int main()
clock_t t;
t = clock();
findSum(10000000);
t = clock() - t;
return 0;
#include <stdio.h>
#include <time.h>
int findSum(int n)
return n*(n+1)/2;
// The main program calls fun() and measures time taken by fun()
int main()
clock_t t;
t = clock();
findSum(10000000);
t = clock() - t;
return 0;
The difference in execution time shows that Program-2 performs better than Program-1. But, execution time is
dependent on the system specifications. Thus, there comes the concept of Asymptotic notation.
https://www.geeksforgeeks.org/understanding-time-complexity-simple-examples/