0% found this document useful (0 votes)
15 views35 pages

Module 1

The document provides an overview of data structures and algorithms, defining key terms such as data, information, and data items, and explaining the importance of data structures in organizing data for efficient processing. It classifies data structures into primitive and non-primitive types, detailing linear and non-linear structures, and introduces abstract data types (ADTs) that encapsulate data representation and operations. Additionally, it discusses algorithm properties, efficiency, time and space complexity, and the significance of analyzing algorithms for resource prediction.

Uploaded by

Dark Python
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)
15 views35 pages

Module 1

The document provides an overview of data structures and algorithms, defining key terms such as data, information, and data items, and explaining the importance of data structures in organizing data for efficient processing. It classifies data structures into primitive and non-primitive types, detailing linear and non-linear structures, and introduces abstract data types (ADTs) that encapsulate data representation and operations. Additionally, it discusses algorithm properties, efficiency, time and space complexity, and the significance of analyzing algorithms for resource prediction.

Uploaded by

Dark Python
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/ 35

Data Structure & Algorithms

Basic Terminologies:
 DATA : raw facts / set of values. Eg : 25
 INFORMATION: useful or processed form of data. Eg: age=25
 Data Item: single unit of value
 Types: 1.Group Data Item
2. Elementary Data Item
 Entity
 Entity Set
 Field
 Record
Introduction to Data Structures
 A data structure is a way of storing data in a computer so that it can be used

efficiently and it will allow the most efficient algorithm to be used.

 Data structure introduction refers to a scheme for organizing data, or in other words it

is an arrangement of data in computer's memory in such a way that it could make the

data quickly available to the processor for required calculations.


 Data: Collection of raw facts.

 Data structure is representation


of the logical relationship existing
between individual elements of
data.

 Data structure is a specialized


format for organizing and storing
data in memory that considers not
only the elements stored but also
their relationship to each other.
A data structure should be seen as a logical concept that must address two fundamental
concerns.
1. First, how the data will be stored, and
2. Second, what operations will be performed on it
 As data structure is a scheme for data organization so the functional definition of a
data structure should be independent of its implementation.
 The functional definition of a data structure is known as ADT (Abstract Data Type)
which is independent of implementation.
 The way in which the data is organized affects the performance of a program for
different tasks.
 Computer programmers decide which data structures to use based on the nature of
the data and the processes that need to be performed on that data.
 Some of the more commonly used data structures include lists, arrays, stacks,
queues, heaps, trees, and graphs.
Classification of Data Structure
Primitive Data Structure
 There are basic structures and directly operated upon by the machine
instructions.
 Data structures that are directly operated upon the machine level instructions are
known as primitive data structures.
 Integer, Floatingpoint number, Character constants, string constants, pointers
etc, fall in this category.
 The most commonly used operation on data structure are broadly categorized
into following types:
• Create
• Selection
• Updating
• Destroy or Delete
Non Primitive Data Structure
 The Data structures that are derived from the primitive data structures are called Non
primitive data structure.
 The non primitive data structures emphasize on structuring a group of homogeneous
(same type) or heterogeneous (different type) data items.
1. Linear Data structures
2. NonLinear Data structures
Linear Data Structure
 Linear data structures can be constructed as a continuous arrangement of data elements in the
memory.
 It can be constructed by using array data type.
 In the linear Data Structures the relationship of adjacency is maintained between the data
elements.
 Operations applied on linear data structure: The following list of operations applied on linear
data structures
1. Add an element
2. Delete an element
3. Traverse
4. Sort the list of elements
5. Search for a data element
For example Stack, Queue, Tables, List, and Linked Lists.
Non-linear Data Structure
 Non-linear data structure can be constructed as a collection of randomly distributed
set of data item joined together by using a special pointer (tag).
 In non-linear Data structure the relationship of adjacency is not maintained between
the data items.
 Operations applied on non-linear data structures: The following list of operations
applied on non-linear data structures.
1. Add elements
2. Delete elements
3. Display the elements
4. Sort the list of elements
5. Search for a data element
For example Tree and Graph
Abstract Data Type
 An abstract data type, sometimes abbreviated ADT, is a logical description of how
we view the data and the operations that are allowed without regard to how they will
be implemented.
 This means that we are concerned only with what data is representing and not with
how it will eventually be constructed.
 By providing this level of abstraction, we are creating an encapsulation around the
data.
 The idea is that by encapsulating the details of the implementation, we are hiding
them from the user’s view. This is called information hiding.
 The implementation of an abstract data type, often referred to as a data structure,
will require that we provide a physical view of the data using some collection of
programming constructs and primitive data types.
ADT
Data Structure Operations
 Traversing : Accessing each element exactly once.

 Searching : Finding the location of a particular record.

 Insertion : Adding a new record to the structure.

 Deletion : Removing a record from the structure.

 Sorting : Arranging the records in some logical order.


Algorithms
Structure and Properties of Algorithm:
An algorithm has the following structure
1. Input Step
2. Assignment Step
3. Decision Step
4. Repetitive Step
5. Output Step
An algorithm is endowed with the following properties:
1. Finiteness: An algorithm must terminate after a finite number of steps.
2. Definiteness: The steps of the algorithm must be precisely defined or
unambiguously specified.
3. Generality: An algorithm must be generic enough to solve all problems of a
particular class.
4. Effectiveness: the operations of the algorithm must be basic enough to be put
down on pencil and paper. They should not be too complex to warrant writing
another algorithm for the operation.
5. Input-Output: The algorithm must have certain initial and precise inputs, and
outputs that may be generated both at its intermediate and final steps.
Different Approaches to Design an Algorithm
An algorithm does not enforce a language or mode for its expression but only
demands adherence to its properties.
Practical Algorithm Design Issues:
1. To save time (Time Complexity): A program that runs faster is a better program.
2. To save space (Space Complexity): A program that saves space over a competing
program is 4 considerable desirable.
Efficiency of Algorithms:
 The performances of algorithms can be measured on the scales of time and space.
 The performance of a program is the amount of computer memory and time needed
to run a program.
 We use two approaches to determine the performance of a program.
 One is analytical and the other is experimental.
 In performance analysis we use analytical methods, while in performance
measurement we conduct experiments.
Time Complexity:
 The time complexity of an algorithm or a program is a function of the running time
of the algorithm or a program.
 In other words, it is the amount of computer time it needs to run to completion.
Space Complexity:
The space complexity of an algorithm or program is a function of the space needed by
the algorithm or program to run to completion.
 The time complexity of an algorithm can be computed either by an empirical or
theoretical approach.

 The empirical or posteriori testing approach calls for implementing the complete
algorithms and executing them on a computer for various instances of the
problem.

 The time taken by the execution of the programs for various instances of the
problem are noted and compared.

 The algorithm whose implementation yields the least time is considered as the
best among the candidate algorithmic solutions.
Analyzing Algorithms
 Suppose M is an algorithm, and suppose n is the size of the input data.

 Clearly the complexity f(n) of M increases as n increases.

 It is usually the rate of increase of f(n) with some standard functions.

 The most common computing times are O(1), O(log2 n), O(n), O(n log2 n),

O(n2 ), O(n3 ), O(2n )


 The total frequency counts of the program segments A, B and C given by 1,

(3n+1) and (3n2 +3n+1) respectively are expressed as O(1), O(n) and O(n2 ).

 These are referred to as the time complexities of the program segments since

they are indicative of the running times of the program segments.

 In a similar manner space complexities of a program can also be expressed in

terms of mathematical notations, which is nothing but the amount of memory

they require for their execution.


Asymptotic Notations:
 It is often used to describe how the size of the input data affects an algorithm’s
usage of computational resources.
 Running time of an algorithm is described as a function of input size n for large
n.
1. Big oh(O) :-
Definition: f(n) = O(g(n)) (read as f of n is big oh of g of n) if there exist a positive
integer n0 and a positive number c such that |f(n)| ≤ c|g(n)| for all n ≥ n0 .
Here g(n) is the upper bound of the function f(n).
2. Omega(Ω):
Definition: f(n) = Ω(g(n)) ( read as f of n is omega of g of n), if there exists a positive
integer n0 and a positive number c such that |f(n)| ≥ c |g(n)| for all n ≥ n0.
Here g(n) is the lower bound of the function f(n).
3. Theta(Θ):
Definition: f(n) = Θ(g(n)) (read as f of n is theta of g of n), if there exists a positive
integer n0 and two positive constants c1 and c2 such that c1 |g(n)| ≤ |f(n)| ≤ c2 |g(n)| for
all n ≥ n0.
The function g(n) is both an upper bound and a lower bound for the function f(n) for all
values of n, n ≥ n0 .
4. Little oh(o):
Definition: f(n) = O(g(n)) ( read as f of n is little oh of g of n), if f(n) = O(g(n)) and f(n)
≠ Ω(g(n)).
Time Complexities of various Algorithms:
Reasons for analyzing algorithms:
1. To predict the resources that the algorithm requires
 Computational Time(CPU consumption).
 Memory Space(RAM consumption).
 Communication bandwidth consumption.
2. To predict the running time of an algorithm
 Total number of primitive operations executed.

You might also like