Dsa Unit1.1
Dsa Unit1.1
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
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.
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.
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
With ADT we know what a Specific data type can do but how it is actually
does it hidden.
ALGORITHM
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
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
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