Introduction To Data Structures
Introduction To Data Structures
2
Topics
• Data structure
• Algorithm complexity
• Arrays
• String processing
3
Objectives
4
Objectives
5
Introduction
6
Introduction
• Numbers
• Alphabets
• Symbols
8
Data Structures
• Definition:
the memory
Classification of Data Structure
10
Primitive and Non-Primitive
11
Simple and Compound Data Structure
Simple Data Structures
• They are built from primitive data types like integer, Boolean,
• Example:
• Arrays
• Pointers
Compound Data Structures
• They are formed from simple data structures
• Examples:
• Stack
• List
• Queue
• Linked list
Non-linear Data Structure
• Data is randomly stored in memory and linked using pointers.
• Examples:
• Trees
• Graphs
• Decision trees
Elementary Data Organization
17
Elementary Data Organization
18
Elementary Data Organization
• Record
• Key
• File:
20
Advantages of Data Structure
21
Time and Space Complexity of an
Algorithm
22
Algorithm Efficiency
• Average case efficiency: The efficiency that is averaged on all possible inputs.
23
Time and Space Complexity
• Time complexity shows the amount of time an algorithm needs to run. Time
can mean:
24
Complexities
25
Arrays
26
Introduction
• Array is a collection of homogenous data elements.
• Array Name
• Index
• Size
• Data elements
Declaring and Initializing Arrays
• Declaring an
array:
data_type
arrayName[];
Representation of Linear Array in Memory
• Length=UB-LB+1
Applications of array
• Given a list of test scores, determine the maximum and minimum scores.
• Read in a list of student names and rearrange them in alphabetical order
(sorting).
• Given the height measurements of students in a class, output the names of
those students who are taller than average.
Programs using array
1) Finding Largest element.
2) Finding Smallest element
3) Search an element.
4) Sorting all elements
Operations on array:
Insertion, deletion, sorting ,searching, mergeing,traversing .
32
© iNurture Education Solutions Pvt. Ltd., INDIA. 2014-15. All rights reserved
Traversing Linear Array
1. Initialize a counter, C
5. Increment counter by 1, C = C + 1
6. Exit
Insertion and Deletion in an Array
numbers[3] = 4
Algo for Traversing an Array
TRAVARR(A,N)
// A is a one –D Array of size N. in traversing we have to process each
element at least once. i is my index variable.
Step-1: Set i=0
Step-2: Repeat Step- 3 & 4 While(i<N)
Step-3: Process/Display A[i]
Step-4: Set i=i+1
Step-5: Stop
Algo to Insert a new Element in Array At
Specified Position
INSERT(LA,N,K,ITEM) Here LA is a linear array with N elements and K is a
positive integer such that K<=N . This algorithm insert ITEM INTO the kth
position in LA.
Step:1- Set J=N
Step:7- Exit
Algo to Delete a data Element from Array
DELETE(LA,N,K,ITEM)
Here LA is a linear array with N elements and K is a positive integer such
that K<=N . This algorithm deletes the kth element from LA.
Step:1- Set ITEM:= LA[K]
38
Summary
• Data structure organizes data in such a way that it is easy to manipulate the
data.
• Searching and sorting the data structure is easier than when records and
39
Self Evaluating Questions
40
Questions
• Two Marks Questions
• What is data structure?
• Explain differences between primitive and non-primitive data types
• Give a note on primitive data structure
• Explain time and space complexity
• What is an array and how is it represented?
• Five Marks Questions
• Explain different complexities with example
• Give a note on the classifications of data structure.
• Give a note on algorithm complexity
• Explain insertion and deletion operation in an array.
• How will you traverse an array?
41
References
42
References
43