SlideShare a Scribd company logo
Chapter – 1 Introduction to Data Structures
Asmelash Girmay
Department of Information Technology
Data Structures
The Need of Data Structure
• Helps to understand relationship one data element with other and
organize it within the memory. Example:
• Months of a year: one month after the other can be linked
• Thus knowing the starting and ending month name could help to know the other months
• Specific department of a university can be represented in a tree
• Example: IT
IT3201 Data Structures 22018-10-30
Data Representation
• Various methods are used to represent data in Computers
• Example: hierarchal data representation
• Bit – basic unit of data representation
• Byte – combination of 8 bits
• In ASCII code representation 1 byte represents a character
• One or more characters are used to form a string
• String: is a data structure that emerges through several layers of data structures.
IT3201 Data Structures 32018-10-30
Integer Representation
• Int: -2n-1 to 2n-1 - 1 using n-number of bits
• Non-negative int represented using binary number system
• Each bit position represents power of 2, where the right most bit represents 20 = 1
• Example: 00100110 represents 21 + 22 + 25 = 2 + 4 + 32 = 38.
• Negative int represented using one’s complement and two’s complement
• One’s complement complements each bit, e.g. -38 = 11011001
• Two’s complement adds to the one’s complement of a number, e.g. -38 = 11011010
IT3201 Data Structures 42018-10-30
Real Number Representation
• Float: m*nr => -3.4*1038 to 3.4*1038
• A real number is represented by mantissa and exponent. E.g.,
• 43.56 can be represented as 4356 * 10-2 , where 4356 – mantissa, -2 exponent
• Both mantissa and exponent are two’s complement of binary
integers. E.g.
• 4356 = 0001000100000100, and -2 = 1111 1110 (8 – bit representation)
• 43.56 = 0001 0001 0000 0100 1111 1110
IT3201 Data Structures 52018-10-30
Character Representation
• Char: [0-9, a-z, A-Z] + other symbols = 2n chars, for n-number of bits
• Codes to represent characters are BCD, EBCDIC, ASCII
• ASCII is commonly used
• If 8 bits used to represent a character, 28 = 256 characters can be represented
• E.g., If character ‘A’ represented with 0100 0001 and ‘B’ with 0100 0010, then
“AB” can be represented with 0100 0001 0100 0010, which is a string
IT3201 Data Structures 62018-10-30
Abstract Data Types (ADTs)
• ADT is the mathematical model of data objects
• Specifies logical & mathematical properties of a data type and its operations
• ADT is useful as a guideline to implement a data type.
• In ADT, no implementation
• Two steps in ADT
1. Description of the way in which components are related to each other.
2. Statements of operations that can be performed on that data type.
IT3201 Data Structures 72018-10-30
Abstract Data Types (ADTs)...
• Example: in C, to implement integer data type, INTEGER_ADT defines:
• Range of numbers that will be represented
• Formats for storing the integer numbers
• Operations on it, such as addition, subtraction, division, multiplication,
modulo
IT3201 Data Structures 82018-10-30
Data Type
• A method of interpreting a bit pattern.
• It’s the implementation of the mathematical model specified by an ADT.
• It is an internal representation of data in the memory.
• Once ADT specification is done, a data type can then be implemented in:
• Hardwire – Circuitry as part of a computer
• Software – using the existing hard wired instructions
IT3201 Data Structures 92018-10-30
Data Structure Types
IT3201 Data Structures 102018-10-30
Review on C
This course uses C to implement data structures
IT3201 Data Structures 112018-10-30
Function
• A section of program, separately written from main program for:
• Reusability, readability, and/or modularity of software program.
• Function is a way of modularizing and organizing program.
• Function has much emphasis on procedural-oriented programming such as C.
• We can define a function in C in 4 ways.
• A function – with return type and argument/s [WRWA]
• A function – with return type but no arguments [WRNA]
• A function – with no return type but with arguments [NRWA]
• A function – with no return type and no arguments [NRNA]
KEY: R-return type, A – Argument lists, W – With, and N – No
IT3201 Data Structures 122018-10-30
Function…
IT3201 Data Structures 132018-10-30
Array
• Array is a derived data type, from basic data types like int, float, char, etc.
• It is used to store more than one data of same types at a time. E.g.,
• float StudentsGrade [57];
• It stores data in indexing form, where indexing starts at 0 (zero).
• It is also a data structure, but built-in and stores fixed-size sequential collection of
elements of same type.
• There are one-dimensional arrays, two-dimensional arrays, and three or above
dimensional arrays.
IT3201 Data Structures 142018-10-30
Structures
• A structure is a user-defined derived data type which allows you to
combine data items of different kinds/types.
• Used to store/represent a record as in a database table. E.g.,
• Attributes of a book:
• Title,
• Author,
• Subject,
• BookId
IT3201 Data Structures 152018-10-30
Structures…
• Exercise: Given a record with attributes, Students {name, gender,
department, idNumber}. Construct a structure type of students and use
them in your main program.
• A special type of structure that points to it self.
• It’s important in creating a linked list, dynamic stack and queue, tree, and
other data structures.
IT3201 Data Structures 162018-10-30
Pointers
• It is a type, which stores the location of another variable of any data
type.
• In C, some tasks are easy to work with pointers;
• Tasks like memory management cannot be performed without using pointers.
• Example: int A; int *ptrA = &A;
IT3201 Data Structures 172018-10-30
Memory Management
• Memory space is limited and should be dynamically managed.
• In C, memory management is done using
• Pointers, and
• Built-in functions such as calloc, free, malloc and realloc
IT3201 Data Structures 182018-10-30
Conditional statements
• In C, conditional statements are used to define conditional actions,
e.g., if no class, work on your homework. Otherwise, go to class.
• Conditions are defined using
• if…
• if...else
• if...else if…else
• switch
IT3201 Data Structures 192018-10-30
Loops
• In C, loops are used to program repetitive actions
• Loops defined using one of the following, let’s say: int i, n = 10;
• For loop:
• for (i=0; i<n; i++) { //Statements }
• While loop
• while (i<n) {//Statements; i++;}
• Do…while loop
• do {//Statements; i++;} while (i<n);
IT3201 Data Structures 202018-10-30
Analysis of Algorithm
The algorithm can be analyzed by tracing all step-by-step instructions.
IT3201 Data Structures 212018-10-30
Algorithm
• Algorithm should be checked for
• Correctness
• Simplicity
• Performance
• Algorithm performance analysis and measurements depends on:
• Space complexity
• Time complexity
IT3201 Data Structures 222018-10-30
Algorithm: Space Complexity
• Space complexity of an algorithm is the amount of memory it needs
to run to completion.
• Space needed by a program:
• Instruction space: to run an executable program. It is fixed
• Data space: to store all constants and variable values…
• For constants and simple variables. Fixed
• For fixed structural variables such as array and structure
• Dynamically allocated space.
IT3201 Data Structures 232018-10-30
Algorithm: Space Complexity…
• Environment stack space: to store information of suspended functions
• When a function is invoked, the following data is stored:
• Return address
• Value of all lead variables and formal parameters of the function being invoked
• The amount of space used by recursive functions is called recursive stack space.
• This space depends on:
• The size of each local variables
• The depth of the recursion
IT3201 Data Structures 242018-10-30
Algorithm: Time Complexity
• The amount of time a program needs to run to completion
• Exact time depends on:
• Implementation of the algorithm
• Programming language
• Compiler used
• CPU speed
• Other hardware characteristics
• Counting all operations performed in the algorithm will help in calculating time
IT3201 Data Structures 252018-10-30
Algorithm: Time Complexity…
• Time complexity has to be expressed in the form of functions
• Analysis of algorithm depends
• The input data
• Three cases of an algorithm
• Best case – best possible input data
• Average case – typical input data
• Worst case – worst input configuration
IT3201 Data Structures 262018-10-30
Algorithm: Big “OH” Notation
• A characteristics scheme that measures properties of algorithm complexity,
performance, and memory requirements.
• Complexity can be measured by eliminating constant factors.
• Thus, complexity function f(n) of an algorithm increases as ‘n’ increases.
• E.g., Let’s consider a sequential searching algorithm
• If an array contains n elements.
• Worst case – the search compares the whole elements with the target, thus f(n) = n
• Average case – if the target element found at half way, thus f(n) = n/2
• Best case – if the target element found in the first position, thus f(n) = 1
IT3201 Data Structures 272018-10-30
Algorithm: Big “OH” Notation...
• F(n) = O(n) read as “fof n is big Oh of n” or “f(n) is the order of n”
• The total running time (or time complexity) includes the initializations and several other
iterative statements through the loop.
• Based on the time complexity representation of the big Oh notation, an algorithm can
be:
IT3201 Data Structures 282018-10-30
Limitation of Big “OH” Notation
• It contains no effort to improve the programming methodology. Big Oh Notation
does not discuss the way and means to improve the efficiency of the program,
but it helps to analyze and calculate the efficiency (by finding time complexity) of
the program.
• It does not exhibit the potential of the constants. For example, one algorithm is
taking 1000n2 time to execute and the other n3 time. The first algorithm is O(n2),
which implies that it will take less time than the other algorithm which is O(n3).
However, in actual execution the second algorithm will be faster for n< 100
IT3201 Data Structures 292018-10-30
Recursion
”A recursion routine is one whose design includes a call to itself”
IT3201 Data Structures 302018-10-30
Recursion
• Recursion is a powerful technique for defining an algorithm
• A procedure is recursive if it is defined in terms of itself. E
• Example:
• Factorial: f(n) = n*f(n-1), where f(0) = 1 for n>0.
• Fibonacci numbers f(n-1) + f(n-2), where f(0) = 0, f(1) = 1.
IT3201 Data Structures 312018-10-30
Recursion…
• Factorial:
• Factorial (n)
• If n == 0 or 1 Return 1;
• Else Return n*Factorial(n-1);
• Fibonacci:
• Fibonacci(n)
• if n <= 1 Return n;
• else Return Fibonacci(n-1) + Fibonacci(n-2);
IT3201 Data Structures 322018-10-30
Principle of Recursion
• While design an algorithm with recursion, the following basic principles should be
considered.
1. Find the key step – then find out if the remaining problem can be solved the same way
2. Find a stopping rule – after substantial part of an algorithm is done, the execution should
stop
3. Outline the algorithm – combining the above two principles (1 and 2) with if…else
statements and recursion, an algorithm should be designed
4. Check termination – the recursion should terminate after finite number of steps
5. Draw a recursion tree – to analyze the recursion algorithm, one has to draw a recursion
tree
IT3201 Data Structures 332018-10-30
Recursion vs Loop
• Loop is used when we want to execute a part of the program or block
of statements several times
• A recursion function is a function which calls itself from its body again
and again.
IT3201 Data Structures 342018-10-30
The End ☺
IT3201 Data Structures 352018-10-30

More Related Content

What's hot

CIS110 Computer Programming Design Chapter (14)
CIS110 Computer Programming Design Chapter  (14)CIS110 Computer Programming Design Chapter  (14)
CIS110 Computer Programming Design Chapter (14)
Dr. Ahmed Al Zaidy
 
Programming Logic and Design: Working with Data
Programming Logic and Design: Working with DataProgramming Logic and Design: Working with Data
Programming Logic and Design: Working with Data
Nicole Ryan
 
Storage struct
Storage structStorage struct
Storage struct
durgaprasad1407
 
Unit I Database concepts - RDBMS & ORACLE
Unit I  Database concepts - RDBMS & ORACLEUnit I  Database concepts - RDBMS & ORACLE
Unit I Database concepts - RDBMS & ORACLE
DrkhanchanaR
 
Data Structures & Algorithms
Data Structures & AlgorithmsData Structures & Algorithms
Data Structures & Algorithms
Ain-ul-Moiz Khawaja
 
Computer organiztion3
Computer organiztion3Computer organiztion3
Computer organiztion3
Umang Gupta
 
B.sc cs-ii-u-1.4 digital logic circuits, digital component
B.sc cs-ii-u-1.4 digital logic circuits, digital componentB.sc cs-ii-u-1.4 digital logic circuits, digital component
B.sc cs-ii-u-1.4 digital logic circuits, digital component
Rai University
 
Lecture 01 dld 2018
Lecture 01 dld  2018Lecture 01 dld  2018
Lecture 01 dld 2018
Tanveer Hussain
 
Week 1 - Data Structures and Algorithms
Week 1 - Data Structures and AlgorithmsWeek 1 - Data Structures and Algorithms
Week 1 - Data Structures and Algorithms
Ferdin Joe John Joseph PhD
 
Data Structures 7
Data Structures 7Data Structures 7
Data Structures 7
Dr.Umadevi V
 
Switching theory Unit 1
Switching theory Unit 1Switching theory Unit 1
Switching theory Unit 1
SURBHI SAROHA
 
Logic Design
Logic DesignLogic Design
Logic Design
Partha_bappa
 
Lecture4b dynamic data_structure
Lecture4b dynamic data_structureLecture4b dynamic data_structure
Lecture4b dynamic data_structure
mbadhi barnabas
 
CIS110 Computer Programming Design Chapter (10)
CIS110 Computer Programming Design Chapter  (10)CIS110 Computer Programming Design Chapter  (10)
CIS110 Computer Programming Design Chapter (10)
Dr. Ahmed Al Zaidy
 
Logic design and switching theory
Logic design and switching theoryLogic design and switching theory
Logic design and switching theory
jomerson remorosa
 
Computer organiztion2
Computer organiztion2Computer organiztion2
Computer organiztion2
Umang Gupta
 

What's hot (16)

CIS110 Computer Programming Design Chapter (14)
CIS110 Computer Programming Design Chapter  (14)CIS110 Computer Programming Design Chapter  (14)
CIS110 Computer Programming Design Chapter (14)
 
Programming Logic and Design: Working with Data
Programming Logic and Design: Working with DataProgramming Logic and Design: Working with Data
Programming Logic and Design: Working with Data
 
Storage struct
Storage structStorage struct
Storage struct
 
Unit I Database concepts - RDBMS & ORACLE
Unit I  Database concepts - RDBMS & ORACLEUnit I  Database concepts - RDBMS & ORACLE
Unit I Database concepts - RDBMS & ORACLE
 
Data Structures & Algorithms
Data Structures & AlgorithmsData Structures & Algorithms
Data Structures & Algorithms
 
Computer organiztion3
Computer organiztion3Computer organiztion3
Computer organiztion3
 
B.sc cs-ii-u-1.4 digital logic circuits, digital component
B.sc cs-ii-u-1.4 digital logic circuits, digital componentB.sc cs-ii-u-1.4 digital logic circuits, digital component
B.sc cs-ii-u-1.4 digital logic circuits, digital component
 
Lecture 01 dld 2018
Lecture 01 dld  2018Lecture 01 dld  2018
Lecture 01 dld 2018
 
Week 1 - Data Structures and Algorithms
Week 1 - Data Structures and AlgorithmsWeek 1 - Data Structures and Algorithms
Week 1 - Data Structures and Algorithms
 
Data Structures 7
Data Structures 7Data Structures 7
Data Structures 7
 
Switching theory Unit 1
Switching theory Unit 1Switching theory Unit 1
Switching theory Unit 1
 
Logic Design
Logic DesignLogic Design
Logic Design
 
Lecture4b dynamic data_structure
Lecture4b dynamic data_structureLecture4b dynamic data_structure
Lecture4b dynamic data_structure
 
CIS110 Computer Programming Design Chapter (10)
CIS110 Computer Programming Design Chapter  (10)CIS110 Computer Programming Design Chapter  (10)
CIS110 Computer Programming Design Chapter (10)
 
Logic design and switching theory
Logic design and switching theoryLogic design and switching theory
Logic design and switching theory
 
Computer organiztion2
Computer organiztion2Computer organiztion2
Computer organiztion2
 

Similar to 01. introduction to data structures

Introduction to DS.pptx
Introduction to DS.pptxIntroduction to DS.pptx
Introduction to DS.pptx
OnkarModhave
 
II B.Sc IT DATA STRUCTURES.pptx
II B.Sc IT DATA STRUCTURES.pptxII B.Sc IT DATA STRUCTURES.pptx
II B.Sc IT DATA STRUCTURES.pptx
sabithabanu83
 
CHAPTER-1- Introduction to data structure.pptx
CHAPTER-1- Introduction to data structure.pptxCHAPTER-1- Introduction to data structure.pptx
CHAPTER-1- Introduction to data structure.pptx
OnkarModhave
 
Data Structure & aaplications_Module-1.pptx
Data Structure & aaplications_Module-1.pptxData Structure & aaplications_Module-1.pptx
Data Structure & aaplications_Module-1.pptx
GIRISHKUMARBC1
 
UNIT 3 PPT.ppt
UNIT 3 PPT.pptUNIT 3 PPT.ppt
UNIT 3 PPT.ppt
SaraswathiTAsstProfI
 
data types.pptx
data types.pptxdata types.pptx
data types.pptx
FatimaGraceApinan
 
Chapter 1- IT.pptx
Chapter 1- IT.pptxChapter 1- IT.pptx
Chapter 1- IT.pptx
ssuserb78e291
 
data-structures_unit-01.pdf
data-structures_unit-01.pdfdata-structures_unit-01.pdf
data-structures_unit-01.pdf
RushikeshPeddawad
 
dsa.ppt
dsa.pptdsa.ppt
dsa.ppt
ssuser1f953d
 
dsa.ppt
dsa.pptdsa.ppt
dsa.ppt
ssuser1f953d
 
dsa (1).ppt
dsa (1).pptdsa (1).ppt
dsa (1).ppt
ssuser1f953d
 
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_II_08-08-2022_D...
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_II_08-08-2022_D...FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_II_08-08-2022_D...
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_II_08-08-2022_D...
AntareepMajumder
 
b,Sc it data structure.pptx
b,Sc it data structure.pptxb,Sc it data structure.pptx
b,Sc it data structure.pptx
classall
 
b,Sc it data structure.pptx
b,Sc it data structure.pptxb,Sc it data structure.pptx
b,Sc it data structure.pptx
classall
 
b,Sc it data structure.ppt
b,Sc it data structure.pptb,Sc it data structure.ppt
b,Sc it data structure.ppt
classall
 
09 Structures in C.pptx
09 Structures in C.pptx09 Structures in C.pptx
09 Structures in C.pptx
MouDhara1
 
algo 1.ppt
algo 1.pptalgo 1.ppt
algo 1.ppt
example43
 
Data structure Unit-I Part A
Data structure Unit-I Part AData structure Unit-I Part A
Data structure Unit-I Part A
SSN College of Engineering, Kalavakkam
 
Data preprocessing.pdf
Data preprocessing.pdfData preprocessing.pdf
Data preprocessing.pdf
sankirtishiravale
 
DS Module 1.pptx
DS Module 1.pptxDS Module 1.pptx
DS Module 1.pptx
sarala9
 

Similar to 01. introduction to data structures (20)

Introduction to DS.pptx
Introduction to DS.pptxIntroduction to DS.pptx
Introduction to DS.pptx
 
II B.Sc IT DATA STRUCTURES.pptx
II B.Sc IT DATA STRUCTURES.pptxII B.Sc IT DATA STRUCTURES.pptx
II B.Sc IT DATA STRUCTURES.pptx
 
CHAPTER-1- Introduction to data structure.pptx
CHAPTER-1- Introduction to data structure.pptxCHAPTER-1- Introduction to data structure.pptx
CHAPTER-1- Introduction to data structure.pptx
 
Data Structure & aaplications_Module-1.pptx
Data Structure & aaplications_Module-1.pptxData Structure & aaplications_Module-1.pptx
Data Structure & aaplications_Module-1.pptx
 
UNIT 3 PPT.ppt
UNIT 3 PPT.pptUNIT 3 PPT.ppt
UNIT 3 PPT.ppt
 
data types.pptx
data types.pptxdata types.pptx
data types.pptx
 
Chapter 1- IT.pptx
Chapter 1- IT.pptxChapter 1- IT.pptx
Chapter 1- IT.pptx
 
data-structures_unit-01.pdf
data-structures_unit-01.pdfdata-structures_unit-01.pdf
data-structures_unit-01.pdf
 
dsa.ppt
dsa.pptdsa.ppt
dsa.ppt
 
dsa.ppt
dsa.pptdsa.ppt
dsa.ppt
 
dsa (1).ppt
dsa (1).pptdsa (1).ppt
dsa (1).ppt
 
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_II_08-08-2022_D...
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_II_08-08-2022_D...FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_II_08-08-2022_D...
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_II_08-08-2022_D...
 
b,Sc it data structure.pptx
b,Sc it data structure.pptxb,Sc it data structure.pptx
b,Sc it data structure.pptx
 
b,Sc it data structure.pptx
b,Sc it data structure.pptxb,Sc it data structure.pptx
b,Sc it data structure.pptx
 
b,Sc it data structure.ppt
b,Sc it data structure.pptb,Sc it data structure.ppt
b,Sc it data structure.ppt
 
09 Structures in C.pptx
09 Structures in C.pptx09 Structures in C.pptx
09 Structures in C.pptx
 
algo 1.ppt
algo 1.pptalgo 1.ppt
algo 1.ppt
 
Data structure Unit-I Part A
Data structure Unit-I Part AData structure Unit-I Part A
Data structure Unit-I Part A
 
Data preprocessing.pdf
Data preprocessing.pdfData preprocessing.pdf
Data preprocessing.pdf
 
DS Module 1.pptx
DS Module 1.pptxDS Module 1.pptx
DS Module 1.pptx
 

Recently uploaded

一比一原版加拿大渥太华大学毕业证(uottawa毕业证书)如何办理
一比一原版加拿大渥太华大学毕业证(uottawa毕业证书)如何办理一比一原版加拿大渥太华大学毕业证(uottawa毕业证书)如何办理
一比一原版加拿大渥太华大学毕业证(uottawa毕业证书)如何办理
uevausa
 
A gentle exploration of Retrieval Augmented Generation
A gentle exploration of Retrieval Augmented GenerationA gentle exploration of Retrieval Augmented Generation
A gentle exploration of Retrieval Augmented Generation
dataschool1
 
一比一原版马来西亚博特拉大学毕业证(upm毕业证)如何办理
一比一原版马来西亚博特拉大学毕业证(upm毕业证)如何办理一比一原版马来西亚博特拉大学毕业证(upm毕业证)如何办理
一比一原版马来西亚博特拉大学毕业证(upm毕业证)如何办理
eudsoh
 
一比一原版斯威本理工大学毕业证(swinburne毕业证)如何办理
一比一原版斯威本理工大学毕业证(swinburne毕业证)如何办理一比一原版斯威本理工大学毕业证(swinburne毕业证)如何办理
一比一原版斯威本理工大学毕业证(swinburne毕业证)如何办理
actyx
 
一比一原版多伦多大学毕业证(UofT毕业证书)学历如何办理
一比一原版多伦多大学毕业证(UofT毕业证书)学历如何办理一比一原版多伦多大学毕业证(UofT毕业证书)学历如何办理
一比一原版多伦多大学毕业证(UofT毕业证书)学历如何办理
eoxhsaa
 
Orchestrating the Future: Navigating Today's Data Workflow Challenges with Ai...
Orchestrating the Future: Navigating Today's Data Workflow Challenges with Ai...Orchestrating the Future: Navigating Today's Data Workflow Challenges with Ai...
Orchestrating the Future: Navigating Today's Data Workflow Challenges with Ai...
Kaxil Naik
 
一比一原版(UO毕业证)渥太华大学毕业证如何办理
一比一原版(UO毕业证)渥太华大学毕业证如何办理一比一原版(UO毕业证)渥太华大学毕业证如何办理
一比一原版(UO毕业证)渥太华大学毕业证如何办理
bmucuha
 
[VCOSA] Monthly Report - Cotton & Yarn Statistics March 2024
[VCOSA] Monthly Report - Cotton & Yarn Statistics March 2024[VCOSA] Monthly Report - Cotton & Yarn Statistics March 2024
[VCOSA] Monthly Report - Cotton & Yarn Statistics March 2024
Vietnam Cotton & Spinning Association
 
原版一比一多伦多大学毕业证(UofT毕业证书)如何办理
原版一比一多伦多大学毕业证(UofT毕业证书)如何办理原版一比一多伦多大学毕业证(UofT毕业证书)如何办理
原版一比一多伦多大学毕业证(UofT毕业证书)如何办理
mkkikqvo
 
一比一原版加拿大麦吉尔大学毕业证(mcgill毕业证书)如何办理
一比一原版加拿大麦吉尔大学毕业证(mcgill毕业证书)如何办理一比一原版加拿大麦吉尔大学毕业证(mcgill毕业证书)如何办理
一比一原版加拿大麦吉尔大学毕业证(mcgill毕业证书)如何办理
agdhot
 
在线办理(英国UCA毕业证书)创意艺术大学毕业证在读证明一模一样
在线办理(英国UCA毕业证书)创意艺术大学毕业证在读证明一模一样在线办理(英国UCA毕业证书)创意艺术大学毕业证在读证明一模一样
在线办理(英国UCA毕业证书)创意艺术大学毕业证在读证明一模一样
v7oacc3l
 
一比一原版卡尔加里大学毕业证(uc毕业证)如何办理
一比一原版卡尔加里大学毕业证(uc毕业证)如何办理一比一原版卡尔加里大学毕业证(uc毕业证)如何办理
一比一原版卡尔加里大学毕业证(uc毕业证)如何办理
oaxefes
 
一比一原版莱斯大学毕业证(rice毕业证)如何办理
一比一原版莱斯大学毕业证(rice毕业证)如何办理一比一原版莱斯大学毕业证(rice毕业证)如何办理
一比一原版莱斯大学毕业证(rice毕业证)如何办理
zsafxbf
 
DATA COMMS-NETWORKS YR2 lecture 08 NAT & CLOUD.docx
DATA COMMS-NETWORKS YR2 lecture 08 NAT & CLOUD.docxDATA COMMS-NETWORKS YR2 lecture 08 NAT & CLOUD.docx
DATA COMMS-NETWORKS YR2 lecture 08 NAT & CLOUD.docx
SaffaIbrahim1
 
Build applications with generative AI on Google Cloud
Build applications with generative AI on Google CloudBuild applications with generative AI on Google Cloud
Build applications with generative AI on Google Cloud
Márton Kodok
 
一比一原版(曼大毕业证书)曼尼托巴大学毕业证如何办理
一比一原版(曼大毕业证书)曼尼托巴大学毕业证如何办理一比一原版(曼大毕业证书)曼尼托巴大学毕业证如何办理
一比一原版(曼大毕业证书)曼尼托巴大学毕业证如何办理
ytypuem
 
一比一原版(lbs毕业证书)伦敦商学院毕业证如何办理
一比一原版(lbs毕业证书)伦敦商学院毕业证如何办理一比一原版(lbs毕业证书)伦敦商学院毕业证如何办理
一比一原版(lbs毕业证书)伦敦商学院毕业证如何办理
ywqeos
 
Beyond the Basics of A/B Tests: Highly Innovative Experimentation Tactics You...
Beyond the Basics of A/B Tests: Highly Innovative Experimentation Tactics You...Beyond the Basics of A/B Tests: Highly Innovative Experimentation Tactics You...
Beyond the Basics of A/B Tests: Highly Innovative Experimentation Tactics You...
Aggregage
 
Cell The Unit of Life for NEET Multiple Choice Questions.docx
Cell The Unit of Life for NEET Multiple Choice Questions.docxCell The Unit of Life for NEET Multiple Choice Questions.docx
Cell The Unit of Life for NEET Multiple Choice Questions.docx
vasanthatpuram
 
一比一原版英国赫特福德大学毕业证(hertfordshire毕业证书)如何办理
一比一原版英国赫特福德大学毕业证(hertfordshire毕业证书)如何办理一比一原版英国赫特福德大学毕业证(hertfordshire毕业证书)如何办理
一比一原版英国赫特福德大学毕业证(hertfordshire毕业证书)如何办理
nyvan3
 

Recently uploaded (20)

一比一原版加拿大渥太华大学毕业证(uottawa毕业证书)如何办理
一比一原版加拿大渥太华大学毕业证(uottawa毕业证书)如何办理一比一原版加拿大渥太华大学毕业证(uottawa毕业证书)如何办理
一比一原版加拿大渥太华大学毕业证(uottawa毕业证书)如何办理
 
A gentle exploration of Retrieval Augmented Generation
A gentle exploration of Retrieval Augmented GenerationA gentle exploration of Retrieval Augmented Generation
A gentle exploration of Retrieval Augmented Generation
 
一比一原版马来西亚博特拉大学毕业证(upm毕业证)如何办理
一比一原版马来西亚博特拉大学毕业证(upm毕业证)如何办理一比一原版马来西亚博特拉大学毕业证(upm毕业证)如何办理
一比一原版马来西亚博特拉大学毕业证(upm毕业证)如何办理
 
一比一原版斯威本理工大学毕业证(swinburne毕业证)如何办理
一比一原版斯威本理工大学毕业证(swinburne毕业证)如何办理一比一原版斯威本理工大学毕业证(swinburne毕业证)如何办理
一比一原版斯威本理工大学毕业证(swinburne毕业证)如何办理
 
一比一原版多伦多大学毕业证(UofT毕业证书)学历如何办理
一比一原版多伦多大学毕业证(UofT毕业证书)学历如何办理一比一原版多伦多大学毕业证(UofT毕业证书)学历如何办理
一比一原版多伦多大学毕业证(UofT毕业证书)学历如何办理
 
Orchestrating the Future: Navigating Today's Data Workflow Challenges with Ai...
Orchestrating the Future: Navigating Today's Data Workflow Challenges with Ai...Orchestrating the Future: Navigating Today's Data Workflow Challenges with Ai...
Orchestrating the Future: Navigating Today's Data Workflow Challenges with Ai...
 
一比一原版(UO毕业证)渥太华大学毕业证如何办理
一比一原版(UO毕业证)渥太华大学毕业证如何办理一比一原版(UO毕业证)渥太华大学毕业证如何办理
一比一原版(UO毕业证)渥太华大学毕业证如何办理
 
[VCOSA] Monthly Report - Cotton & Yarn Statistics March 2024
[VCOSA] Monthly Report - Cotton & Yarn Statistics March 2024[VCOSA] Monthly Report - Cotton & Yarn Statistics March 2024
[VCOSA] Monthly Report - Cotton & Yarn Statistics March 2024
 
原版一比一多伦多大学毕业证(UofT毕业证书)如何办理
原版一比一多伦多大学毕业证(UofT毕业证书)如何办理原版一比一多伦多大学毕业证(UofT毕业证书)如何办理
原版一比一多伦多大学毕业证(UofT毕业证书)如何办理
 
一比一原版加拿大麦吉尔大学毕业证(mcgill毕业证书)如何办理
一比一原版加拿大麦吉尔大学毕业证(mcgill毕业证书)如何办理一比一原版加拿大麦吉尔大学毕业证(mcgill毕业证书)如何办理
一比一原版加拿大麦吉尔大学毕业证(mcgill毕业证书)如何办理
 
在线办理(英国UCA毕业证书)创意艺术大学毕业证在读证明一模一样
在线办理(英国UCA毕业证书)创意艺术大学毕业证在读证明一模一样在线办理(英国UCA毕业证书)创意艺术大学毕业证在读证明一模一样
在线办理(英国UCA毕业证书)创意艺术大学毕业证在读证明一模一样
 
一比一原版卡尔加里大学毕业证(uc毕业证)如何办理
一比一原版卡尔加里大学毕业证(uc毕业证)如何办理一比一原版卡尔加里大学毕业证(uc毕业证)如何办理
一比一原版卡尔加里大学毕业证(uc毕业证)如何办理
 
一比一原版莱斯大学毕业证(rice毕业证)如何办理
一比一原版莱斯大学毕业证(rice毕业证)如何办理一比一原版莱斯大学毕业证(rice毕业证)如何办理
一比一原版莱斯大学毕业证(rice毕业证)如何办理
 
DATA COMMS-NETWORKS YR2 lecture 08 NAT & CLOUD.docx
DATA COMMS-NETWORKS YR2 lecture 08 NAT & CLOUD.docxDATA COMMS-NETWORKS YR2 lecture 08 NAT & CLOUD.docx
DATA COMMS-NETWORKS YR2 lecture 08 NAT & CLOUD.docx
 
Build applications with generative AI on Google Cloud
Build applications with generative AI on Google CloudBuild applications with generative AI on Google Cloud
Build applications with generative AI on Google Cloud
 
一比一原版(曼大毕业证书)曼尼托巴大学毕业证如何办理
一比一原版(曼大毕业证书)曼尼托巴大学毕业证如何办理一比一原版(曼大毕业证书)曼尼托巴大学毕业证如何办理
一比一原版(曼大毕业证书)曼尼托巴大学毕业证如何办理
 
一比一原版(lbs毕业证书)伦敦商学院毕业证如何办理
一比一原版(lbs毕业证书)伦敦商学院毕业证如何办理一比一原版(lbs毕业证书)伦敦商学院毕业证如何办理
一比一原版(lbs毕业证书)伦敦商学院毕业证如何办理
 
Beyond the Basics of A/B Tests: Highly Innovative Experimentation Tactics You...
Beyond the Basics of A/B Tests: Highly Innovative Experimentation Tactics You...Beyond the Basics of A/B Tests: Highly Innovative Experimentation Tactics You...
Beyond the Basics of A/B Tests: Highly Innovative Experimentation Tactics You...
 
Cell The Unit of Life for NEET Multiple Choice Questions.docx
Cell The Unit of Life for NEET Multiple Choice Questions.docxCell The Unit of Life for NEET Multiple Choice Questions.docx
Cell The Unit of Life for NEET Multiple Choice Questions.docx
 
一比一原版英国赫特福德大学毕业证(hertfordshire毕业证书)如何办理
一比一原版英国赫特福德大学毕业证(hertfordshire毕业证书)如何办理一比一原版英国赫特福德大学毕业证(hertfordshire毕业证书)如何办理
一比一原版英国赫特福德大学毕业证(hertfordshire毕业证书)如何办理
 

01. introduction to data structures

  • 1. Chapter – 1 Introduction to Data Structures Asmelash Girmay Department of Information Technology Data Structures
  • 2. The Need of Data Structure • Helps to understand relationship one data element with other and organize it within the memory. Example: • Months of a year: one month after the other can be linked • Thus knowing the starting and ending month name could help to know the other months • Specific department of a university can be represented in a tree • Example: IT IT3201 Data Structures 22018-10-30
  • 3. Data Representation • Various methods are used to represent data in Computers • Example: hierarchal data representation • Bit – basic unit of data representation • Byte – combination of 8 bits • In ASCII code representation 1 byte represents a character • One or more characters are used to form a string • String: is a data structure that emerges through several layers of data structures. IT3201 Data Structures 32018-10-30
  • 4. Integer Representation • Int: -2n-1 to 2n-1 - 1 using n-number of bits • Non-negative int represented using binary number system • Each bit position represents power of 2, where the right most bit represents 20 = 1 • Example: 00100110 represents 21 + 22 + 25 = 2 + 4 + 32 = 38. • Negative int represented using one’s complement and two’s complement • One’s complement complements each bit, e.g. -38 = 11011001 • Two’s complement adds to the one’s complement of a number, e.g. -38 = 11011010 IT3201 Data Structures 42018-10-30
  • 5. Real Number Representation • Float: m*nr => -3.4*1038 to 3.4*1038 • A real number is represented by mantissa and exponent. E.g., • 43.56 can be represented as 4356 * 10-2 , where 4356 – mantissa, -2 exponent • Both mantissa and exponent are two’s complement of binary integers. E.g. • 4356 = 0001000100000100, and -2 = 1111 1110 (8 – bit representation) • 43.56 = 0001 0001 0000 0100 1111 1110 IT3201 Data Structures 52018-10-30
  • 6. Character Representation • Char: [0-9, a-z, A-Z] + other symbols = 2n chars, for n-number of bits • Codes to represent characters are BCD, EBCDIC, ASCII • ASCII is commonly used • If 8 bits used to represent a character, 28 = 256 characters can be represented • E.g., If character ‘A’ represented with 0100 0001 and ‘B’ with 0100 0010, then “AB” can be represented with 0100 0001 0100 0010, which is a string IT3201 Data Structures 62018-10-30
  • 7. Abstract Data Types (ADTs) • ADT is the mathematical model of data objects • Specifies logical & mathematical properties of a data type and its operations • ADT is useful as a guideline to implement a data type. • In ADT, no implementation • Two steps in ADT 1. Description of the way in which components are related to each other. 2. Statements of operations that can be performed on that data type. IT3201 Data Structures 72018-10-30
  • 8. Abstract Data Types (ADTs)... • Example: in C, to implement integer data type, INTEGER_ADT defines: • Range of numbers that will be represented • Formats for storing the integer numbers • Operations on it, such as addition, subtraction, division, multiplication, modulo IT3201 Data Structures 82018-10-30
  • 9. Data Type • A method of interpreting a bit pattern. • It’s the implementation of the mathematical model specified by an ADT. • It is an internal representation of data in the memory. • Once ADT specification is done, a data type can then be implemented in: • Hardwire – Circuitry as part of a computer • Software – using the existing hard wired instructions IT3201 Data Structures 92018-10-30
  • 10. Data Structure Types IT3201 Data Structures 102018-10-30
  • 11. Review on C This course uses C to implement data structures IT3201 Data Structures 112018-10-30
  • 12. Function • A section of program, separately written from main program for: • Reusability, readability, and/or modularity of software program. • Function is a way of modularizing and organizing program. • Function has much emphasis on procedural-oriented programming such as C. • We can define a function in C in 4 ways. • A function – with return type and argument/s [WRWA] • A function – with return type but no arguments [WRNA] • A function – with no return type but with arguments [NRWA] • A function – with no return type and no arguments [NRNA] KEY: R-return type, A – Argument lists, W – With, and N – No IT3201 Data Structures 122018-10-30
  • 14. Array • Array is a derived data type, from basic data types like int, float, char, etc. • It is used to store more than one data of same types at a time. E.g., • float StudentsGrade [57]; • It stores data in indexing form, where indexing starts at 0 (zero). • It is also a data structure, but built-in and stores fixed-size sequential collection of elements of same type. • There are one-dimensional arrays, two-dimensional arrays, and three or above dimensional arrays. IT3201 Data Structures 142018-10-30
  • 15. Structures • A structure is a user-defined derived data type which allows you to combine data items of different kinds/types. • Used to store/represent a record as in a database table. E.g., • Attributes of a book: • Title, • Author, • Subject, • BookId IT3201 Data Structures 152018-10-30
  • 16. Structures… • Exercise: Given a record with attributes, Students {name, gender, department, idNumber}. Construct a structure type of students and use them in your main program. • A special type of structure that points to it self. • It’s important in creating a linked list, dynamic stack and queue, tree, and other data structures. IT3201 Data Structures 162018-10-30
  • 17. Pointers • It is a type, which stores the location of another variable of any data type. • In C, some tasks are easy to work with pointers; • Tasks like memory management cannot be performed without using pointers. • Example: int A; int *ptrA = &A; IT3201 Data Structures 172018-10-30
  • 18. Memory Management • Memory space is limited and should be dynamically managed. • In C, memory management is done using • Pointers, and • Built-in functions such as calloc, free, malloc and realloc IT3201 Data Structures 182018-10-30
  • 19. Conditional statements • In C, conditional statements are used to define conditional actions, e.g., if no class, work on your homework. Otherwise, go to class. • Conditions are defined using • if… • if...else • if...else if…else • switch IT3201 Data Structures 192018-10-30
  • 20. Loops • In C, loops are used to program repetitive actions • Loops defined using one of the following, let’s say: int i, n = 10; • For loop: • for (i=0; i<n; i++) { //Statements } • While loop • while (i<n) {//Statements; i++;} • Do…while loop • do {//Statements; i++;} while (i<n); IT3201 Data Structures 202018-10-30
  • 21. Analysis of Algorithm The algorithm can be analyzed by tracing all step-by-step instructions. IT3201 Data Structures 212018-10-30
  • 22. Algorithm • Algorithm should be checked for • Correctness • Simplicity • Performance • Algorithm performance analysis and measurements depends on: • Space complexity • Time complexity IT3201 Data Structures 222018-10-30
  • 23. Algorithm: Space Complexity • Space complexity of an algorithm is the amount of memory it needs to run to completion. • Space needed by a program: • Instruction space: to run an executable program. It is fixed • Data space: to store all constants and variable values… • For constants and simple variables. Fixed • For fixed structural variables such as array and structure • Dynamically allocated space. IT3201 Data Structures 232018-10-30
  • 24. Algorithm: Space Complexity… • Environment stack space: to store information of suspended functions • When a function is invoked, the following data is stored: • Return address • Value of all lead variables and formal parameters of the function being invoked • The amount of space used by recursive functions is called recursive stack space. • This space depends on: • The size of each local variables • The depth of the recursion IT3201 Data Structures 242018-10-30
  • 25. Algorithm: Time Complexity • The amount of time a program needs to run to completion • Exact time depends on: • Implementation of the algorithm • Programming language • Compiler used • CPU speed • Other hardware characteristics • Counting all operations performed in the algorithm will help in calculating time IT3201 Data Structures 252018-10-30
  • 26. Algorithm: Time Complexity… • Time complexity has to be expressed in the form of functions • Analysis of algorithm depends • The input data • Three cases of an algorithm • Best case – best possible input data • Average case – typical input data • Worst case – worst input configuration IT3201 Data Structures 262018-10-30
  • 27. Algorithm: Big “OH” Notation • A characteristics scheme that measures properties of algorithm complexity, performance, and memory requirements. • Complexity can be measured by eliminating constant factors. • Thus, complexity function f(n) of an algorithm increases as ‘n’ increases. • E.g., Let’s consider a sequential searching algorithm • If an array contains n elements. • Worst case – the search compares the whole elements with the target, thus f(n) = n • Average case – if the target element found at half way, thus f(n) = n/2 • Best case – if the target element found in the first position, thus f(n) = 1 IT3201 Data Structures 272018-10-30
  • 28. Algorithm: Big “OH” Notation... • F(n) = O(n) read as “fof n is big Oh of n” or “f(n) is the order of n” • The total running time (or time complexity) includes the initializations and several other iterative statements through the loop. • Based on the time complexity representation of the big Oh notation, an algorithm can be: IT3201 Data Structures 282018-10-30
  • 29. Limitation of Big “OH” Notation • It contains no effort to improve the programming methodology. Big Oh Notation does not discuss the way and means to improve the efficiency of the program, but it helps to analyze and calculate the efficiency (by finding time complexity) of the program. • It does not exhibit the potential of the constants. For example, one algorithm is taking 1000n2 time to execute and the other n3 time. The first algorithm is O(n2), which implies that it will take less time than the other algorithm which is O(n3). However, in actual execution the second algorithm will be faster for n< 100 IT3201 Data Structures 292018-10-30
  • 30. Recursion ”A recursion routine is one whose design includes a call to itself” IT3201 Data Structures 302018-10-30
  • 31. Recursion • Recursion is a powerful technique for defining an algorithm • A procedure is recursive if it is defined in terms of itself. E • Example: • Factorial: f(n) = n*f(n-1), where f(0) = 1 for n>0. • Fibonacci numbers f(n-1) + f(n-2), where f(0) = 0, f(1) = 1. IT3201 Data Structures 312018-10-30
  • 32. Recursion… • Factorial: • Factorial (n) • If n == 0 or 1 Return 1; • Else Return n*Factorial(n-1); • Fibonacci: • Fibonacci(n) • if n <= 1 Return n; • else Return Fibonacci(n-1) + Fibonacci(n-2); IT3201 Data Structures 322018-10-30
  • 33. Principle of Recursion • While design an algorithm with recursion, the following basic principles should be considered. 1. Find the key step – then find out if the remaining problem can be solved the same way 2. Find a stopping rule – after substantial part of an algorithm is done, the execution should stop 3. Outline the algorithm – combining the above two principles (1 and 2) with if…else statements and recursion, an algorithm should be designed 4. Check termination – the recursion should terminate after finite number of steps 5. Draw a recursion tree – to analyze the recursion algorithm, one has to draw a recursion tree IT3201 Data Structures 332018-10-30
  • 34. Recursion vs Loop • Loop is used when we want to execute a part of the program or block of statements several times • A recursion function is a function which calls itself from its body again and again. IT3201 Data Structures 342018-10-30
  • 35. The End ☺ IT3201 Data Structures 352018-10-30