SlideShare a Scribd company logo
1 of 16
Download to read offline
1
G BHARATH KUMAR, Assistant Professor, CSE Department
MODULE 1:
INTRODUCTION
I. Basic Terminology: Elementary Data Organization:
1. Data: Data are simply values or sets of values.
 The word "data" was first used to mean "Transmissible and storable computer information" in
1946.
Data Documents: whenever data needs to be registered, data exists in the form of a data
documents. Different kinds of data documents include:
 data repository
 data study
 data set
 software
 data paper
 data base
 data handbook
 data journal etc...
Structure: Structure means to purposefully arrange something in a specific way.
 Structure is an arrangement and organization of interrelated elements in a system.
 The arrangement of and relations between the parts of something complex.
 a building or other object constructed from several parts.
2. Data items: 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, and last name.
Data items that are not able to divide into sub-items are called Elementary items.
Ex: R.No, Gender, Age etc...
3. Entity: An entity can be a real-world object, either animate or inanimate, that can be easily
Identifiable. The values may be either numeric or non-numeric.
Attributes- Names, Age, Sex, SSN
Values- Rohland Gail, 34, F, 134-34-5533
For Example, in a college data base students, Staff, classes and courses offered can be considered as
entities.
All these entities have some attributes that give them their identity.
4. Field is a single elementary unit of information representing an attribute of an entity.
5. Record is the collection of field values of a given entity.
2
G BHARATH KUMAR, Assistant Professor, CSE Department
6. File is the collection of records of the entities in a given entity set.
Each record in a file may contain many field items but 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,
….. in such a field are called keys or key values.
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.
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.
7. Data Structures
Data may be organized in many different ways. The logical or mathematical model of a
particular organization of data is called a data structure.
The choice of a particular data model depends on the two considerations
1. It must be rich enough in structure to mirror the actual relationships of the data in the
real world.
2. The structure should be simple enough that one can effectively process the data
whenever necessary.
In computer science, a data structure is a data organization, management, and storage format
that enables efficient access and modification. More precisely, a data structure is a collection of data
values, the relationships among them, and the functions or operations that can be applied to the data.
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 Structures Usage
Data structures serve as the basis for abstract data types (ADT). The ADT defines the logical form of
the data type. The data structure implements the physical form of the data type.
Different types of data structures are suited to different kinds of applications, and some are highly
specialized to specific tasks. For example, relational databases commonly use B-tree indexes for data
retrieval, while compiler implementations usually use hash tables to look up identifiers.
3
G BHARATH KUMAR, Assistant Professor, CSE Department
Data structures provide a means to manage large amounts of data efficiently for uses such as
large databases and internet indexing services. Usually, efficient data structures are key to designing
efficient algorithms. Some formal design methods and programming languages emphasize data
structures, rather than algorithms, as the key organizing factor in software design. Data structures
can be used to organize the storage and retrieval of information stored in both main
memory and secondary memory.
Data Structures Implementation
Data structures are generally based on the ability of a computer to fetch and store data at any place in
its memory, specified by a pointer—a bit string, representing a memory address, that can be itself
stored in memory and manipulated by the program. Thus, the array and record data structures are
based on computing the addresses of data items with arithmetic operations, while the linked data
structures are based on storing addresses of data items within the structure itself.
The implementation of a data structure usually requires writing a set of procedures that create and
manipulate instances of that structure. The efficiency of a data structure cannot be analyzed
separately from those operations. This observation motivates the theoretical concept of an abstract
data type, a data structure that is defined indirectly by the operations that may be performed on it,
and the mathematical properties of those operations (including their space and time cost).
CLASSIFICATION OF DATA STRUCTURES
Data structures are generally classified into
 Primitive data Structures
 Non-primitive data Structures
1. Primitive data Structures: Primitive data structures are the fundamental data types which
are supported by a programming language. Basic data types such as integer, real, character
and Boolean are known as Primitive data Structures. These data types consists of characters
that cannot be divided and hence they also called simple data types.
2. Non- Primitive data Structures: Non-primitive data structures are those data structures
which are created using primitive data structures. Examples of non-primitive data structures
is the processing of complex numbers, linked lists, stacks, trees, andgraphs.
Based on the structure and arrangement of data, non-primitive data structures is further
classified into
1. Linear Data Structure
2. Non-linear Data Structure
1. Linear Data Structure:
A data structure is said to be linear if its elements form a sequence or a linear list. There are
basically two ways of representing such linear structure in memory.
1. One way is to have the linear relationships between the elements represented by means
of sequential memory location. These linear structures are called arrays.
2. The other way is to have the linear relationship between the elements represented by
4
G BHARATH KUMAR, Assistant Professor, CSE Department
means of pointers or links. These linear structures are called linked lists.
The common examples of linear data structure are Arrays, Queues, Stacks, Linked lists
2. Non-linear Data Structure:
A data structure is said to be non-linear if the data are not arranged in sequence or a linear. The
insertion and deletion of data is not possible in linear fashion. This structure is mainly used to
represent data containing a hierarchical relationship between elements. Trees and graphs are
the examples of non-linear data structure.
Abstract Data Types
Abstract Data type (ADT) is a type (or class) for objects whose behaviour is defined by a set of value and a set of operations.
The definition of ADT only mentions what operations are to be performed but not how these operations will be implemented. It
does not specify how data will be organized in memory and what algorithms will be used for implementing the operations. It is
called ―abstract‖ because it gives an implementation-independent view. The process of providing only the essentials and hiding
the details is known as abstraction.
The user of data type does not need to know how that data type is implemented, for example, we have been using
Primitive values like int, float, char data types only with the knowledge that these data type can operate and be
performed on without any idea of how they are implemented. So a user only needs to know what a data type can do,
but not how it will be implemented. Think of ADT as a black box which hides the inner structure and design of the
data type.
Trees
Data frequently contain a hierarchical relationship between various elements. The data structure
which reflects this relationship is called a rooted tree graph or a tree.
Some of the basic properties of tree are explained by means of examples
Example 1: Record Structure
Although a file may be maintained by means of one or more arrays a record, where one indicates
both the group items and the elementary items, can best be described by means of a tree
structure.
For example, an employee personnel record may contain the following data items:
Social Security Number, Name, Address, Age, Salary, Dependents
5
G BHARATH KUMAR, Assistant Professor, CSE Department
However, Name may be a group item with the sub-items Last, First and MI (middle initial).
Also Address may be a group item with the subitems Street address and Area address, where
Area itself may be a group item having subitems City, State and ZIP codenumber.
This hierarchical structure is pictured below
Another way of picturing such a tree structure is in terms of levels, as shown below
Some of the data structures are briefly described below.
1. Stack: A stack, also called a fast-in first-out (LIFO) system, is a linear list in which insertions
and deletions can take place only at one end, called the top. This structure is similar in its
operation to a stack of dishes on a spring system as shown in fig.
Note that new 4 dishes are inserted only at the top of the stack and dishes can be deleted only
from the top of the Stack.
6
G BHARATH KUMAR, Assistant Professor, CSE Department
7
G BHARATH KUMAR, Assistant Professor, CSE Department
2. Queue: A queue, also called a first-in first-out (FIFO) system, is a linear list in which
deletions can take place only at one end of the list, the "from'' of the list, and insertions can take
place only at the other end of the list, the ―rear‖ of the list.
This structure operates in much the same way as a line of people waiting at a bus stop, as
pictured in Fig. the first person in line is the first person to board the bus. Another analogy is
with automobiles waiting to pass through an intersection the first car in line is the first car
through.
3. Graph: Data sometimes contain a relationship between pairs of elements which is not
necessarily hierarchical in nature. For example, suppose an airline flies only between the cities
connected by lines in Fig. The data structure which reflects this type of relationship is called a
graph.
8
G BHARATH KUMAR, Assistant Professor, CSE Department
II. DATA STRUCTURES OPERATIONS
The data appearing in data structures are processed by means of certain operations.
The following four operations play a major role in thistext:
1. Traversing: accessing each record/node exactly once so that certain items in the record
may be processed. (This accessing and processing is sometimes called ―visiting‖ the
record.)
2. Searching: Finding the location of the desired node with a given key value, or finding
the locations of all such nodes which satisfy one or more conditions.
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.
V Space-Time Trade-off
Types of Space-Time Trade-off
 Compressed or Uncompressed data
 Re Rendering or Stored images
 Smaller code or loop unrolling
 Lookup tables or Recalculation
Compressed or Uncompressed data: A space-time trade-off can be applied to the problem of data
storage.
If data stored is uncompressed, it takes more space but less time.
But if the data is stored compressed, it takes less space but more time to run the decompression algorithm.
There are many instances where it is possible to directly work with compressed data. In that case of
compressed bitmap indices, where it is faster to work with compression than without compression.
Re-Rendering or Stored images: In this case, storing only the source.
rendering it as an image would take more space but less time i.e., storing an image in the cache is faster
than re-rendering but requires more space in memory.
Smaller code or Loop Unrolling(larger code- without loops): Smaller code occupies less space in
memory but it requires high computation time that is required for jumping back to the beginning of the
loop at the end of each iteration.
9
G BHARATH KUMAR, Assistant Professor, CSE Department
Loop unrolling can optimize execution speed at the cost of increased binary size. It occupies more space in
memory but requires less computation time.
Lookup tables or Recalculation: In a lookup table, an implementation can include the entire table which
reduces computing time but increases the amount of memory needed.
It can recalculate i.e., compute table entries as needed, increasing computing time but reducing memory
requirements.
Searching Algorithms
Searching-
 Searching is a process of finding a particular element among several given elements.
 The search is successful if the required element is found.
 Otherwise, the search is unsuccessful.
Searching Algorithms-
Searching Algorithms are a family of algorithms used for the purpose of searching.
10
G BHARATH KUMAR, Assistant Professor, CSE Department
The searching of an element in the given array may be carried out in the following two ways-
1. Linear Search
2. Binary Search
In this article, we will discuss about Linear Search Algorithm.
VI. Linear Search
 Linear Search is the simplest searching algorithm.
 It traverses the array sequentially to locate the required element.
 It searches for an element by comparing it with each element of the array one by one.
 So, it is also called as Sequential Search.
Linear Search Algorithm is applied when-
 No information is given about the array.
 The given array is unsorted or the elements are unordered.
 The list of data items is smaller.
Linear Search Algorithm-
Consider-
 There is a linear array ‗a‘ of size ‗n‘.
 Linear search algorithm is being used to search an element ‗item‘ in this linear array.
 If search ends in success, it sets loc to the index of the element otherwise it sets loc to -1.
In computer science, a linear search or sequential search is a method for finding an element within
a list. It sequentially checks each element of the list until a match is found or the whole list has been
searched.[1]
11
G BHARATH KUMAR, Assistant Professor, CSE Department
A linear search runs in at worst linear time and makes at most n comparisons, where n is the length of the
list. If each element is equally likely to be searched, then linear search has an average case
of n+1/2 comparisons, but the average case can be affected if the search probabilities for each element
vary. Linear search is rarely practical because other search algorithms and schemes, such as the binary
search algorithm and hash tables, allow significantly faster searching for all but short lists.[2]
Linear search is a very simple search algorithm. In this type of search, a sequential search is made over
all items one by one. Every item is checked and if a match is found then that particular item is returned,
otherwise the search continues till the end of the data collection.
Algorithm
Linear Search ( Array A, Value x)
Step 1: Set i to 1
Step 2: if i > n then go to step 7
Step 3: if A[i] = x then go to step 6
Step 4: Set i to i + 1
Step 5: Go to Step 2
Step 6: Print Element x Found at index i and go to step 8
Step 7: Print element not found
Step 8: Exit
Pseudocode
procedure linear_search (list, value)
for each item in the list
if match item == value
return the item's location
end if
end for
end procedure
A simple approach is to do a linear search, i.e
 Start from the leftmost element of arr[] and one by one compare x with each element of arr[]
 If x matches with an element, return the index.
 If x doesn‘t match with any of elements, return -1.
Note:
Linear search is rarely used practically because other search algorithms such as the binary search algorithm
and hash tables allow significantly faster-searching comparison to Linear search.
12
G BHARATH KUMAR, Assistant Professor, CSE Department
Linear Search vs Binary Search
A linear search scans one item at a time, without jumping to any item .
1. The worst case complexity is O(n), sometimes known an O(n) search
2. Time taken to search elements keep increasing as the number of elements are increased.
A binary search however, cut down your search to half as soon as you find middle of a sorted list.
1. The middle element is looked to check if it is greater than or less than the value to be searched.
2. Accordingly, search is done to either half of the given list
Important Differences
 Input data needs to be sorted in Binary Search and not in Linear Search
 Linear search does the sequential access whereas Binary search access data randomly.
 Time complexity of linear search -O(n) , Binary search has time complexity O(log n).
 Linear search performs equality comparisons and Binary search performs ordering comparisons
Class Search algorithm
Worst-case performance O(n)
Best-case performance O(1)
Average performance O(n/2)
Worst-case space complexity O(1) iterative
#include<stdio.h>
int main()
{
int a[20],i,x,n;
printf("How many elements?");
scanf("%d",&n);
printf("Enter array elements:n");
for(i=0;i<n;++i)
scanf("%d",&a[i]);
printf("nEnter element to search:");
scanf("%d",&x);
for(i=0;i<n;++i)
if(a[i]==x)
break;
if(i<n)
13
G BHARATH KUMAR, Assistant Professor, CSE Department
printf("Element found at index %d",i);
else
printf("Element not found");
return 0;
}
Complexity of the Linear Search Algorithm
VII Binary Search-
 Binary Search is one of the fastest searching algorithms.
 It is used for finding the location of an element in a linear array.
 It works on the principle of divide and conquer technique.
Binary Search Algorithm can be applied only on Sorted arrays.
So, the elements must be arranged in-
 Either ascending order if the elements are numbers.
 Or dictionary order if the elements are strings.
To apply binary search on an unsorted array,
 First, sort the array using some sorting technique.
 Then, use binary search algorithm.
Binary Search Algorithm-
Consider-
 There is a linear array ‗a‘ of size ‗n‘.
 Binary search algorithm is being used to search an element ‗item‘ in this linear array.
 If search ends in success, it sets loc to the index of the element otherwise it sets loc to -1.
 Variables beg and end keeps track of the index of the first and last element of the array or sub array in
which the element is being searched at that instant.
 Variable mid keeps track of the index of the middle element of that array or sub array in which the
element is being searched at that instant.
Then, Binary Search Algorithm is as follows-
Begin Set beg = 0 Set end = n-1 Set mid = (beg + end) / 2 while ( (beg <= end) and (a[mid] ≠ item) ) do
if (item < a[mid]) then Set end = mid - 1 else Set beg = mid + 1 endif Set mid = (beg + end) / 2
14
G BHARATH KUMAR, Assistant Professor, CSE Department
endwhile if (beg > end) then Set loc = -1 else Set loc = mid endif End
Explanation
Binary Search Algorithm searches an element by comparing it with the middle most
element of the array.
Then, following three cases are possible-
Case-01
If the element being searched is found to be the middle most element, its index is
returned.
Case-02
If the element being searched is found to be greater than the middle most element,
then its search is further continued in the right sub array of the middle most element.
Case-03
If the element being searched is found to be smaller than the middle most element,
then its search is further continued in the left sub array of the middle most element.
This iteration keeps on repeating on the sub arrays until the desired element is found
or size of the sub array reduces to zero.
Time Complexity Analysis-
Binary Search time complexity analysis is done below-
 In each iteration or in each recursive call, the search gets reduced to half of the array.
 So for n elements in the array, there are log2n iterations or recursive calls.
Thus, we have-
Time Complexity of Binary Search Algorithm is O(log2n).
15
G BHARATH KUMAR, Assistant Professor, CSE Department
Here, n is the number of elements in the sorted linear array.
This time complexity of binary search remains unchanged irrespective of the element position even if it
is not present in the array.
Binary Search Example-
Consider-
 We are given the following sorted linear array.
 Element 15 has to be searched in it using Binary Search Algorithm.
Binary Search Algorithm works in the following steps-
Step-01:
 To begin with, we take beg=0 and end=6.
 We compute location of the middle element as-
mid
= (beg + end) / 2
= (0 + 6) / 2
= 3
 Here, a[mid] = a[3] = 20 ≠ 15 and beg < end.
 So, we start next iteration.
Step-02:
 Since a[mid] = 20 > 15, so we take end = mid – 1 = 3 – 1 = 2 whereas beg remains unchanged.
 We compute location of the middle element as-
mid
= (beg + end) / 2
= (0 + 2) / 2
16
G BHARATH KUMAR, Assistant Professor, CSE Department
= 1
 Here, a[mid] = a[1] = 10 ≠ 15 and beg < end.
 So, we start next iteration.
Step-03:
 Since a[mid] = 10 < 15, so we take beg = mid + 1 = 1 + 1 = 2 whereas end remains unchanged.
 We compute location of the middle element as-
mid
= (beg + end) / 2
= (2 + 2) / 2
= 2
 Here, a[mid] = a[2] = 15 which matches to the element being searched.
 So, our search terminates in success and index 2 is returned.
Binary Search Algorithm Advantages-
The advantages of binary search algorithm are-
 It eliminates half of the list from further searching by using the result of each comparison.
 It indicates whether the element being searched is before or after the current position in the list.
 This information is used to narrow the search.
 For large lists of data, it works significantly better than linear search.
Binary Search Algorithm Disadvantages-
The disadvantages of binary search algorithm are-
 It employs recursive approach which requires more stack space.
 Programming binary search algorithm is error prone and difficult.
 The interaction of binary search with memory hierarchy i.e. caching is poor.
(because of its random access nature)
Important Note-
For in-memory searching, if the interval to be searched is small,
 Linear search may exhibit better performance than binary search.
 This is because it exhibits better locality of reference.

More Related Content

What's hot

Introduction to data structure ppt
Introduction to data structure pptIntroduction to data structure ppt
Introduction to data structure pptNalinNishant3
 
Chapter 1( intro &amp; overview)
Chapter 1( intro &amp; overview)Chapter 1( intro &amp; overview)
Chapter 1( intro &amp; overview)MUHAMMAD AAMIR
 
Introduction to data structure
Introduction to data structureIntroduction to data structure
Introduction to data structuresunilchute1
 
Data structure
Data structureData structure
Data structureMohd Arif
 
Lecture 1 data structures and algorithms
Lecture 1 data structures and algorithmsLecture 1 data structures and algorithms
Lecture 1 data structures and algorithmsAakash deep Singhal
 
data structure
data structuredata structure
data structurehashim102
 
Data and File Structure Lecture Notes
Data and File Structure Lecture NotesData and File Structure Lecture Notes
Data and File Structure Lecture NotesFellowBuddy.com
 
Introductiont To Aray,Tree,Stack, Queue
Introductiont To Aray,Tree,Stack, QueueIntroductiont To Aray,Tree,Stack, Queue
Introductiont To Aray,Tree,Stack, QueueGhaffar Khan
 
Chapter 8: tree data structure
Chapter 8:  tree data structureChapter 8:  tree data structure
Chapter 8: tree data structureMahmoud Alfarra
 
Mca ii dfs u-1 introduction to data structure
Mca ii dfs u-1 introduction to data structureMca ii dfs u-1 introduction to data structure
Mca ii dfs u-1 introduction to data structureRai University
 
Introduction to data structure
Introduction to data structure Introduction to data structure
Introduction to data structure NUPOORAWSARMOL
 
Data structure & its types
Data structure & its typesData structure & its types
Data structure & its typesRameesha Sadaqat
 
Presentation on Data Structure
Presentation on Data StructurePresentation on Data Structure
Presentation on Data StructureA. N. M. Jubaer
 
Introduction to data structure
Introduction to data structureIntroduction to data structure
Introduction to data structureadeel hamid
 

What's hot (20)

Introduction to data structure ppt
Introduction to data structure pptIntroduction to data structure ppt
Introduction to data structure ppt
 
Chapter 1( intro &amp; overview)
Chapter 1( intro &amp; overview)Chapter 1( intro &amp; overview)
Chapter 1( intro &amp; overview)
 
Introduction to data structure
Introduction to data structureIntroduction to data structure
Introduction to data structure
 
Linked Lists
Linked ListsLinked Lists
Linked Lists
 
Data structure
Data structureData structure
Data structure
 
Lecture 1 data structures and algorithms
Lecture 1 data structures and algorithmsLecture 1 data structures and algorithms
Lecture 1 data structures and algorithms
 
data structure
data structuredata structure
data structure
 
Data and File Structure Lecture Notes
Data and File Structure Lecture NotesData and File Structure Lecture Notes
Data and File Structure Lecture Notes
 
Data structure
Data structureData structure
Data structure
 
Data Structures
Data StructuresData Structures
Data Structures
 
Introductiont To Aray,Tree,Stack, Queue
Introductiont To Aray,Tree,Stack, QueueIntroductiont To Aray,Tree,Stack, Queue
Introductiont To Aray,Tree,Stack, Queue
 
Chapter 8: tree data structure
Chapter 8:  tree data structureChapter 8:  tree data structure
Chapter 8: tree data structure
 
Mca ii dfs u-1 introduction to data structure
Mca ii dfs u-1 introduction to data structureMca ii dfs u-1 introduction to data structure
Mca ii dfs u-1 introduction to data structure
 
Introduction to data structure
Introduction to data structure Introduction to data structure
Introduction to data structure
 
Data structure & its types
Data structure & its typesData structure & its types
Data structure & its types
 
Data structure and its types.
Data structure and its types.Data structure and its types.
Data structure and its types.
 
Presentation on Data Structure
Presentation on Data StructurePresentation on Data Structure
Presentation on Data Structure
 
lect 2-DS ALGO(online).pdf
lect 2-DS  ALGO(online).pdflect 2-DS  ALGO(online).pdf
lect 2-DS ALGO(online).pdf
 
Data Structure
Data StructureData Structure
Data Structure
 
Introduction to data structure
Introduction to data structureIntroduction to data structure
Introduction to data structure
 

Similar to Introduction of Data Structures and Algorithms by GOWRU BHARATH KUMAR

Introduction of data structures and algorithms
Introduction of data structures and algorithmsIntroduction of data structures and algorithms
Introduction of data structures and algorithmsVinayKumarV16
 
module-1.pdf. Uooyuf sh kcgfkgkggfjk
module-1.pdf.         Uooyuf sh kcgfkgkggfjkmodule-1.pdf.         Uooyuf sh kcgfkgkggfjk
module-1.pdf. Uooyuf sh kcgfkgkggfjkanil23hr1a0547
 
DataStructurePpt.pptx
DataStructurePpt.pptxDataStructurePpt.pptx
DataStructurePpt.pptxDCABCA
 
1- Introduction.pptx.pdf
1- Introduction.pptx.pdf1- Introduction.pptx.pdf
1- Introduction.pptx.pdfgm6523
 
2. Chapter Two.pdf
2. Chapter Two.pdf2. Chapter Two.pdf
2. Chapter Two.pdffikadumola
 
Module03
Module03Module03
Module03susir
 
DataStructurePpt.pptx
DataStructurePpt.pptxDataStructurePpt.pptx
DataStructurePpt.pptxssuser031f35
 
Business Analytics Project Example
Business Analytics Project ExampleBusiness Analytics Project Example
Business Analytics Project ExampleMBA Capstone Project
 
Unit-1 DataStructure Intro.pptx
Unit-1 DataStructure Intro.pptxUnit-1 DataStructure Intro.pptx
Unit-1 DataStructure Intro.pptxajajkhan16
 
2. Introduction to Data Structure.pdf
2. Introduction to Data Structure.pdf2. Introduction to Data Structure.pdf
2. Introduction to Data Structure.pdfSulabhPawaia
 

Similar to Introduction of Data Structures and Algorithms by GOWRU BHARATH KUMAR (20)

Introduction of data structures and algorithms
Introduction of data structures and algorithmsIntroduction of data structures and algorithms
Introduction of data structures and algorithms
 
Datastructures Notes
Datastructures NotesDatastructures Notes
Datastructures Notes
 
module-1.pdf. Uooyuf sh kcgfkgkggfjk
module-1.pdf.         Uooyuf sh kcgfkgkggfjkmodule-1.pdf.         Uooyuf sh kcgfkgkggfjk
module-1.pdf. Uooyuf sh kcgfkgkggfjk
 
UNIT I - Data Structures.pdf
UNIT I - Data Structures.pdfUNIT I - Data Structures.pdf
UNIT I - Data Structures.pdf
 
Data Abstraction
Data AbstractionData Abstraction
Data Abstraction
 
DataStructurePpt.pptx
DataStructurePpt.pptxDataStructurePpt.pptx
DataStructurePpt.pptx
 
Architecture of dbms
Architecture of dbmsArchitecture of dbms
Architecture of dbms
 
1- Introduction.pptx.pdf
1- Introduction.pptx.pdf1- Introduction.pptx.pdf
1- Introduction.pptx.pdf
 
2. Chapter Two.pdf
2. Chapter Two.pdf2. Chapter Two.pdf
2. Chapter Two.pdf
 
Module03
Module03Module03
Module03
 
Database Concepts
Database ConceptsDatabase Concepts
Database Concepts
 
DBMS Part 1.pptx
DBMS Part 1.pptxDBMS Part 1.pptx
DBMS Part 1.pptx
 
DataStructurePpt.pptx
DataStructurePpt.pptxDataStructurePpt.pptx
DataStructurePpt.pptx
 
Business Analytics Project Example
Business Analytics Project ExampleBusiness Analytics Project Example
Business Analytics Project Example
 
UNIT II.docx
UNIT II.docxUNIT II.docx
UNIT II.docx
 
Data Structures & Algorithms
Data Structures & AlgorithmsData Structures & Algorithms
Data Structures & Algorithms
 
Unit-1 DataStructure Intro.pptx
Unit-1 DataStructure Intro.pptxUnit-1 DataStructure Intro.pptx
Unit-1 DataStructure Intro.pptx
 
Data models
Data modelsData models
Data models
 
Data models
Data modelsData models
Data models
 
2. Introduction to Data Structure.pdf
2. Introduction to Data Structure.pdf2. Introduction to Data Structure.pdf
2. Introduction to Data Structure.pdf
 

More from BHARATH KUMAR

Object-Oriented concepts.pptx
Object-Oriented concepts.pptxObject-Oriented concepts.pptx
Object-Oriented concepts.pptxBHARATH KUMAR
 
history and evaluation of java.pptx
history and evaluation of java.pptxhistory and evaluation of java.pptx
history and evaluation of java.pptxBHARATH KUMAR
 
Structure of a DBMS/Architecture of a DBMS
Structure of a DBMS/Architecture of a DBMSStructure of a DBMS/Architecture of a DBMS
Structure of a DBMS/Architecture of a DBMSBHARATH KUMAR
 
DBMS languages/ Types of SQL Commands
DBMS languages/ Types of SQL CommandsDBMS languages/ Types of SQL Commands
DBMS languages/ Types of SQL CommandsBHARATH KUMAR
 
1.4 data independence
1.4 data independence1.4 data independence
1.4 data independenceBHARATH KUMAR
 
data abstraction in DBMS
data abstraction in DBMSdata abstraction in DBMS
data abstraction in DBMSBHARATH KUMAR
 
Trees and Graphs in data structures and Algorithms
Trees and Graphs in data structures and AlgorithmsTrees and Graphs in data structures and Algorithms
Trees and Graphs in data structures and AlgorithmsBHARATH KUMAR
 
Why we study LMC? by GOWRU BHARATH KUMAR
Why we study LMC? by GOWRU BHARATH KUMARWhy we study LMC? by GOWRU BHARATH KUMAR
Why we study LMC? by GOWRU BHARATH KUMARBHARATH KUMAR
 
A Survey on Big Data Analytics
A Survey on Big Data AnalyticsA Survey on Big Data Analytics
A Survey on Big Data AnalyticsBHARATH KUMAR
 
Relation between Languages, Machines and Computations
Relation between Languages, Machines and ComputationsRelation between Languages, Machines and Computations
Relation between Languages, Machines and ComputationsBHARATH KUMAR
 

More from BHARATH KUMAR (15)

Object-Oriented concepts.pptx
Object-Oriented concepts.pptxObject-Oriented concepts.pptx
Object-Oriented concepts.pptx
 
Java buzzwords.pptx
Java buzzwords.pptxJava buzzwords.pptx
Java buzzwords.pptx
 
history and evaluation of java.pptx
history and evaluation of java.pptxhistory and evaluation of java.pptx
history and evaluation of java.pptx
 
Data Models
Data ModelsData Models
Data Models
 
Structure of a DBMS/Architecture of a DBMS
Structure of a DBMS/Architecture of a DBMSStructure of a DBMS/Architecture of a DBMS
Structure of a DBMS/Architecture of a DBMS
 
DBMS languages/ Types of SQL Commands
DBMS languages/ Types of SQL CommandsDBMS languages/ Types of SQL Commands
DBMS languages/ Types of SQL Commands
 
1.4 data independence
1.4 data independence1.4 data independence
1.4 data independence
 
data abstraction in DBMS
data abstraction in DBMSdata abstraction in DBMS
data abstraction in DBMS
 
File system vs DBMS
File system vs DBMSFile system vs DBMS
File system vs DBMS
 
DBMS introduction
DBMS introductionDBMS introduction
DBMS introduction
 
Trees and Graphs in data structures and Algorithms
Trees and Graphs in data structures and AlgorithmsTrees and Graphs in data structures and Algorithms
Trees and Graphs in data structures and Algorithms
 
Sorting
SortingSorting
Sorting
 
Why we study LMC? by GOWRU BHARATH KUMAR
Why we study LMC? by GOWRU BHARATH KUMARWhy we study LMC? by GOWRU BHARATH KUMAR
Why we study LMC? by GOWRU BHARATH KUMAR
 
A Survey on Big Data Analytics
A Survey on Big Data AnalyticsA Survey on Big Data Analytics
A Survey on Big Data Analytics
 
Relation between Languages, Machines and Computations
Relation between Languages, Machines and ComputationsRelation between Languages, Machines and Computations
Relation between Languages, Machines and Computations
 

Recently uploaded

Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxupamatechverse
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSRajkumarAkumalla
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxupamatechverse
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Call Girls in Nagpur High Profile
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)Suman Mia
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSSIVASHANKAR N
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordAsst.prof M.Gokilavani
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college projectTonystark477637
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxupamatechverse
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINESIVASHANKAR N
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130Suhani Kapoor
 

Recently uploaded (20)

Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptx
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college project
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
 

Introduction of Data Structures and Algorithms by GOWRU BHARATH KUMAR

  • 1. 1 G BHARATH KUMAR, Assistant Professor, CSE Department MODULE 1: INTRODUCTION I. Basic Terminology: Elementary Data Organization: 1. Data: Data are simply values or sets of values.  The word "data" was first used to mean "Transmissible and storable computer information" in 1946. Data Documents: whenever data needs to be registered, data exists in the form of a data documents. Different kinds of data documents include:  data repository  data study  data set  software  data paper  data base  data handbook  data journal etc... Structure: Structure means to purposefully arrange something in a specific way.  Structure is an arrangement and organization of interrelated elements in a system.  The arrangement of and relations between the parts of something complex.  a building or other object constructed from several parts. 2. Data items: 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, and last name. Data items that are not able to divide into sub-items are called Elementary items. Ex: R.No, Gender, Age etc... 3. Entity: An entity can be a real-world object, either animate or inanimate, that can be easily Identifiable. The values may be either numeric or non-numeric. Attributes- Names, Age, Sex, SSN Values- Rohland Gail, 34, F, 134-34-5533 For Example, in a college data base students, Staff, classes and courses offered can be considered as entities. All these entities have some attributes that give them their identity. 4. Field is a single elementary unit of information representing an attribute of an entity. 5. Record is the collection of field values of a given entity.
  • 2. 2 G BHARATH KUMAR, Assistant Professor, CSE Department 6. File is the collection of records of the entities in a given entity set. Each record in a file may contain many field items but 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, ….. in such a field are called keys or key values. 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. 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. 7. Data Structures Data may be organized in many different ways. The logical or mathematical model of a particular organization of data is called a data structure. The choice of a particular data model depends on the two considerations 1. It must be rich enough in structure to mirror the actual relationships of the data in the real world. 2. The structure should be simple enough that one can effectively process the data whenever necessary. In computer science, a data structure is a data organization, management, and storage format that enables efficient access and modification. More precisely, a data structure is a collection of data values, the relationships among them, and the functions or operations that can be applied to the data. 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 Structures Usage Data structures serve as the basis for abstract data types (ADT). The ADT defines the logical form of the data type. The data structure implements the physical form of the data type. Different types of data structures are suited to different kinds of applications, and some are highly specialized to specific tasks. For example, relational databases commonly use B-tree indexes for data retrieval, while compiler implementations usually use hash tables to look up identifiers.
  • 3. 3 G BHARATH KUMAR, Assistant Professor, CSE Department Data structures provide a means to manage large amounts of data efficiently for uses such as large databases and internet indexing services. Usually, efficient data structures are key to designing efficient algorithms. Some formal design methods and programming languages emphasize data structures, rather than algorithms, as the key organizing factor in software design. Data structures can be used to organize the storage and retrieval of information stored in both main memory and secondary memory. Data Structures Implementation Data structures are generally based on the ability of a computer to fetch and store data at any place in its memory, specified by a pointer—a bit string, representing a memory address, that can be itself stored in memory and manipulated by the program. Thus, the array and record data structures are based on computing the addresses of data items with arithmetic operations, while the linked data structures are based on storing addresses of data items within the structure itself. The implementation of a data structure usually requires writing a set of procedures that create and manipulate instances of that structure. The efficiency of a data structure cannot be analyzed separately from those operations. This observation motivates the theoretical concept of an abstract data type, a data structure that is defined indirectly by the operations that may be performed on it, and the mathematical properties of those operations (including their space and time cost). CLASSIFICATION OF DATA STRUCTURES Data structures are generally classified into  Primitive data Structures  Non-primitive data Structures 1. Primitive data Structures: Primitive data structures are the fundamental data types which are supported by a programming language. Basic data types such as integer, real, character and Boolean are known as Primitive data Structures. These data types consists of characters that cannot be divided and hence they also called simple data types. 2. Non- Primitive data Structures: Non-primitive data structures are those data structures which are created using primitive data structures. Examples of non-primitive data structures is the processing of complex numbers, linked lists, stacks, trees, andgraphs. Based on the structure and arrangement of data, non-primitive data structures is further classified into 1. Linear Data Structure 2. Non-linear Data Structure 1. Linear Data Structure: A data structure is said to be linear if its elements form a sequence or a linear list. There are basically two ways of representing such linear structure in memory. 1. One way is to have the linear relationships between the elements represented by means of sequential memory location. These linear structures are called arrays. 2. The other way is to have the linear relationship between the elements represented by
  • 4. 4 G BHARATH KUMAR, Assistant Professor, CSE Department means of pointers or links. These linear structures are called linked lists. The common examples of linear data structure are Arrays, Queues, Stacks, Linked lists 2. Non-linear Data Structure: A data structure is said to be non-linear if the data are not arranged in sequence or a linear. The insertion and deletion of data is not possible in linear fashion. This structure is mainly used to represent data containing a hierarchical relationship between elements. Trees and graphs are the examples of non-linear data structure. Abstract Data Types Abstract Data type (ADT) is a type (or class) for objects whose behaviour is defined by a set of value and a set of operations. The definition of ADT only mentions what operations are to be performed but not how these operations will be implemented. It does not specify how data will be organized in memory and what algorithms will be used for implementing the operations. It is called ―abstract‖ because it gives an implementation-independent view. The process of providing only the essentials and hiding the details is known as abstraction. The user of data type does not need to know how that data type is implemented, for example, we have been using Primitive values like int, float, char data types only with the knowledge that these data type can operate and be performed on without any idea of how they are implemented. So a user only needs to know what a data type can do, but not how it will be implemented. Think of ADT as a black box which hides the inner structure and design of the data type. Trees Data frequently contain a hierarchical relationship between various elements. The data structure which reflects this relationship is called a rooted tree graph or a tree. Some of the basic properties of tree are explained by means of examples Example 1: Record Structure Although a file may be maintained by means of one or more arrays a record, where one indicates both the group items and the elementary items, can best be described by means of a tree structure. For example, an employee personnel record may contain the following data items: Social Security Number, Name, Address, Age, Salary, Dependents
  • 5. 5 G BHARATH KUMAR, Assistant Professor, CSE Department However, Name may be a group item with the sub-items Last, First and MI (middle initial). Also Address may be a group item with the subitems Street address and Area address, where Area itself may be a group item having subitems City, State and ZIP codenumber. This hierarchical structure is pictured below Another way of picturing such a tree structure is in terms of levels, as shown below Some of the data structures are briefly described below. 1. Stack: A stack, also called a fast-in first-out (LIFO) system, is a linear list in which insertions and deletions can take place only at one end, called the top. This structure is similar in its operation to a stack of dishes on a spring system as shown in fig. Note that new 4 dishes are inserted only at the top of the stack and dishes can be deleted only from the top of the Stack.
  • 6. 6 G BHARATH KUMAR, Assistant Professor, CSE Department
  • 7. 7 G BHARATH KUMAR, Assistant Professor, CSE Department 2. Queue: A queue, also called a first-in first-out (FIFO) system, is a linear list in which deletions can take place only at one end of the list, the "from'' of the list, and insertions can take place only at the other end of the list, the ―rear‖ of the list. This structure operates in much the same way as a line of people waiting at a bus stop, as pictured in Fig. the first person in line is the first person to board the bus. Another analogy is with automobiles waiting to pass through an intersection the first car in line is the first car through. 3. Graph: Data sometimes contain a relationship between pairs of elements which is not necessarily hierarchical in nature. For example, suppose an airline flies only between the cities connected by lines in Fig. The data structure which reflects this type of relationship is called a graph.
  • 8. 8 G BHARATH KUMAR, Assistant Professor, CSE Department II. DATA STRUCTURES OPERATIONS The data appearing in data structures are processed by means of certain operations. The following four operations play a major role in thistext: 1. Traversing: accessing each record/node exactly once so that certain items in the record may be processed. (This accessing and processing is sometimes called ―visiting‖ the record.) 2. Searching: Finding the location of the desired node with a given key value, or finding the locations of all such nodes which satisfy one or more conditions. 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. V Space-Time Trade-off Types of Space-Time Trade-off  Compressed or Uncompressed data  Re Rendering or Stored images  Smaller code or loop unrolling  Lookup tables or Recalculation Compressed or Uncompressed data: A space-time trade-off can be applied to the problem of data storage. If data stored is uncompressed, it takes more space but less time. But if the data is stored compressed, it takes less space but more time to run the decompression algorithm. There are many instances where it is possible to directly work with compressed data. In that case of compressed bitmap indices, where it is faster to work with compression than without compression. Re-Rendering or Stored images: In this case, storing only the source. rendering it as an image would take more space but less time i.e., storing an image in the cache is faster than re-rendering but requires more space in memory. Smaller code or Loop Unrolling(larger code- without loops): Smaller code occupies less space in memory but it requires high computation time that is required for jumping back to the beginning of the loop at the end of each iteration.
  • 9. 9 G BHARATH KUMAR, Assistant Professor, CSE Department Loop unrolling can optimize execution speed at the cost of increased binary size. It occupies more space in memory but requires less computation time. Lookup tables or Recalculation: In a lookup table, an implementation can include the entire table which reduces computing time but increases the amount of memory needed. It can recalculate i.e., compute table entries as needed, increasing computing time but reducing memory requirements. Searching Algorithms Searching-  Searching is a process of finding a particular element among several given elements.  The search is successful if the required element is found.  Otherwise, the search is unsuccessful. Searching Algorithms- Searching Algorithms are a family of algorithms used for the purpose of searching.
  • 10. 10 G BHARATH KUMAR, Assistant Professor, CSE Department The searching of an element in the given array may be carried out in the following two ways- 1. Linear Search 2. Binary Search In this article, we will discuss about Linear Search Algorithm. VI. Linear Search  Linear Search is the simplest searching algorithm.  It traverses the array sequentially to locate the required element.  It searches for an element by comparing it with each element of the array one by one.  So, it is also called as Sequential Search. Linear Search Algorithm is applied when-  No information is given about the array.  The given array is unsorted or the elements are unordered.  The list of data items is smaller. Linear Search Algorithm- Consider-  There is a linear array ‗a‘ of size ‗n‘.  Linear search algorithm is being used to search an element ‗item‘ in this linear array.  If search ends in success, it sets loc to the index of the element otherwise it sets loc to -1. In computer science, a linear search or sequential search is a method for finding an element within a list. It sequentially checks each element of the list until a match is found or the whole list has been searched.[1]
  • 11. 11 G BHARATH KUMAR, Assistant Professor, CSE Department A linear search runs in at worst linear time and makes at most n comparisons, where n is the length of the list. If each element is equally likely to be searched, then linear search has an average case of n+1/2 comparisons, but the average case can be affected if the search probabilities for each element vary. Linear search is rarely practical because other search algorithms and schemes, such as the binary search algorithm and hash tables, allow significantly faster searching for all but short lists.[2] Linear search is a very simple search algorithm. In this type of search, a sequential search is made over all items one by one. Every item is checked and if a match is found then that particular item is returned, otherwise the search continues till the end of the data collection. Algorithm Linear Search ( Array A, Value x) Step 1: Set i to 1 Step 2: if i > n then go to step 7 Step 3: if A[i] = x then go to step 6 Step 4: Set i to i + 1 Step 5: Go to Step 2 Step 6: Print Element x Found at index i and go to step 8 Step 7: Print element not found Step 8: Exit Pseudocode procedure linear_search (list, value) for each item in the list if match item == value return the item's location end if end for end procedure A simple approach is to do a linear search, i.e  Start from the leftmost element of arr[] and one by one compare x with each element of arr[]  If x matches with an element, return the index.  If x doesn‘t match with any of elements, return -1. Note: Linear search is rarely used practically because other search algorithms such as the binary search algorithm and hash tables allow significantly faster-searching comparison to Linear search.
  • 12. 12 G BHARATH KUMAR, Assistant Professor, CSE Department Linear Search vs Binary Search A linear search scans one item at a time, without jumping to any item . 1. The worst case complexity is O(n), sometimes known an O(n) search 2. Time taken to search elements keep increasing as the number of elements are increased. A binary search however, cut down your search to half as soon as you find middle of a sorted list. 1. The middle element is looked to check if it is greater than or less than the value to be searched. 2. Accordingly, search is done to either half of the given list Important Differences  Input data needs to be sorted in Binary Search and not in Linear Search  Linear search does the sequential access whereas Binary search access data randomly.  Time complexity of linear search -O(n) , Binary search has time complexity O(log n).  Linear search performs equality comparisons and Binary search performs ordering comparisons Class Search algorithm Worst-case performance O(n) Best-case performance O(1) Average performance O(n/2) Worst-case space complexity O(1) iterative #include<stdio.h> int main() { int a[20],i,x,n; printf("How many elements?"); scanf("%d",&n); printf("Enter array elements:n"); for(i=0;i<n;++i) scanf("%d",&a[i]); printf("nEnter element to search:"); scanf("%d",&x); for(i=0;i<n;++i) if(a[i]==x) break; if(i<n)
  • 13. 13 G BHARATH KUMAR, Assistant Professor, CSE Department printf("Element found at index %d",i); else printf("Element not found"); return 0; } Complexity of the Linear Search Algorithm VII Binary Search-  Binary Search is one of the fastest searching algorithms.  It is used for finding the location of an element in a linear array.  It works on the principle of divide and conquer technique. Binary Search Algorithm can be applied only on Sorted arrays. So, the elements must be arranged in-  Either ascending order if the elements are numbers.  Or dictionary order if the elements are strings. To apply binary search on an unsorted array,  First, sort the array using some sorting technique.  Then, use binary search algorithm. Binary Search Algorithm- Consider-  There is a linear array ‗a‘ of size ‗n‘.  Binary search algorithm is being used to search an element ‗item‘ in this linear array.  If search ends in success, it sets loc to the index of the element otherwise it sets loc to -1.  Variables beg and end keeps track of the index of the first and last element of the array or sub array in which the element is being searched at that instant.  Variable mid keeps track of the index of the middle element of that array or sub array in which the element is being searched at that instant. Then, Binary Search Algorithm is as follows- Begin Set beg = 0 Set end = n-1 Set mid = (beg + end) / 2 while ( (beg <= end) and (a[mid] ≠ item) ) do if (item < a[mid]) then Set end = mid - 1 else Set beg = mid + 1 endif Set mid = (beg + end) / 2
  • 14. 14 G BHARATH KUMAR, Assistant Professor, CSE Department endwhile if (beg > end) then Set loc = -1 else Set loc = mid endif End Explanation Binary Search Algorithm searches an element by comparing it with the middle most element of the array. Then, following three cases are possible- Case-01 If the element being searched is found to be the middle most element, its index is returned. Case-02 If the element being searched is found to be greater than the middle most element, then its search is further continued in the right sub array of the middle most element. Case-03 If the element being searched is found to be smaller than the middle most element, then its search is further continued in the left sub array of the middle most element. This iteration keeps on repeating on the sub arrays until the desired element is found or size of the sub array reduces to zero. Time Complexity Analysis- Binary Search time complexity analysis is done below-  In each iteration or in each recursive call, the search gets reduced to half of the array.  So for n elements in the array, there are log2n iterations or recursive calls. Thus, we have- Time Complexity of Binary Search Algorithm is O(log2n).
  • 15. 15 G BHARATH KUMAR, Assistant Professor, CSE Department Here, n is the number of elements in the sorted linear array. This time complexity of binary search remains unchanged irrespective of the element position even if it is not present in the array. Binary Search Example- Consider-  We are given the following sorted linear array.  Element 15 has to be searched in it using Binary Search Algorithm. Binary Search Algorithm works in the following steps- Step-01:  To begin with, we take beg=0 and end=6.  We compute location of the middle element as- mid = (beg + end) / 2 = (0 + 6) / 2 = 3  Here, a[mid] = a[3] = 20 ≠ 15 and beg < end.  So, we start next iteration. Step-02:  Since a[mid] = 20 > 15, so we take end = mid – 1 = 3 – 1 = 2 whereas beg remains unchanged.  We compute location of the middle element as- mid = (beg + end) / 2 = (0 + 2) / 2
  • 16. 16 G BHARATH KUMAR, Assistant Professor, CSE Department = 1  Here, a[mid] = a[1] = 10 ≠ 15 and beg < end.  So, we start next iteration. Step-03:  Since a[mid] = 10 < 15, so we take beg = mid + 1 = 1 + 1 = 2 whereas end remains unchanged.  We compute location of the middle element as- mid = (beg + end) / 2 = (2 + 2) / 2 = 2  Here, a[mid] = a[2] = 15 which matches to the element being searched.  So, our search terminates in success and index 2 is returned. Binary Search Algorithm Advantages- The advantages of binary search algorithm are-  It eliminates half of the list from further searching by using the result of each comparison.  It indicates whether the element being searched is before or after the current position in the list.  This information is used to narrow the search.  For large lists of data, it works significantly better than linear search. Binary Search Algorithm Disadvantages- The disadvantages of binary search algorithm are-  It employs recursive approach which requires more stack space.  Programming binary search algorithm is error prone and difficult.  The interaction of binary search with memory hierarchy i.e. caching is poor. (because of its random access nature) Important Note- For in-memory searching, if the interval to be searched is small,  Linear search may exhibit better performance than binary search.  This is because it exhibits better locality of reference.