Вы находитесь на странице: 1из 40

Chapter 1.

1 | Basics of Data
Structure

1.1 Basics of Data


Structures

Data Structures and Algorithms


Semester III

Introduction to Data Structures


1 1
Module

Chapter 1.1 | Basics of Data


Structures

Aim
To learn basic characteristics of
standard data structures and
learn algorithms used by those
data structures

Data Structures and Algorithms


Semester III

Data Structures and Algorithms


2
Semester III

Instructional
Objectives
Objectives of this chapter are:
Explain the role of Data Structures in
Computer Science.
Describe the different types and
classification of Data Structures and the
concept of Elementary Data Organization.
Explain the concept of Time and Space
Complexity of an algorithm.
Describe the different memory allocation
techniques.
How to access the address of a variable?
3

Introduction to Data Structures

Introduction to Data Structures


What is a Data Structure?
Examples of data structures:
Arrays, Linked Lists
Data structures as ADT
5

Quiz/Assessment
1) What are the characteristics of data
structures which differ them from others?
2) Why dynamic data structures such as linked
lists are preferred over static array-based
data structures?
3) Linear data structures are the ones in which
elements are not arranged sequentially.
a) True
b) False
7

Types of Data Structures

Types of Data Structures

A data structure can be broadly


classified into:
(i) Primitive data structure
(ii) Non-primitive data structure

Types of Data Structures


There are two types of nonprimitive data structures.
(i) Linear data structure
(ii) Non-linear data structure

10

Types of Data Structures


Linear data structure
Eg: Linked Lists
Linked lists
Eg. Single linked lists and Double
linked lists
11

Types of Data Structures


A list has two subsets. They are: (i) Stack
(ii) Queue

12

Types of Data Structures


Non-linear data structure
Eg: Trees and Graphs

13

Quiz/Assessment
4) Differentiate between linear data structures and
non-linear data structures.
5) Graphs maintains random relationship or point-topoint relationship between various elements.
a) True
b) False
6) Stack is a _____ system whereas a queue is a _____
system.
a)
b)
c)
d)

first in first out, last in last out


last in first out, first in first out
last in last out, first in first out
first in last out, last in first out
14

Elementary Data
Organization

15

Elementary Data
Organization

Data
Data item
Entity
Entity Set
Information
Field
Record
File
Key
16

Time and Space


Complexity

17

Time and Space


Complexity
There are two main complexity
measures of the efficiency of an
algorithm:
(i) Time Complexity
(ii) Space Complexity

18

Time and Space


Complexity
Time Complexity
Space Complexity

19

Time and Space


Complexity
Asymptotic Notation
(i) Big Oh Notation,
(ii) Omega Notation,
(iii)Theta Notation,

20

Time and Space


Complexity
Big Oh Notation,

21

Time and Space


Complexity
Omega Notation,

22

Time and Space


Complexity
Theta Notation,

23

Quiz/Assessment
7) Define space complexity and time complexity
with respect to algorithms.
8) Name the three asymptotic notations that are
used to represent time complexity of
algorithms.
9) When determining the efficiency of algorithm
the time factor is measured by
a) Counting microseconds
b) Counting the number of key operations
c) Counting the number of statements
d) Counting the kilobytes of algorithm
24

String Processing

25

String Processing
Commonly used string handling
functions are:
Strlen()
Strcpy()
Strcat()
Strcmp()
Strlwr()
Strupr()
26

Memory Allocation

27

Memory Allocation
Memory allocation has two core types:
1. Static Memory Allocation
2. Dynamic Memory Allocation

28

Memory Allocation
Static Memory Allocation
Dynamic Memory Allocation

29

Memory Allocation
Dynamic Memory Allocation
Dynamic memory allocation is when an
executing program requests that the operating
system give it a block of main memory.
It enables us to create data types and
structures of any size and length to suit our
programs need within the program.
Memory Fragmentation occurs when small
holes of memory are formed which cannot be
used to fulfil the dynamic requests.
30

Quiz/Assessment
10)What is string processing? List some string
handling functions.
11)State and explain how memory allocation
takes during program execution.
12)List and explain the advantages and
disadvantages of static memory allocation
and dynamic memory allocation.
13)Explain how the situation of memory
fragmentation arises in memory allocation.
31

Accessing the address of a


variable

32

Accessing the address of a


variable
The address of a variable can be
obtained by preceding the name of a
variable with an ampersand sign (&),
known as address-of operator.

33

Quiz/Assessment
14) Consider the following code
fragment:
1-> myvar = 35;
2-> foo = &myvar;
3-> bar = myvar;
Explain the significance of & operator in
line 2 of the code fragment and also
explain what happens in line 1 and line
3 of the code fragment when compared
with line 2 of the code fragment.
34

Quiz/Assessment
15)What is the role of & operator
in C?
16)What are pointers in C?

35

Activity
Description:
Divide the students into two
groups. Given selection sort
algorithm and insertion sort
algorithm to each of the
groups, students should
calculate time complexities for
both these algorithms.
36

Summary
Data Structure is a way of collecting and organising
data in such a way that we can perform operations
on these data in an effective way.
Data structures are categorized into two types:
linear and nonlinear.
Linear data structures are the ones in which elements are
arranged in a sequence, nonlinear data structures are the
ones in which elements are not arranged sequentially.

The complexity of an algorithm is a function


describing the efficiency of the algorithm in terms of
the amount of data the algorithm must process.

37

E-References
Introduction to data structures
https://www.youtube.com/watch?
v=92S4zgXN17o&list=PL2_aWCzGMAwI3W_JlcBbtYTwiQSsOTa6P
Data Structures: List as abstract data type
https://www.youtube.com/watch?
v=HdFG8L1sajw&list=PL2_aWCzGMAwI3W_JlcBbtYTwiQSsOTa6P&index=2
Data Structures: Arrays vs Linked Lists
https://www.youtube.com/watch?
v=lCyYCOnN8Q&index=4&list=PL2_aWCzGMAwI3W_JlcBbtYTwiQSsOTa6P
Introduction to asymptotic notations
https://www.youtube.com/watch?
v=aGjL7YXI31Q&list=PLEbnTDJUr_IeHYw_sfBOJ6gk5pie0yP-0

38

E-References
Time complexity Analysis of iterative programs
https://www.youtube.com/watch?
v=FEnwMiDb2g&list=PLEbnTDJUr_IeHYw_sfBOJ6gk5pie0yP-0&index=2
Time analysis of recursive program
https://www.youtube.com/watch?
v=gCsfk2ei2R8&index=3&list=PLEbnTDJUr_IeHYw_sfBOJ6gk5pie0yP-0
Analysing Space complexity of iterative and recursive algorithms
https://www.youtube.com/watch?
v=HEjmH9wKiMo&list=PLEbnTDJUr_IeHYw_sfBOJ6gk5pie0yP-0&index=6
Memory Allocation
https://www.youtube.com/watch?v=Dml54J3Kwm4
https://www.cs.utexas.edu/users/djimenez/utsa/cs1723/lecture2.html
http://www.compsci.hunter.cuny.edu/~sweiss/resources/cstrings.pdf
39

External Resources
Data Structures and program
designing using C by Robert Kruse.
Data Structures and Algorithm
Analysis in C by Wiess
Data structures in C by D. Srivastava

40

Вам также может понравиться