Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
10 views

Introduction To Data Structures

This document provides an introduction to data structures using C. It covers topics like the classification of data structures as primitive vs non-primitive and simple vs compound. Array is presented as a simple data structure. The document discusses algorithm complexity analysis in terms of time and space. It provides examples of traversing, inserting, and deleting elements in an array. The objectives are to explain data structures, classifications, algorithm complexity, and array operations.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Introduction To Data Structures

This document provides an introduction to data structures using C. It covers topics like the classification of data structures as primitive vs non-primitive and simple vs compound. Array is presented as a simple data structure. The document discusses algorithm complexity analysis in terms of time and space. It provides examples of traversing, inserting, and deleting elements in an array. The objectives are to explain data structures, classifications, algorithm complexity, and array operations.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 43

Data Structures Using C

Unit 1: Introduction to Data


Structures
Topics Covered

2
Topics

• The topics covered are:

• Data structure

• Classification of data structure

• Algorithm complexity

• Arrays

• String processing

3
Objectives

4
Objectives

• After studying this module, you will be able to:

• Explain the use of data structures

• Identify different classifications of data structure

• Discuss the different algorithm complexities

• Explain the insertion and deletion operation in an array

5
Introduction

6
Introduction

• Data is needed to perform operations in a computer.

• Data can be:

• Numbers

• Alphabets

• Symbols

• These data has to be stored in memory.


Data structure

8
Data Structures

• Definition:

• “A data structure is an arrangement of data in a computer's memory or even

disk storage. It has a different way of storing and organizing data in a

computer so that it can be used efficiently”

• Increase in quantity of data affects proper storage.

• Data structures helps in storing data in a well-organized manner in

the memory
Classification of Data Structure

10
Primitive and Non-Primitive

• Primitive data structures:

• Primitive data types

• Available in programming languages

• E.g. integer, Boolean, double, float, character, etc.

• Non-primitive data structures:

• Derived from primitive data types

• Examples are arrays, records, etc.

11
Simple and Compound Data Structure
Simple Data Structures
• They are built from primitive data types like integer, Boolean,

character, float, etc.

• It is available as a built-in component in programming languages.

• Example:

• Arrays

• Pointers
Compound Data Structures
• They are formed from simple data structures

• Two types of Compound data structures:

• Linear Data Structure

• Non-linear Data Structure


Linear Data Structure
• Single-level data organization

• Continuous allocation in memory

• 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

• Data and data item

• Data can be a value or a set of values.

• Data item is a single value.

• Data types and Variables

• Data types are used to identify the type of data

• Variables can hold data of different data types

18
Elementary Data Organization
• Record

• Collection of data items.

• Set of elements called fields or members.

• Key

• Contains a unique value

• Entity and Entity Set

• An entity will have a set of properties.

• Entity set is a group of similar entities


19
Elementary Data Organization

• File:

• A collection of records of the entities in a given entity set is known as a file.

• Initially the data was organized in variables, records, files, etc.

20
Advantages of Data Structure

• High level of data organization

• Data can be accessed and stored in its elementary level

• Allows operations like looking up priority, adding new data, deleting

new data, etc.

• Easy data searching and sorting

• Efficient data management

21
Time and Space Complexity of an
Algorithm

22
Algorithm Efficiency

• Amount of resources used shows algorithm’s efficiency.

• Different types of efficiencies can exist for the algorithm:

• Worst case efficiency: maximum number of steps

• Average case efficiency: The efficiency that is averaged on all possible inputs.

• Best case efficiency: minimum number of steps

23
Time and Space Complexity
• Time complexity shows the amount of time an algorithm needs to run. Time

can mean:

• Number of memory accesses performed

• Number of comparisons between integers

• Number of times the loop is executed

• Space complexity shows the amount of space an algorithm needs to run

• Algorithm complexity is represented with O(f) notation or asymptotic

notation or Big O notation.

24
Complexities

25
Arrays

26
Introduction
• Array is a collection of homogenous data elements.

• It is a simple linear data structure

• An index is used to identify each element in an array


Attributes of an Array

• An Array will have the following attributes:

• Array Name

• Index

• Size

• Data elements
Declaring and Initializing Arrays

• Declaring an

array:

data_type

arrayName[];
Representation of Linear Array in Memory

• Memory has a sequence of locations

where you can store data.

• Each location has an address


Representation of Linear Array in Memory

• The computer needs the following

information to store an array:

• Starting address of memory

• The size of the array

• 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

2. Set counter as the lower bound value, C = Lower_Bound

3. Repeat steps 4 and 5 till counter equals the upper bound

4. Visit element arrayName[C]

5. Increment counter by 1, C = C + 1

[End of step 3 loop]

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:2- Repeat step 3 & 4 while (J>=K)

Step:3- [Move Jth element downward] Set LA[J+1]=LA[J]

Step:4- [Decrease counter]Set J=J-1


[End of step 2 loop]
Step:5- [Insert element]Set LA[K]=ITEM

Step:6-[Reset N] Set N=N+1

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]

Step:2- Repeat for J=K to N-1


[Move J+1st element upward] set LA[J]=LA[J+1]
[end of loop]

Step:3- [Reset the number N of element in LA] Set N=N-1


Step:4- Exit
Summary

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

files were used.

• There are different types of data structure – simple and compound.

• Algorithm has different complexities based on the number of inputs.

• Complexities can be linked with either time or space.

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

• Weiss, Data Structures and Algorithm Analysis in C, II Edition, Pearson Education,


2001
• Lipschutz: Schaum’s outline series Data structures Tata McGraw-Hill
• Robert Kruse Data Structures and program designing using ‘C’
• Trembley and Sorenson Data Structures
• E. Balaguruswamy Programming in ANSI C.
• Bandyopadhyay, Data Structures Using C Pearson Education, 1999
• Tenenbaum, Data Structures Using C. Pearson Education, 200
• Kamthane: Introduction to Data Structures in C. Pearson Education 2005.
• Hanumanthappa M., Practical approach to Data Structures, Laxmi Publications,
Fire Wall media 2006
• Langsam, Ausenstein Maoshe & M. Tanenbaum Aaron Data Structures using C
and C++ Pearson Education

43

You might also like