Data Structure:
Data structure is the way to represent the relationship between different data items appearing in
group along with operations.
A data structure is specialized format for organizing and storing data. It is designed to organize
data to specific application.
Data structure are the fundamental building blocks of computer programming. They define
how data is organized, stored, and manipulated within a program.
Types of data structure:
The main types of data structures are commonly divided into two categories: Primitive and Non-
Primitive. Primitive data structures include basic types like integers (int), floating-point numbers
(float), characters (char), and booleans (bool). Non-Primitive data structures are more complex
and include arrays, lists, stacks, queues, trees, graphs, and hash tables.
1. 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.
Example: Array, Stack, Queue, Linked List, etc.
2. 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: Trees and Graphs.
Data Structure operation
1. Inserting: adding a new record to the structure.
2. Deleting: removing a record form the structure.
3. Searching: Find the location of the record.
4. Sorting: arranging all the records in same logical order.
5. Merging: combining two sorted files to form a single sorted file.
1.1 Algorithm
An algorithm is a step by step procedure to solve a well-defined problem in finite number of
steps. It should be efficient and last stem must terminate/exit.
An algorithm is a step by step procedure to solve a problem. In normal language,
algorithm is defined as a sequence of statements which are used to perform a task. In computer
science, an algorithm can have defined as follows:
Types of Algorithm:
Algorithm specifications:
1. Brute Force Algorithm
2. Recursive Algorithm
3. Divide and conquer Algorithm
4. Greedy Algorithm
5. Dynamic programming Algorithm
6. Backtracking Algorithm
7. Searching Algorithm
8. Sorting Algorithm
1. Brute Force Algorithm:
Brute Force Algorithm are simple and straight forward solutions that use trial and error to
solve problems it blindly iterates all possible solutions to search one or more than one
solution that makes solve a function.
Brute force algorithm are usually easiest to implement but the disadvantage of solving a
problem by this method is that it is usually very slow and can be applied only to perform
when input size is small.
2. Divide and conquer Algorithm:
This algorithm breaks a problem into sub-problems, solves a single sub problem and merge
the solutions to get the final solutions it consist of the following three steps Divide, Solve,
Integrate.
3. Dynamic programming Algorithm
The algorithm work by remembering the results of the past run and using them to find new
results. In other words, it solves complex problems by breaking them into multiple simple
sub problems by breaking them into multiple simple sub problems and them it solves each of
them once and then stores them for further use Fibonacci series is a good example for
dynamic programming algorithm.
4. Greedy Algorithm:
It makes locally optimum choices at each step in the hope of finding a global optimum useful
for optimization problems but may not always lead to the best solution.
5. Transform and Conquer Algorithm:
It is the easier to transform the problem into something that we recognize and then try to
solve that problem to arrive at the solution.
6. Backtracking Algorithm
Backtracking approach is very similar to brute force approach. Whenever a solutions fails we
track back to the failure points build on the next solutions and continue this process till we
find the solutions.