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

Data Structure 1

The document discusses data structures and their importance in organizing data efficiently. It defines key terms like data type, linear and non-linear data structures. Common linear data structures include arrays, linked lists, stacks and queues. The organization of data impacts efficiency of operations like search and storage.

Uploaded by

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

Data Structure 1

The document discusses data structures and their importance in organizing data efficiently. It defines key terms like data type, linear and non-linear data structures. Common linear data structures include arrays, linked lists, stacks and queues. The organization of data impacts efficiency of operations like search and storage.

Uploaded by

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

Data Structures

Introduction
Why to Learn Data Structure and
Algorithms?
⚫ As applications are getting complex and data rich, there are three
common problems that applications face now-a-days.
⚫ Data Search − Consider an inventory of 1 million(106) items of a
store. If the application is to search an item, it has to search an item in
1 million(106) items every time slowing down the search. As data
grows, search will become slower.
⚫ Processor speed − Processor speed although being very high, falls
limited if the data grows to billion records.
⚫ Multiple requests − As thousands of users can search data
simultaneously on a web server, even the fast server fails while
searching the data.

⚫ To solve the above-mentioned problems, data structures come to


rescue.
⚫ Data can be organized in a data structure in such a way that all items
may not be required to be searched, and the required data can be
searched almost instantly.
Data Structures
⚫ Data Structure is a systematic way to organize data in order to
use it efficiently.
⚫ Foundation terms of a data structure.

⚫ Interface − Each data structure has an interface. Interface


represents the set of operations that a data structure supports. An
interface only provides the list of supported operations, type of
parameters they can accept and return type of these operations.

⚫ Implementation − Implementation provides the internal


representation of a data structure. Implementation also provides
the definition of the algorithms used in the operations of the data
structure.
Important Terms
⚫ Data Definition
Data Definition defines a particular data with the following characteristics.
⚫ Atomic − Definition should define a single concept.

⚫ Traceable − Definition should be able to be mapped to some data element.

⚫ Accurate − Definition should be unambiguous.

⚫ Clear and Concise − Definition should be understandable.

⚫ Data Object
Data Object represents an object having a data.
⚫ Data Type
Data type is a way to classify various types of data such as integer, string, etc.
which determines the values that can be used with the corresponding type of data,
the type of operations that can be performed on the corresponding type of data.
There are two data types −
⚫ Built-in Data Type

⚫ Derived Data Type


Important Terms
⚫ Built-in Data Type
⚫ Those data types for which a language has built-in support are known as
Built-in Data types. For example, most of the languages provide the
following built-in data types.
⚫ Integers
⚫ Boolean (true, false)
⚫ Floating (Decimal numbers)
⚫ Character and Strings

⚫ Derived Data Type


⚫ Those data types which are implementation independent as they can be
implemented in one or the other way are known as derived data types.
These data types are normally built by the combination of primary or
built-in data types and associated operations on them. For example −
⚫ List
⚫ Array
⚫ Stack
⚫ Queue
Characteristics of a Data Structure

⚫ Correctness − Data structure implementation should


implement its interface correctly.

⚫ Time Complexity − Running time or the execution time


of operations of data structure must be as small as
possible.

⚫ Space Complexity − Memory usage of a data structure


operation should be as little as possible.
Basic Operations
⚫ The data in the data structures are processed by certain
operations. The particular data structure chosen largely
depends on the frequency of the operation that needs to be
performed on the data structure.
⚫ Traversing
⚫ Searching
⚫ Insertion
⚫ Deletion
⚫ Sorting
⚫ Merging
Need for Data Structure
⚫ As applications are getting complex and data rich, there are three
common problems that applications face now-a-days.

• Data Search − Consider an inventory of 1 million(106) items of a


store. If the application is to search an item, it has to search an item in
1 million(106) items every time slowing down the search. As data
grows, search will become slower.
• Processor speed − Processor speed although being very high, falls
limited if the data grows to billion records.
• Multiple requests − As thousands of users can search data
simultaneously on a web server, even the fast server fails while
searching the data.

⚫ To solve the above-mentioned problems, data structures come to


rescue. Data can be organized in a data structure in such a way that
all items may not be required to be searched, and the required data
can be searched almost instantly.
Execution Time Cases
⚫ There are three cases which are usually used to compare various data
structure's execution time in a relative manner.

⚫ Worst Case − This is the scenario where a particular data structure


operation takes maximum time it can take. If an operation's worst case
time is ƒ(n) then this operation will not take more than ƒ(n) time where
ƒ(n) represents function of n.
⚫ Average Case − This is the scenario depicting the average execution
time of an operation of a data structure. If an operation takes ƒ(n) time
in execution, then m operations will take mƒ(n) time.
⚫ Best Case − This is the scenario depicting the least possible execution
time of an operation of a data structure. If an operation takes ƒ(n) time
in execution, then the actual operation may take time as the random
number which would be maximum as ƒ(n).
Advantages of Data Structures
⚫ Efficiency:
⚫ Efficiency of a program depends upon the choice of data structures. For
example: suppose, we have some data and we need to perform the
search for a particular record. In that case, if we organize our data in an
array, we will have to search sequentially element by element. hence,
using array may not be very efficient here. There are better data
structures which can make the search process efficient like ordered
array, binary search tree or hash tables.
⚫ Reusability:
⚫ Data structures are reusable, i.e. once we have implemented a particular
data structure, we can use it at any other place. Implementation of data
structures can be compiled into libraries which can be used by different
clients.
⚫ Abstraction:
⚫ Data structure is specified by the ADT which provides a level of
abstraction. The client program uses the data structure through interface
only, without getting into the implementation details.
Basic Terminology
⚫ Data − Data are values or set of values.
⚫ Data Item − Data item refers to single unit of values.
⚫ Group Items − Data items that are divided into sub items are
called as Group Items.
⚫ Elementary Items − Data items that cannot be divided are
called as Elementary Items.
⚫ Attribute and Entity − An entity is that which contains
certain attributes or properties, which may be assigned values.
⚫ Entity Set − Entities of similar attributes form an entity set.
⚫ Field − Field is a single elementary unit of information
representing an attribute of an entity.
⚫ Record − Record is a collection of field values of a given
entity.
⚫ File − File is a collection of records of the entities in a given
entity set.
Data Structure Classification
Linear Data Structures
⚫ A data structure is called linear if all of its elements are
arranged in the linear order. In linear data structures, the
elements are stored in non-hierarchical way where each
element has the successors and predecessors except the first
and last element.

⚫ Types of Linear Data Structures are given below:


⚫ Arrays
⚫ Linked List
⚫ Stacks
⚫ Queue
Linear Data Structures
⚫ Arrays: An array is a collection of similar type of data items
and each data item is called an element of the array. The data
type of the element may be any valid data type like char, int,
float or double.
⚫ The elements of array share the same variable name but each one carries a
different index number known as subscript. The array can be one dimensional,
two dimensional or multidimensional.
⚫ The individual elements of the array age are:
⚫ age[0], age[1], age[2], age[3],......... age[98], age[99].

⚫ Linked List: Linked list is a linear data structure which is used


to maintain a list in the memory. It can be seen as the collection
of nodes stored at non-contiguous memory locations. Each
node of the list contains a pointer to its adjacent node.
Linear Data Structures
⚫ Stack: Stack is a linear list in which insertion and
deletions are allowed only at one end, called top.
⚫ A stack is an abstract data type (ADT), can be implemented
in most of the programming languages. It is named as stack
because it behaves like a real-world stack, for example: -
piles of plates or deck of cards etc.

⚫ Queue: Queue is a linear list in which elements can be


inserted only at one end called rear and deleted only at the
other end called front.
⚫ It is an abstract data structure, similar to stack. Queue is
opened at both end therefore it follows First-In-First-Out
(FIFO) methodology for storing the data items.
Non Linear Data Structures
⚫ This data structure does not form a sequence i.e. each item or
element is connected with two or more other items in a
non-linear arrangement. The data elements are not arranged in
sequential structure.

⚫ Types of Non Linear Data Structures are given below:


⚫ Trees
⚫ Graphs
Non Linear Data Structures
⚫ Trees: Trees are multilevel data structures with a hierarchical
relationship among its elements known as nodes. The
bottommost nodes in the hierarchy are called leaf node while
the topmost node is called root node. Each node contains
pointers to point adjacent nodes.
⚫ Tree data structure is based on the parent-child relationship
among the nodes. Each node in the tree can have more than one
children except the leaf nodes whereas each node can have
atmost one parent except the root node. Trees can be classified
into many categories which will be discussed later in this tutorial.

⚫ Graphs: Graphs can be defined as the pictorial representation


of the set of elements (represented by vertices) connected by
the links known as edges. A graph is different from tree in the
sense that a graph can have cycle while the tree can not have
the one.
Operations on Data Structure
⚫ Traversing: Every data structure contains the set of data elements.
Traversing the data structure means visiting each element of the data
structure in order to perform some specific operation like searching
or sorting.
⚫ Example: If we need to calculate the average of the marks obtained by
a student in 6 different subject, we need to traverse the complete array
of marks and calculate the total sum, then we will decide that sum by
the number of subjects i.e. 6, in order to find the average.

⚫ Insertion: Insertion can be defined as the process of adding the


elements to the data structure at any location.
⚫ If the size of data structure is n then we can only insert n-1 data
elements into it.

⚫ Deletion: The process of removing an element from the data


structure is called Deletion. We can delete an element from the data
structure at any random location.
⚫ If we try to delete an element from an empty data structure
then underflow occurs.
Operations on Data Structure
⚫ Searching: The process of finding the location of an element within
the data structure is called Searching. There are two algorithms to
perform searching, Linear Search and Binary Search. We will
discuss each one of them later in this tutorial.

⚫ Sorting: The process of arranging the data structure in a specific


order is known as Sorting. There are many algorithms that can be
used to perform sorting, for example, insertion sort, selection sort,
bubble sort, etc.

⚫ Merging: When two lists List A and List B of size M and N


respectively, of similar type of elements, clubbed or joined to
produce the third list, List C of size (M+N), then this process is
called merging
Thanks

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