SlideShare a Scribd company logo
CSE42D: Data Structures
Outline
• Overview of the Course
• Queues
• Stacks
Goals of the Course
• Become familiar with some of the fundamental
data structures in computer science
• Improve ability to solve problems abstractly
– data structures are the building blocks
• Improve ability to analyze your algorithms
– prove correctness
– gauge (and improve) time complexity
• Become modestly skilled with the UNIX
operating system and X-windows (you’ll need this in
upcoming courses)
Observation
• All programs manipulate data
– programs process, store, display, gather
– data can be information, numbers, images, sound
• Each program must decide how to store data
• Choice influences program at every level
– execution speed
– memory requirements
– maintenance (debugging, extending, etc.)
What is a Data Structure?
data structure -
What is an Abstract Data Type?
Abstract Data Type (ADT) -
1) An opportunity for an acronym
2) Mathematical description of an object
and the set of operations on the object
Data Structures : Algorithms
• Algorithm
– A high level, language independent
description of a step-by-step process for
solving a problem
• Data Structure
– A set of algorithms which implement an
ADT
Why so many data structures?
Ideal data structure:
fast, elegant, memory
efficient
Generates tensions:
– time vs. space
– performance vs.
elegance
– generality vs. simplicity
– one operation’s
performance vs.
another’s
Dictionary ADT
– list
– binary search tree
– AVL tree
– Splay tree
– Red-Black tree
– hash table
Code Implementation
• Theoretically
– abstract base class describes ADT
– inherited implementations implement data
structures
– can change data structures transparently (to client
code)
• Practice
– different implementations sometimes suggest
different interfaces (generality vs. simplicity)
– performance of a data structure may influence
form of client code (time vs. space, one operation
vs. another)
ADT Presentation Algorithm
• Present an ADT
• Motivate with some applications
• Repeat until browned entirely through
– develop a data structure for the ADT
– analyze its properties
• efficiency
• correctness
• limitations
• ease of programming
• Contrast data structure’s strengths and
weaknesses
– understand when to use each one
Queue ADT
• Queue operations
– create
– destroy
– enqueue
– dequeue
– is_empty
• Queue property: if x is enQed before y is
enQed, then x will be deQed before y is
deQed
FIFO: First In First Out
F E D C B
enqueue dequeue
G A
Applications of the Q
• Hold jobs for a printer
• Store packets on network routers
• Hold memory “freelists”
• Make waitlists fair
• Breadth first search
Circular Array Q Data Structure
void enqueue(Object x) {
Q[back] = x
back = (back + 1) % size
}
Object dequeue() {
x = Q[front]
front = (front + 1) % size
return x
}
b c d e f
Q
0 size - 1
front back
This is pseudocode. Do not correct my semicolons.
When is the Q empty?
Are there error situations this
code will not catch?
What are some limitations of
this structure?
Q Example
enqueue R
enqueue O
dequeue
enqueue T
enqueue A
enqueue T
dequeue
dequeue
enqueue E
dequeue
Linked List Q Data Structure
b c d e f
front back
void enqueue(Object x) {
if (is_empty())
front = back = new Node(x)
else
back->next = new Node(x)
back = back->next
}
Object dequeue() {
assert(!is_empty)
return_data = front->data
temp = front
front = front->next
delete temp
return temp->data
}
Circular Array vs. Linked List
LIFO Stack ADT
• Stack operations
– create
– destroy
– push
– pop
– top
– is_empty
• Stack property: if x is on the stack before y is
pushed, then x will be popped after y is
popped
LIFO: Last In First Out
A
B
C
D
E
F
E D C B A
F
Stacks in Practice
• Function call stack
• Removing recursion
• Balancing symbols (parentheses)
• Evaluating Reverse Polish Notation
• Depth first search
Array Stack Data Structure
S
0 size - 1
f e d c b
void push(Object x) {
assert(!is_full())
S[back] = x
back++
}
Object top() {
assert(!is_empty())
return S[back - 1]
}
back
Object pop() {
back--
return S[back]
}
bool is_full() {
return back == size
}
Linked List Stack Data Structure
b c d e f
back
void push(Object x) {
temp = back
back = new Node(x)
back->next = temp
}
Object top() {
assert(!is_empty())
return back->data
}
Object pop() {
assert(!is_empty())
return_data = back->data
temp = back
back = back->next
return return_data
}
Data structures you should
already know
• Arrays
• Linked lists
• Trees
• Queues
• Stacks

More Related Content

PPT
INTRODUCTION TO DATA STRUCTURES LECTURE!
PPT
Intro_2.ppt
PPT
Intro.ppt
PPT
Intro.ppt
PPT
lecture1.ppt
PPTX
lecture NOTES ON OOPS C++ ON CLASS AND OBJECTS
PPT
lecture02-cpp.ppt
PPT
lecture02-cpp.ppt
INTRODUCTION TO DATA STRUCTURES LECTURE!
Intro_2.ppt
Intro.ppt
Intro.ppt
lecture1.ppt
lecture NOTES ON OOPS C++ ON CLASS AND OBJECTS
lecture02-cpp.ppt
lecture02-cpp.ppt

Similar to lecture1.ppt (20)

PPT
lecture02-cpp.ppt
PPT
lecture02-cpp.ppt
PPT
C++ - A powerful and system level language
PDF
DSJ_Unit I & II.pdf
PPTX
Data structure and algorithm using java
PPT
lecture5-cpp.pptintroduccionaC++basicoye
PPT
Introduction to Inheritance in C plus plus
PPT
UsingCPP_for_Artist.ppt
PPTX
A full Machine learning pipeline in Scikit-learn vs in scala-Spark: pros and ...
PPT
c++ ppt.ppt
PPTX
AN introduction to Software Engineering and Data.pptx
PPTX
Unit I- Data structures Introduction, Evaluation of Algorithms, Arrays, Spars...
PPT
linked list in c++
PPTX
Algorithm and Data Structures - Basic of IT Problem Solving
PDF
week15a.pdf
PPTX
Shark
PDF
Tulsa techfest Spark Core Aug 5th 2016
PPT
Fallsem2015 16 cp1699-20-jul-2015_rm01_stacks_and_queues
PPTX
Large-scale Recommendation Systems on Just a PC
PPTX
Data structure basic concepts and sparse
lecture02-cpp.ppt
lecture02-cpp.ppt
C++ - A powerful and system level language
DSJ_Unit I & II.pdf
Data structure and algorithm using java
lecture5-cpp.pptintroduccionaC++basicoye
Introduction to Inheritance in C plus plus
UsingCPP_for_Artist.ppt
A full Machine learning pipeline in Scikit-learn vs in scala-Spark: pros and ...
c++ ppt.ppt
AN introduction to Software Engineering and Data.pptx
Unit I- Data structures Introduction, Evaluation of Algorithms, Arrays, Spars...
linked list in c++
Algorithm and Data Structures - Basic of IT Problem Solving
week15a.pdf
Shark
Tulsa techfest Spark Core Aug 5th 2016
Fallsem2015 16 cp1699-20-jul-2015_rm01_stacks_and_queues
Large-scale Recommendation Systems on Just a PC
Data structure basic concepts and sparse
Ad

More from SanjeevKumarSinha13 (7)

PPT
INT529 zero lecture.pptdsfsdffewwretetrtetretr
PPT
ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 c...
PPTX
inputdevices.pptx
PDF
Lecture1-2_19395_Ch 1- Generic Skill.pdf
PDF
Lecture6-7_19395_Lecture1-2_19395_CH 2- Managing Self.pdf
PPTX
Lecture1-2_19395_Ch 1- Generic Skills.pptx
PDF
Lecture1-2_19395_Ch 1- Generic Skills.pdf
INT529 zero lecture.pptdsfsdffewwretetrtetretr
ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 ch3 c...
inputdevices.pptx
Lecture1-2_19395_Ch 1- Generic Skill.pdf
Lecture6-7_19395_Lecture1-2_19395_CH 2- Managing Self.pdf
Lecture1-2_19395_Ch 1- Generic Skills.pptx
Lecture1-2_19395_Ch 1- Generic Skills.pdf
Ad

Recently uploaded (20)

PPTX
additive manufacturing of ss316l using mig welding
PPTX
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
PPTX
OOP with Java - Java Introduction (Basics)
PPTX
Geodesy 1.pptx...............................................
PPTX
CH1 Production IntroductoryConcepts.pptx
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
PPTX
Strings in CPP - Strings in C++ are sequences of characters used to store and...
PPTX
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
PPTX
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
PPTX
Sustainable Sites - Green Building Construction
PPTX
web development for engineering and engineering
PDF
Embodied AI: Ushering in the Next Era of Intelligent Systems
PDF
Operating System & Kernel Study Guide-1 - converted.pdf
PDF
Structs to JSON How Go Powers REST APIs.pdf
PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PDF
Model Code of Practice - Construction Work - 21102022 .pdf
PPTX
bas. eng. economics group 4 presentation 1.pptx
PDF
composite construction of structures.pdf
additive manufacturing of ss316l using mig welding
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
OOP with Java - Java Introduction (Basics)
Geodesy 1.pptx...............................................
CH1 Production IntroductoryConcepts.pptx
UNIT-1 - COAL BASED THERMAL POWER PLANTS
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
Strings in CPP - Strings in C++ are sequences of characters used to store and...
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
Sustainable Sites - Green Building Construction
web development for engineering and engineering
Embodied AI: Ushering in the Next Era of Intelligent Systems
Operating System & Kernel Study Guide-1 - converted.pdf
Structs to JSON How Go Powers REST APIs.pdf
CYBER-CRIMES AND SECURITY A guide to understanding
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
Model Code of Practice - Construction Work - 21102022 .pdf
bas. eng. economics group 4 presentation 1.pptx
composite construction of structures.pdf

lecture1.ppt

  • 2. Outline • Overview of the Course • Queues • Stacks
  • 3. Goals of the Course • Become familiar with some of the fundamental data structures in computer science • Improve ability to solve problems abstractly – data structures are the building blocks • Improve ability to analyze your algorithms – prove correctness – gauge (and improve) time complexity • Become modestly skilled with the UNIX operating system and X-windows (you’ll need this in upcoming courses)
  • 4. Observation • All programs manipulate data – programs process, store, display, gather – data can be information, numbers, images, sound • Each program must decide how to store data • Choice influences program at every level – execution speed – memory requirements – maintenance (debugging, extending, etc.)
  • 5. What is a Data Structure? data structure -
  • 6. What is an Abstract Data Type? Abstract Data Type (ADT) - 1) An opportunity for an acronym 2) Mathematical description of an object and the set of operations on the object
  • 7. Data Structures : Algorithms • Algorithm – A high level, language independent description of a step-by-step process for solving a problem • Data Structure – A set of algorithms which implement an ADT
  • 8. Why so many data structures? Ideal data structure: fast, elegant, memory efficient Generates tensions: – time vs. space – performance vs. elegance – generality vs. simplicity – one operation’s performance vs. another’s Dictionary ADT – list – binary search tree – AVL tree – Splay tree – Red-Black tree – hash table
  • 9. Code Implementation • Theoretically – abstract base class describes ADT – inherited implementations implement data structures – can change data structures transparently (to client code) • Practice – different implementations sometimes suggest different interfaces (generality vs. simplicity) – performance of a data structure may influence form of client code (time vs. space, one operation vs. another)
  • 10. ADT Presentation Algorithm • Present an ADT • Motivate with some applications • Repeat until browned entirely through – develop a data structure for the ADT – analyze its properties • efficiency • correctness • limitations • ease of programming • Contrast data structure’s strengths and weaknesses – understand when to use each one
  • 11. Queue ADT • Queue operations – create – destroy – enqueue – dequeue – is_empty • Queue property: if x is enQed before y is enQed, then x will be deQed before y is deQed FIFO: First In First Out F E D C B enqueue dequeue G A
  • 12. Applications of the Q • Hold jobs for a printer • Store packets on network routers • Hold memory “freelists” • Make waitlists fair • Breadth first search
  • 13. Circular Array Q Data Structure void enqueue(Object x) { Q[back] = x back = (back + 1) % size } Object dequeue() { x = Q[front] front = (front + 1) % size return x } b c d e f Q 0 size - 1 front back This is pseudocode. Do not correct my semicolons. When is the Q empty? Are there error situations this code will not catch? What are some limitations of this structure?
  • 14. Q Example enqueue R enqueue O dequeue enqueue T enqueue A enqueue T dequeue dequeue enqueue E dequeue
  • 15. Linked List Q Data Structure b c d e f front back void enqueue(Object x) { if (is_empty()) front = back = new Node(x) else back->next = new Node(x) back = back->next } Object dequeue() { assert(!is_empty) return_data = front->data temp = front front = front->next delete temp return temp->data }
  • 16. Circular Array vs. Linked List
  • 17. LIFO Stack ADT • Stack operations – create – destroy – push – pop – top – is_empty • Stack property: if x is on the stack before y is pushed, then x will be popped after y is popped LIFO: Last In First Out A B C D E F E D C B A F
  • 18. Stacks in Practice • Function call stack • Removing recursion • Balancing symbols (parentheses) • Evaluating Reverse Polish Notation • Depth first search
  • 19. Array Stack Data Structure S 0 size - 1 f e d c b void push(Object x) { assert(!is_full()) S[back] = x back++ } Object top() { assert(!is_empty()) return S[back - 1] } back Object pop() { back-- return S[back] } bool is_full() { return back == size }
  • 20. Linked List Stack Data Structure b c d e f back void push(Object x) { temp = back back = new Node(x) back->next = temp } Object top() { assert(!is_empty()) return back->data } Object pop() { assert(!is_empty()) return_data = back->data temp = back back = back->next return return_data }
  • 21. Data structures you should already know • Arrays • Linked lists • Trees • Queues • Stacks