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

Dsa Unit1.1

Uploaded by

Priyanshu Tak
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)
6 views

Dsa Unit1.1

Uploaded by

Priyanshu Tak
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/ 33

Lecture By : Ms.

Priya Swami
Designation : Assistant Professor
Subject : Data Structure
Course Code : BCE03102
Content Overview


Definition of Data Structure

Classification of Data Structures

Primitive

Non-primitive

Elementary Data Organization

Time and Space Complexity of an Algorithm
(Examples)

String Processing
Definition of Data Structure


Data Structures is about how data can be stored in different
structures.

Algorithms is about how to solve different problems, often by
searching through and manipulating data structures.

Theory about Data Structures and Algorithms (DSA) helps
us to use large amounts of data to solve problems efficiently.

The choice of a particular data model depends on the two
considerations

It must be rich enough in structure to mirror the actual
relationships of the data in the real world.

The structure should be simple enough that one can
effectively process the data whenever necessary .
Classification of Data Structure

Data structures are generally classified into:



Primitive data Structures

Non-primitive data Structures

Primitive data Structures: The fundamental data types which
are supported by a programming language. Such as integer,
real, character and Boolean. These data types consists of
characters that cannot be divided and hence they also called
Simple data types.

Non-Primitive data Structures: Those data structures which
are created using primitive data structures. Such as the
processing of complex numbers, linked lists, stacks, trees, and
graphs.
Elementary Data Organization

Basic Terminology

Data: Simply values or sets of values.

Data items: Refers to a single unit of values.

Data items that are divided into sub-items are called Group
items.

Ex: An Employee Name may be divided into three subitems:

first name

middle name

last name.

Data items that are not able to divide into sub-items are called
Elementary Items. Ex: SSN
BASIC TERMINOLOGY


Entity: An entity is something that has certain attributes or
properties which may be assigned values.

The values may be either numeric or non-numeric.

Ex: Attributes- Names, Age, Gender, SSN Values- Rohland
Gail, 34, F, 134-34-5533

Entities with similar attributes form an entity set.

Each attribute of an entity set has a range of values, the set of
all possible values that could be assigned to the particular
attribute.

The term “information” is sometimes used for data with given
attributes, of, in other words meaningful or processed data.

Field: A single elementary unit of information representing an
attribute of an entity.
BASIC TERMINOLOGY


File: The collection of records of the entities in a
given entity set.

Each record in a file may contain many field
items.

The value in a certain field may uniquely
determine the record in the file.

Such a field K is called a primary key and the
values k1, k2, . . . kn in such a field are called
keys or key values.
BASIC TERMINOLOGY


Record: The collection of field values of a given entity.

Records may also be classified according to length.

A file can have fixed-length records or variable-length records.

In fixed-length records, all the records contain the same data
items with the same amount of space assigned to each data
item.

In variable-length records file records may contain different
lengths.

Example: Student records have variable lengths, since different
students take different numbers of courses.

Variable-length records have a minimum and a maximum length.
Elementary Data Organization


The above organization of data into fields, records and files may not be
complex enough to maintain and efficiently process certain collections of
data.

For this reason, data are also organized into more complex types of
structures.

The study of complex data structures includes the following three steps:

1. Logical or mathematical description of the structure

2. Implementation of the structure on a computer

3. Quantitative analysis of the structure, which includes determining
the amount of memory needed to store the structure and the time
required to process the structure.
DATA STRUCTURE OPERATIONS

The data appearing in data structures are processed by means of certain operations.

The following four operations play a major role in this text:


1. Traversing: Accessing each record/node exactly once so that certain items in the
record may be processed.


2. Searching: Finding the location of the desired node with a given key value.


3. Inserting: Adding a new node/record to the structure.


4. Deleting: Removing a node/record from the structure.

The following two operations, which are used in special situations:


1. Sorting: Arranging the records in some logical order (e.g., alphabetically according to
some NAME key, or in numerical order according to some NUMBER key, such as social
security number or account number)


2. Merging: Combining the records in two different sorted files into a single sorted file.
Need of Data Organization

The advantages of organizing data are as follows:



It saves a lot of time.

Removes any possible errors.

Easy to understand and memorize.

Organized data are visually appealing.
ABSTRACT DATA TYPE (ADT)

ADT refers to a Set of Value associated with operation or function.

With ADT we know what a Specific data type can do but how it is actually
does it hidden.
ALGORITHM

Algorithm is a step-by-step procedure which defines a


set of instructions to be executed in a certain order to
get the desired output.
Design Approach
Criteria of Algorithm

(i) Input: Zero or more input.


(ii) Output: Must produce at least one Value.
(iii) Finiteness: Must have ending.
(iv) Definiteness: Each step must be clear and un-
ambigous.
(v) Effectiveness: Every instruction should be clear. it
should not be complex
Analyze and Efficiency

Analyzing of Algorithm is require to dectate the


correctness and Measurement the efficiency of
Algorithm.
Analysis Types

There are three types of Analysis:



Worst Case: Maximum number of steps taken
on any instance of size 'n'.

Best Case: Minimum number of steps taken on
any instance of size 'n'.

Average Case: Any Average number of steps
taken on any instance of size 'n'.
Complexity of an Algorithm

The complexity of an algorithm is a function f(n), which


measures the time and/or space used by an algorithm
in terms of the input size n.
There are two types of complexity.

I) Time Complexity: Amount of computer time
need to run to completion.

(II) Space Complexity: Amount of memory time
need run to completion.
Time Complexity Examples
Ex: (i) Sub (a ,n) = T (let)
{
S = 0.0 → 1
for i = 1 to n do → n+1 3+2n = O(n)
S = S + a[i] →n
return S → 1
}
Ex: (ii) Product [a(1......m,1......n), b(1.....n,1.....p)]
for i ← t to m do → m+1
for i ← t to p do → (p+1)m
C[i, j] ⇐ 0 →m.p
for k ← 1 to n do →m.p(n+1)
C[i, j] ← C[i, j] + a[j, k]*b [k, j] →m.p.n
return C[1.....m, 1.....P] →1
T = m +1 + m(P + 1) + mp + mp(n + 1) + mpn
= O(m.p.n)
Space Complexity Examples
(SP) = (Constant + Space) + Auxiliary Space
↑ ↑
(Input, local variable) ( Temporary/ Variable)
Ex: abc (a, b, c)
{
return a + b + b*c + (b + b - c) / a + b + 4.0;
}
∴ SP = 1+1+1
=3 = O(1)
Ex: Sum (a, n)
{
S=0
for i = 1 to n do
S = S + a[i]
return S:
}
∴ SP = (nx1 +1 +1 +1)
= (n+2)+1
= O(1)
Asymptotic Notation

Asymptotic Notations are mathematical tool to represent


complexity in term of Time and Space.

1. Big-oh (O) → Upper Bound

2. Big Omega(Ω) → Lower Bound

3. Theta(θ) → Average Bound

4. Small-oh (o)

5. Small omega(ω)
Time-Space Trade Off
Time-Space is a way of of solving problem:

(i) In less time by using more memory.

(ii) In less memory or space by using more time.


Suppose a file is sorted numerically by social Security number.

As new records are inserted into the file.

Data must be constantly moved to new locations.

In order to maintain the sorted order.
STRING


Each programming languages contains a character set
that is used to communicate with the computer.

The character set include the following:

Alphabet: A B C D E F G H I J K L M N O P Q R S T
UVWXYZ

Digits: 0 1 2 3 4 5 6 7 8 9

Special characters: + - / * ( ) , . $ = ‘ _ (Blank space)
BASIC TERMINOLOGY OF STRING

String: A finite sequence S of zero or more Characters is called string.

Length: The number of characters in a string is called length of string.

Empty or Null String: The string with zero characters.

Concatenation: Let S1 and S2 be the strings.

The string consisting of the characters of S1 followed by the
character S2 is called Concatenation of S1 and S2.

Ex: ‘THE’ // ‘END’ = ‘THEEND’ ‘THE’ // ‘ ’ // ‘END’ = ‘THE END’

Sub-string: A string Y is called sub-string of a string S if there exist
string X and Z such that S = X // Y // Z

If X is an empty string, then Y is called an Initial sub-string of S,
and Z is an empty string then Y is called a terminal sub-string of
S.

Ex: ‘BE OR NOT’ is a sub-string of ‘TO BE OR NOT TO BE’ ‘THE’
is an initial sub-string of ‘THE END
Storing String

Strings are stored in three types of structures:


1. Fixed length structures

2. Variable length structures with fixed maximum

3. Linked structures
Fixed-length Structure

In fixed length structures each line of print is viewed as a record, where all
have the same length i.e, where each record accommodates the same
number of characters.

The main advantages of this method are:

1. The ease of accessing data from any given record

2. The ease of updating data in any given record

The main disadvantages are:

1. Time is wasted reading an entire record if most of the storage
consists of inessential blank spaces.

2. Certain records may require more space than available

3. When the correction consists of more or fewer characters than
the original text, changing a misspelled word requires record to be
changed.
Variable-length Structure


The storage of variable-length strings in memory cells with
fixed lengths can be done in two general ways

1. One can use a marker, such as two dollar signs ($
$), to signal the end of the string

2. One can list the length of the string—as an
additional item in the pointer array
Linked Structure


Most extensive word processing applications, strings are stored
by means of linked lists.

In a one way linked list, a linearly ordered sequence of
memory cells called nodes, where each node contains an
item called a link, which points to the next node in the list, i.e,
which consists the address of the next node.

Strings may be Stored in linked list as follows:

Each memory cell is assigned one character or a fixed
number of characters

A link contained in the cell gives the address of the cell
containing the next character or group of character in the
string.
Character Data Type

The various programming languages handles character data type in different ways:

Constants: Many programming languages denotes string constants by placing the
string in either single or double quotation marks.

Ex: ‘THE END’ “THE BEGINNING” The string constants of length 7 and 13
characters respectively.

Variables: Each programming languages has its own rules for forming character
variables.

These variables fall into one of three categories

1. Static: In static character variable, whose length is defined before the
program is executed and cannot change throughout the program

2. Semi-static: The length of the variable may vary during the execution
of the program as long as the length does not exceed a maximum value
determined by the program before the program is executed.

3. Dynamic: The length of the variable can change during the execution
of the program.
Operations on STRING

Strings support a wide range of operations, including concatenation, sub-


string extraction, length calculation, and more.
These operations allow developers to manipulate and process string data
efficiently.
Below are fundamental operations commonly performed on strings in
programming.
 Concatenation: Combining two strings to create a new string.
 Length: Determining the number of characters in a string.
 Access: Accessing individual characters in a string by index.
 Sub-string: Extracting a portion of a string.
 Comparison: Comparing two strings to check for equality or order.
 Search: Finding the position of a specific substring within a string.
 Modification: Changing or replacing characters within a string.
Applications of STRING


Text Processing: Strings are extensively used for text processing
tasks such as searching, manipulating, and analyzing textual data.

Data Representation: Strings are fundamental for representing and
manipulating data in formats like JSON, XML, and CSV.

Encryption and Hashing: Strings are commonly used in encryption
and hashing algorithms to secure sensitive data and ensure data
integrity.

Database Operations: Strings are essential for working with
databases, including storing and querying text-based data.

Web Development: Strings are utilized in web development for
constructing URLs, handling form data, processing input from web
forms, and generating dynamic content.
References


1. Data Structures and Algorithm Analysis in C,
Weiss Pearson Education, 2001

2. Schaum’s outline series Data structures,
Lipschutz Tata McGraw-Hill

3. Data Structures and program designing using
‘C’, Robert Kruse Pearson

4. Data Structures Using C Bandyopadhyay
Pearson Education, 1999 5 Data Structures Using
C Tenenbaum Pearson Education.
THANK
YOU

You might also like