SlideShare a Scribd company logo
1 of 35
Download to read offline
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 DataNicole Ryan
 
Unit I Database concepts - RDBMS & ORACLE
Unit I  Database concepts - RDBMS & ORACLEUnit I  Database concepts - RDBMS & ORACLE
Unit I Database concepts - RDBMS & ORACLEDrkhanchanaR
 
Computer organiztion3
Computer organiztion3Computer organiztion3
Computer organiztion3Umang 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 componentRai University
 
Switching theory Unit 1
Switching theory Unit 1Switching theory Unit 1
Switching theory Unit 1SURBHI SAROHA
 
Lecture4b dynamic data_structure
Lecture4b dynamic data_structureLecture4b dynamic data_structure
Lecture4b dynamic data_structurembadhi 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 theoryjomerson remorosa
 
Computer organiztion2
Computer organiztion2Computer organiztion2
Computer organiztion2Umang 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 DS-Chapter1

Introduction to DS.pptx
Introduction to DS.pptxIntroduction to DS.pptx
Introduction to DS.pptxOnkarModhave
 
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.pptxsabithabanu83
 
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.pptxOnkarModhave
 
Data Structure & aaplications_Module-1.pptx
Data Structure & aaplications_Module-1.pptxData Structure & aaplications_Module-1.pptx
Data Structure & aaplications_Module-1.pptxGIRISHKUMARBC1
 
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.pptxclassall
 
b,Sc it data structure.pptx
b,Sc it data structure.pptxb,Sc it data structure.pptx
b,Sc it data structure.pptxclassall
 
b,Sc it data structure.ppt
b,Sc it data structure.pptb,Sc it data structure.ppt
b,Sc it data structure.pptclassall
 
09 Structures in C.pptx
09 Structures in C.pptx09 Structures in C.pptx
09 Structures in C.pptxMouDhara1
 
DS Module 1.pptx
DS Module 1.pptxDS Module 1.pptx
DS Module 1.pptxsarala9
 

Similar to DS-Chapter1 (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

VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...
VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...
VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...SUHANI PANDEY
 
Zuja dropshipping via API with DroFx.pptx
Zuja dropshipping via API with DroFx.pptxZuja dropshipping via API with DroFx.pptx
Zuja dropshipping via API with DroFx.pptxolyaivanovalion
 
Log Analysis using OSSEC sasoasasasas.pptx
Log Analysis using OSSEC sasoasasasas.pptxLog Analysis using OSSEC sasoasasasas.pptx
Log Analysis using OSSEC sasoasasasas.pptxJohnnyPlasten
 
Best VIP Call Girls Noida Sector 22 Call Me: 8448380779
Best VIP Call Girls Noida Sector 22 Call Me: 8448380779Best VIP Call Girls Noida Sector 22 Call Me: 8448380779
Best VIP Call Girls Noida Sector 22 Call Me: 8448380779Delhi Call girls
 
Discover Why Less is More in B2B Research
Discover Why Less is More in B2B ResearchDiscover Why Less is More in B2B Research
Discover Why Less is More in B2B Researchmichael115558
 
Smarteg dropshipping via API with DroFx.pptx
Smarteg dropshipping via API with DroFx.pptxSmarteg dropshipping via API with DroFx.pptx
Smarteg dropshipping via API with DroFx.pptxolyaivanovalion
 
CebaBaby dropshipping via API with DroFX.pptx
CebaBaby dropshipping via API with DroFX.pptxCebaBaby dropshipping via API with DroFX.pptx
CebaBaby dropshipping via API with DroFX.pptxolyaivanovalion
 
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...amitlee9823
 
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...amitlee9823
 
Mature dropshipping via API with DroFx.pptx
Mature dropshipping via API with DroFx.pptxMature dropshipping via API with DroFx.pptx
Mature dropshipping via API with DroFx.pptxolyaivanovalion
 
BabyOno dropshipping via API with DroFx.pptx
BabyOno dropshipping via API with DroFx.pptxBabyOno dropshipping via API with DroFx.pptx
BabyOno dropshipping via API with DroFx.pptxolyaivanovalion
 
100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptx100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptxAnupama Kate
 
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...amitlee9823
 
Edukaciniai dropshipping via API with DroFx
Edukaciniai dropshipping via API with DroFxEdukaciniai dropshipping via API with DroFx
Edukaciniai dropshipping via API with DroFxolyaivanovalion
 
Introduction-to-Machine-Learning (1).pptx
Introduction-to-Machine-Learning (1).pptxIntroduction-to-Machine-Learning (1).pptx
Introduction-to-Machine-Learning (1).pptxfirstjob4
 
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Callshivangimorya083
 
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...Delhi Call girls
 
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...Valters Lauzums
 

Recently uploaded (20)

VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...
VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...
VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...
 
Zuja dropshipping via API with DroFx.pptx
Zuja dropshipping via API with DroFx.pptxZuja dropshipping via API with DroFx.pptx
Zuja dropshipping via API with DroFx.pptx
 
(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7
(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7
(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7
 
Log Analysis using OSSEC sasoasasasas.pptx
Log Analysis using OSSEC sasoasasasas.pptxLog Analysis using OSSEC sasoasasasas.pptx
Log Analysis using OSSEC sasoasasasas.pptx
 
Best VIP Call Girls Noida Sector 22 Call Me: 8448380779
Best VIP Call Girls Noida Sector 22 Call Me: 8448380779Best VIP Call Girls Noida Sector 22 Call Me: 8448380779
Best VIP Call Girls Noida Sector 22 Call Me: 8448380779
 
Discover Why Less is More in B2B Research
Discover Why Less is More in B2B ResearchDiscover Why Less is More in B2B Research
Discover Why Less is More in B2B Research
 
Smarteg dropshipping via API with DroFx.pptx
Smarteg dropshipping via API with DroFx.pptxSmarteg dropshipping via API with DroFx.pptx
Smarteg dropshipping via API with DroFx.pptx
 
CebaBaby dropshipping via API with DroFX.pptx
CebaBaby dropshipping via API with DroFX.pptxCebaBaby dropshipping via API with DroFX.pptx
CebaBaby dropshipping via API with DroFX.pptx
 
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
 
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
 
Mature dropshipping via API with DroFx.pptx
Mature dropshipping via API with DroFx.pptxMature dropshipping via API with DroFx.pptx
Mature dropshipping via API with DroFx.pptx
 
BabyOno dropshipping via API with DroFx.pptx
BabyOno dropshipping via API with DroFx.pptxBabyOno dropshipping via API with DroFx.pptx
BabyOno dropshipping via API with DroFx.pptx
 
100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptx100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptx
 
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
 
Edukaciniai dropshipping via API with DroFx
Edukaciniai dropshipping via API with DroFxEdukaciniai dropshipping via API with DroFx
Edukaciniai dropshipping via API with DroFx
 
Abortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Doha Qatar (+966572737505 ! Get CytotecAbortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Doha Qatar (+966572737505 ! Get Cytotec
 
Introduction-to-Machine-Learning (1).pptx
Introduction-to-Machine-Learning (1).pptxIntroduction-to-Machine-Learning (1).pptx
Introduction-to-Machine-Learning (1).pptx
 
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
 
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...
 
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
 

DS-Chapter1

  • 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