0% found this document useful (0 votes)
17 views

DSA Introduction

Uploaded by

Sinthu K
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

DSA Introduction

Uploaded by

Sinthu K
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Data Structure and Algorithms

Introduction to Data Structure


 A computer is an electronic machine which is used for data processing and manipulation.
 When a programmer collects such type of data for processing, he would require to store all
of them in the computer’s main memory.
 To make a computer work, we need to know
o Representation of data in the computer.
o Accessing data.
o Solving the problem step by step.
 For doing this task, we use a data structure.

What is Data Structure?


 Data structure is a representation of the logical relationship existing between individual
elements of data.
 Data Structure is a way of organising all data items that consider not only the elements
stored but also their relationship to each other.
 We can also define data structure as a mathematical or logical model of a particular
organisation of data items.
 The representation of a particular data structure in the main memory of a computer is called
a storage structure.
 The storage structure representation in auxiliary memory is called a file structure.
 It is defined as the way of storing and manipulating data in organized form so that it can be
used efficiently.
 Data Structure mainly specifies the following four things
o Organization of Data
o Accessing methods
o Degree of associativity
o Processing alternatives for information
 Algorithm + Data Structure = Program
 Data structure study covers the following points
o Amount of memory requires to store.
o Amount of time requires to process.
o Representation of data in memory.
o Operations performed on that data.

Classification of Data Structure


Data Structures are normally classified into two broad categories
1. Primitive Data Structure
2. Non-primitive data Structure

Data types
A particular kind of data item, as defined by the values it can take, the programming
language used, or the operations that can be performed on it.

1
Primitive Data Structure
 Primitive data structures are basic structures and are directly operated upon by machine
instructions.
 Primitive data structures have different representations on different computers.
 Integers, floats, character and pointers are examples of primitive data structures.
 These data types are available in most programming languages as built-in type.
o Integer: It is a data type which allows all values without fraction part. We can use it for
whole numbers.
o Float: It is a data type which uses for storing fractional numbers.
o Character: It is a data type which is used for character values.
o Pointer: A variable that holds a memory address of another variable is called pointer.

Non-primitive Data Type


 These are more sophisticated data structures.
 These are derived from primitive data structures.
 The non-primitive data structures emphasise on the structuring of a group of homogeneous
or heterogeneous data items.
 Examples of Non-primitive data type are Array, List, and File etc.
 A Non-primitive data type is further divided into Linear and Non-Linear data structure
o Array: An array is a fixed-size sequenced collection of elements of the same data type.
o List: An ordered set containing the variable number of elements is called Lists.
o File: A file is a collection of logically related information. It can be viewed as a large list
of records consisting of various fields.

Linear data structures


 A data structure is said to be a Linear data structure if its elements are connected linearly
using logically or in sequence memory locations.
 There are two ways to represent a linear data structure in memory,
o Static memory allocation
o Dynamic memory allocation
 The possible operations on the linear data structure are
o Traversal
o Insertion
o Deletion
o Searching

2
o Sorting
o Merging
 Examples of Linear Data Structure are Stack and Queue.
 Stack: Stack is a data structure in which insertion and deletion operations are performed at
one end only.
o The insertion operation is referred to as ‘PUSH’, and deletion operation is referred to as
‘POP’ operation.
o The stack is also called as Last in First out (LIFO) data structure.
 Queue: The data structure which permits the insertion at one end and Deletion at another
end, known as Queue.
o End at which deletion occurs is known as FRONT end, and another end at which insertion
occurs is known as REAR end.
o The queue is also called as First in First out (FIFO) data structure.

Nonlinear data structures


 Nonlinear data structures are those data structure in which data items are not arranged in a
sequence.
 Examples of Non-linear Data Structure are Tree and Graph.
 Tree: A tree can be defined as a finite set of data items (nodes) in which data items are
arranged in branches and sub-branches according to requirement.
o Trees represent the hierarchical relationship between various elements.
o Tree consists of nodes connected by an edge, the node represented by a circle and edge
lives connecting to the circle.

Difference between Linear and Non-Linear Data Structure

Linear Data Structure Non-Linear Data Structure


Every item is related to its previous and next
time. Every item is attached with many other items.
Data is arranged in a linear sequence. Data is not arranged in sequence.
Data items can be traversed in a single run. Data cannot be traversed in a single run.
Eg. Array, Stacks, linked list, queue. Eg. Tree, graph.
Implementation is easy. Implementation is difficult.

Operation on Data Structures


Design of efficient data structure must take operations to be performed on the data structures into
account. The most commonly used operations on data structure are broadly categorized into the
following types
1. Create
The create operation results in reserving memory for program elements. This can be done by
declaration statement. Creation of data structure may take place either during compile-time or
run-time. malloc() function of C language is used for creation.
2. Destroy
Destroy operation destroys memory space allocated for a specified data structure. free()
function of C language is used to destroy data structure.
3. Selection
Selection operation deals with accessing particular data within a data structure.
4. Updating

3
It updates or modifies the data in the data structure.
5. Searching
It finds the presence of desired data item in the list of data items; it may also find the locations
of all elements that satisfy certain conditions.
6. Sorting
Sorting is a process of arranging all data items in a data structure in a particular order, say for
example, either in ascending order or in descending order.
7. Merging
Merging is a process of combining the data items of two different sorted list into a single sorted
list.
8. Splitting
Splitting is a process of partitioning single list to multiple lists.
9. Traversal
Traversal is a process of visiting every node of a list systematically.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy