Data Structures and Algo
Data Structures and Algo
Data classification involves tagging data to make it easily searchable and traceable.
It also eliminates multiple duplications of data, which can reduce storage and
backup costs while speeding up the search process. Though the classification
process may sound highly technical, it is a topic that should be understood by your
organization’s leadership.
There are three main types of data classification that are considered industry
standards:
21
BCA 3rd Sem ( Data Structure)
Example
Stacks- A stack stores a collection of items in the linear order that operations are
applied. This order could be last in first out (LIFO).For example Stack of coins,
stack of plates ,stack of books.
Mainly the following three basic operations are performed in the stack:
22
BCA 3rd Sem ( Data Structure)
Push: Adds an item in the stack. If the stack is full, then it is said to be an
Overflow condition.
Pop: Removes an item from the stack. The items are popped in the reversed order
in which they are pushed. If the stack is empty, then it is said to be an Underflow
condition.
Operations on Queue:
Mainly the following four basic operations are performed on queue:
Enqueue: Adds an item to the queue. If the queue is full, then it is said to be an
Overflow condition.
Dequeue: Removes an item from the queue. The items are popped in the same
order in which they are pushed. If the queue is empty, then it is said to be an
Underflow condition.
23
BCA 3rd Sem ( Data Structure)
Linked lists- A linked list stores a collection of items in a linear order. Each
element, or node, in a linked list contains a data item as well as a reference, or link,
to the next item in the list.
Basic Operations.
Insertion Operation.
Deletion Operation.
Reverse Operation.
24
BCA 3rd Sem ( Data Structure)
them, also known as edges. These are useful for representing real-life systems such
as computer networks
The sector is the minimum storage unit of a hard drive. Most disk partitioning
schemes are designed to have files occupy an integral number of sectors regardless
of the file's actual size. The sector means a portion of a disk between a center,
two radii and a corresponding arc (see Figure 1, item B), which is shaped like a
slice of a pie. Thus, the disk sector refers to the intersection of a track and
geometrical sector.
25
BCA 3rd Sem ( Data Structure)
Static Memory Allocation: Memory is allocated for the declared variable by the
compiler. The address can be obtained by using ‘address of’ operator and can be
assigned to a pointer. The memory is allocated during compile time. Since most of
the declared variables have static memory, this kind of assigning the address of a
variable to a pointer is known as static memory allocation.
26
BCA 3rd Sem ( Data Structure)
When we do not know how much amount of memory would be needed for the
program beforehand.
When we want data structures without any upper limit of memory space.
When you want to use your memory space more efficiently. Example: If you have
allocated memory space for a 1D array as array[20] and you end up using only 10
memory spaces then the remaining 10 memory spaces would be wasted and this
wasted memory cannot even be utilized by other program variables.
Dynamically created lists insertions and deletions can be done very easily just by
the manipulation of addresses whereas in case of statically allocated memory
insertions and deletions lead to more movements and wastage of memory.
When you want you to use the concept of structures and linked list in
programming, dynamic memory allocation is a must.
What is recursion?
The process in which a function calls itself could happen directly as well as
indirectly. This difference in call gives rise to different types of recursion, which
we will talk about a little later. Some of the problems that can be solved using
recursion include DFS of Graph, Towers of Hanoi, Different Types of Tree
Traversals, and others.
Examples of Recursion
27
BCA 3rd Sem ( Data Structure)
By
n! = 1*2*3…..*n.
Tower of Hanoi:-
The Tower of Hanoi (also called the Tower of Brahma or Lucas' Tower[1] and
sometimes pluralized as Towers) is a mathematical game or puzzle. It consists of
three rods and a number of disks of different sizes, which can slide onto any rod.
The puzzle starts with the disks in a neat stack in ascending order of size on one
rod, the smallest at the top, thus making a conical shape.
28
BCA 3rd Sem ( Data Structure)
The objective of the puzzle is to move the entire stack to another rod, obeying the
following simple rules:
Each move consists of taking the upper disk from one of the stacks and placing it
on top of another stack or on an empty rod.
Array
Definition
Arrays are defined as the collection of similar type of data items stored at
contiguous memory locations.
Arrays are the derived data type in C programming language which can store the
primitive type of data such as int, char, double, float, etc.
Array is the simplest data structure where each data element can be randomly
accessed by using its index number.
29
BCA 3rd Sem ( Data Structure)
Advantages of Array
Array provides the single name for the group of variables of the same type
therefore, it is easy to remember the name of all the elements of an array.
Traversing an array is a very simple process, we just need to increment the base
address of the array in order to visit each element one by one.
Any element in the array can be directly accessed by using the index.
Data_type var_name[Expression];
30