DSA Unit 1
DSA Unit 1
Data Structure is a way to store and organize data in the main memory. It is technique or method of
study how the data are interrelate to each other logically and mathematically.
1. Primitive DS:-
Primitive data structure is a kind of data structure that stores the data of only one type.
For example:- int, char, float, double etc.
2. Non Primitive DS:- Non-primitive data structure is a type of data structure that can store the data of
more than two type.
They are divide in 2 types:-
1. Linear DS:- The arrangement of data in a sequential manner is known as a linear data
structure.
For example:- Arrays, Linked list, Stacks, and Queues.
2. Non Linear DS:- The arrangement of data in a non sequential manner is known as a non
linear data structure.
For example:- Tree, graph and linked list,
1. One-Dimensional Array: An Array with only one row of data elements is known as a One-
Dimensional Array. It is stored in ascending storage location.
2. Two-Dimensional Array: An Array consisting of multiple rows and columns of data elements is called
a Two-Dimensional Array. It is also known as a Matrix.
3. Three-Dimensional Array: An array consisting a 2d array is called 3D array.
1. Stack:-
A Stack is a Linear Data Structure that follows the LIFO (Last In, First Out) principle states that the
insertion and deletion from one end of the Stack.
2. Queue:-
The Queue is also a Linear Data Structure that follows the FIFO (First In, First Out) principle states that
the insertion of an element in a Queue is done at one end, and the removal is done at another or
opposite end.
Enqueue(Rear): The insertion or Addition of some data elements to the Queue is called
Enqueue. The element insertion is always done with the help of the rear pointer.
Dequeue(Front): Deleting or removing data elements from the Queue is termed Dequeue. The
deletion of the element is always done with the help of the front pointer.
The top pointer is used in a stack to indicate the top element. It helps in adding new elements to the top
and removing elements from the top.
Define Bubble Sort, Insertion Sort and Selection Sort?
Bubble Sort: Bubble sort is like repeatedly swapping adjacent elements if they are in the wrong
order.
Insertion Sort: Insertion sort is like building a sorted list one item at a time by shifting larger
elements to the right.
Selection Sort: Selection sort is like finding the smallest element and swapping it with the first
unsorted element.
Binary Searching:-
Binary search is a technique used to find the given elements from the sorted array by continuously
halving the array and then searching specified elements from a half array.
It works only the sorted data structures.
Linear Search:-
A linear search is also known as a sequential search that simply scans each element at a time.
It works on the both sorted and unsorted data structures.
When the allocation of memory performs at the When the memory allocation is done at the
compile time, then it is known as static memory. execution or run time, then it is called dynamic
memory allocation.
The memory is allocated at the compile time. The memory is allocated at the runtime
It is fast. It is slow.
In static memory allocation, while executing a In dynamic memory allocation, while executing a
program, the memory cannot be changed. program, the memory can be changed.
What is Algorithm?
The step by step Declaration of any Program is called Algorithm. It is the sequence Wise Declaration of
any program.
Difference between Linear and Non Linear Data Structure?
Those data structures are arranged in Those data structures are not arranged
sequential order is called linear data in sequential order is called non linear
structure. data structure.