0% found this document useful (0 votes)
19 views41 pages

Unit 1.1 Introduction

Uploaded by

aThArvA SiNgh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views41 pages

Unit 1.1 Introduction

Uploaded by

aThArvA SiNgh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 41

APEX INSTITUTE OF TECHNOLOGY

Bachelor of Engineering (Computer Science &


Engineering)

Subject: Data Structure


Subject Code: 23CSH-241
Chapter: Introduction to Data Structure
Subject Coordinator:
Ms. Upasana Tiwari
(E15791)

Introduction to Data Structure DISCOVER . LEARN .


Lecture No. 1.1 EMPOWER
Course Objective
• To develop understanding among the students
about the concept of the data structures
• To demonstrate methods to perform
operations on different data structures.
• To teach use and application of different data
structures for modelling real world problems.

2
Course Outcome
After doing this course, the student will be able
to
1. Identify how arrays, linked lists, stacks,
queues, trees, and graphs are represented in
memory and used by algorithms.
2. Devise appropriate data structures for solving
computing problems.

3
Index
• Concept of data and information
• Introduction to Data Structures
• Types of data structure: Linear and non-linear
• Operations on Data Structures
Data
• Data is a raw and unorganized fact that required to
be processed to make it meaningful. Data can be
simple at the same time unorganized unless it is
organized. Generally, data comprises facts,
observations, perceptions numbers, characters,
symbols, image, etc.
• Data is always interpreted, by a human or machine,
to derive meaning. So, data is meaningless. Data
contains numbers, statements, and characters in a
raw form
Information
• Information is a set of data which is processed in a
meaningful way according to the given
requirement. Information is processed, structured,
or presented in a given context to make it
meaningful and useful.
• It is processed data which includes data that
possess context, relevance, and purpose. It also
involves manipulation of raw data.
Continue
Differences Between Data and Information

The terms data and information can mean different things in


different contexts, but the main differences between them are:

• Data is a collection of facts. Information is how you understand those


facts in context.
• Data is unorganized, while information is structured or organized.
• Information is an uncountable noun, while data is a mass noun.
• Data is not typically useful on its own, but information is.
• Data generally includes the raw forms of numbers, statements, and
characters. Information doesn’t have to.
• Information depends on data.
Introduction to Data Structures

• Computer is an electronic machine which is used for


data processing and manipulation.
• When programmer collects such type of data for
processing, he would require to store all of them in
computer’s main memory.
• In order to make computer work we need to know
• Representation of data in computer.
• Accessing of data.
• How to solve problem step by step.
• For doing this task we use 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 organizing all data items that
considers 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 organization of data items.
• The representation of particular data structure in the main
memory of a computer is called as storage structure.
• The storage structure representation in auxiliary memory is
called as file structure.
Continue..
• 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
• Accessing methods
• Degree of associativity
• Processing alternatives for information
• Algorithm + Data Structure = Program
• Data structure study covers the following points o Amount of
memory require to store.
• Amount of time require to process.
• Representation of data in memory.
• Operations performed on that data.
Classification of Data
Structure
Continue..
• 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.
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.
• Integer: It is a data type which allows all values without fraction part. We
can use it for whole numbers.
• Float: It is a data type which use for storing fractional numbers.
• Character: It is a data type which is used for character values.
• Pointer: A variable that holds memory address of another variable are
called pointer.
Non primitive Data Type
• These are more sophisticated data structures.
• These are derived from primitive data structures.
• The non-primitive data structures emphasize on 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
• Array: An array is a fixed-size sequenced collection of elements of
the same data type.
• List: An ordered set containing variable number of elements is called
as Lists.
• 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 Linear, if its elements are


connected in linear fashion by means of logically or in
sequence memory locations.
• There are two ways to represent a linear data structure in
memory,
• Static memory allocation
• Dynamic memory allocation

• The possible operations on the linear data structure are:


Traversal, Insertion, Deletion, Searching, Sorting and Merging.
• Examples of Linear Data Structure are Stack and Queue.
Continue..
• Stack: Stack is a data structure in which insertion and
deletion operations are performed at one end only.
• The insertion operation is referred to as ‘PUSH’ and deletion
operation is referred to as ‘POP’ operation.
• 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.
• End at which deletion is occurs is known as FRONT end and
another end at which insertion occurs is known as REAR end.
• 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 finite set of data items
(nodes) in which data items are arranged in branches
and sub branches according to requirement.
• Trees represent the hierarchical relationship between
various elements.
• Tree consist of nodes connected by edge, the node
represented by circle and edge lives connecting to circle.
Continue..
• Graph: Graph is a collection of nodes (Information)
and connecting edges (Logical relation) between
nodes. o A tree can be viewed as restricted graph.
Graphs have many types:
• Un-directed Graph
• Directed Graph
• Mixed Graph
• Multi Graph
• Simple Graph
• Null Graph
• Weighted Graph
Difference between Linear
and Non Linear Data Structure
Operations 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
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 specified data
structure. free() function of C language is used to destroy data
structure.
Continue..
3. Selection
Selection operation deals with accessing a particular data
within a data structure.
4. 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.
5. 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.
Continue..
6. Updation
It updates or modifies the data in the data structure.
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 list.
9. Traversal
Traversal is a process of visiting each and every node of a list
in systematic manner.
Index
• Algorithm complexity
• Time-space trade off
• Asymptotic notations
Algorithm complexity
• Algorithmic complexity is a measure of how long an
algorithm would take to complete given an input of
size n. If an algorithm has to scale, it should
compute the result within a finite and practical
time bound even for large values of n. For this
reason, complexity is calculated asymptotically as n
approaches infinity. While complexity is usually in
terms of time, sometimes complexity is also
analyzed in terms of space, which translates to the
algorithm's memory requirements.
Continue..

• Some algorithms are more efficient than others. We would prefer


to choose an efficient algorithm, so it would be nice to have
metrics for comparing algorithm efficiency.
• The complexity of an algorithm is a function describing the
efficiency of the algorithm in terms of the amount of data the
algorithm must process.
• Usually there are natural units for the domain and range of this
function. There are two main complexity measures of the
efficiency of an algorithm.
Time-space trade off

• Time Complexity is a function describing the


amount of time an algorithm takes in terms of the
amount of input to the algorithm.

• Time complexity
"Time" can mean the number of memory accesses
performed, the number of comparisons between
integers, the number of times some inner loop is
executed, or some other natural unit related to the
amount of real time the algorithm will take.
Continue..
• Space complexity is a function describing the amount
of memory (space) an algorithm takes in terms of the
amount of input to the algorithm.
• We often speak of "extra" memory needed, not
counting the memory needed to store the input itself.
Again, we use natural (but fixed-length) units to
measure this.
Continue..

• We can use bytes, but it's easier to use, say,


number of integers used, number of fixed-sized
structures, etc. In the end, the function we come up
with will be independent of the actual number of
bytes needed to represent the unit.
• Space complexity is sometimes ignored because the
space used is minimal and/or obvious, but
sometimes it becomes as important an issue as
time.
Worst Case Analysis

• In the worst case analysis, we calculate upper


bound on running time of an algorithm. We must
know the case that causes maximum number of
operations to be executed. For Linear Search, the
worst case happens when the element to be
searched is not present in the array. When x is not
present, the search () functions compares it with all
the elements of array [] one by one. Therefore, the
worst case time complexity of linear search would
be.
Average Case Analysis
• In average case analysis, we take all possible inputs
and calculate computing time for all of the inputs.
Sum all the calculated values and divide the sum by
total number of inputs. We must know (or predict)
distribution of cases. For the linear search problem,
let us assume that all cases are uniformly
distributed. So we sum all the cases and divide the
sum by (n+1).
Best Case Analysis
• In the best case analysis, we calculate lower bound
on running time of an algorithm. We must know
the case that causes minimum number of
operations to be executed. In the linear search
problem, the best case occurs when x is present at
the first location. The number of operations in
worst case is constant (not dependent on n). So
time complexity in the best case would be.
Asymptotic notations

Types of Data Structure Asymptotic Notation:


1. Big-O Notation (Ο) – Big O notation specificall
describes worst case scenario.
2. Omega Notation (Ω) – Omega(Ω) notation
specifically describes best case scenario.
3. Theta Notation (θ) – This notation represents the
average complexity of an algorithm.
Continue..
Big-O Notation (Ο)
The notation Ο(n) is the formal way to express the
upper bound of an algorithm's running time. It
measures the worst case time complexity or the
longest amount of time an algorithm can possibly take
to complete.
Continue..

For example, for a function f(n)


Ο(f(n)) = { g(n) : there exists c > 0 and n0 such that
f(n) ≤ c.g(n) for all n > n0. }
Continue..
Omega Notation (Ω)
The notation Ω(n) is the formal way to express the
lower bound of an algorithm's running time. It
measures the best case time complexity or the best
amount of time an algorithm can possibly take to
complete.
Continue..

For example, for a function f(n)


Ω(f(n)) ≥ { g(n) : there exists c > 0 and n0 such that
g(n) ≤ c.f(n) for all n > n0. }
Continue..
Theta Notation (θ)
The notation θ(n) is the formal way to express both
the lower bound and the upper bound of an
algorithm's running time. It is represented as
follows −
Continue..

θ(f(n)) = { g(n) if and only if g(n) = Ο(f(n)) and g(n) =


Ω(f(n)) for all n > n0. }
References
WEB LINKS
• https://www.geeksforgeeks.org/data-structures/
• https://www.javatpoint.com/data-structure-tutoria
l
• https://www.tutorialspoint.com/data_structures_al
gorithms/index.htm
VIDEO LINK
• https://www.youtube.com/watch?v=AT14lCXuMKI
&list=PLdo5W4Nhv31bbKJzrsKfMpo_grxuLl8LU
Research Paper
• https://books.google.co.in/books?id=S-tXjl1hsUYC
THANK YOU

For queries
Email: [email protected]

41

You might also like