SlideShare a Scribd company logo
CSE 373
Data Structures and Algorithms
Lecture 1: Introduction; ADTs; Stacks; Eclipse
Course objectives
 Learn basic data structures and algorithms
 data structures – how data is organized
 algorithms – unambiguous sequence of steps to compute
something
 algorithm analysis – determining how long an algorithm will
take to solve a problem
 Become a better software developer
 "Data Structures + Algorithms = Programs"
-- Niklaus Wirth, author of Pascal language
2
Abstract Data Types
 abstract data type (ADT): A specification of a collection of
data and the operations that can be performed on it.
 Describes what a collection does, not how it does it
 Described in Java with interfaces (e.g., List, Map, Set)
 Separate from implementation
 ADTs can be implemented in multiple ways by classes:
 ArrayList and LinkedList implement List
 HashSet and TreeSet implement Set
 LinkedList , ArrayDeque, etc. implement
Queue
 Java messed up on Stack—there's no Stack interface, just a class.
3
List ADT
 An ordered collection the form A0, A1, ..., AN-1, where N is the
size of the list
 Operations described in Java's List interface (subset):
 ArrayList and LinkedList are implementations
4
add(elt, index) inserts the element at the specified position
in the list
remove(index) removes the element at the specified position
get(index) returns the element at the specified position
set(index, elt) replaces the element at the specified position
with the specified element
contains(elt) returns true if the list contains the element
size() returns the number of elements in the list
Stack ADT
5
 stack: a list with the restriction that insertions/deletions
can only be performed at the top/end of the list
 Last-In, First-Out ("LIFO")
 The elements are stored in order of insertion,
but we do not think of them as having indexes.
 The client can only add/remove/examine
the last element added (the "top").
 basic stack operations:
 push: Add an element to the top.
 pop: Remove the top element.
 peek: Examine the top element.
Applications of Stacks
 Programming languages:
 method calls are placed onto a stack (call=push, return=pop)
 Matching up related pairs of things:
 find out whether a string is a palindrome
 examine a file to see if its braces { } and other operators
match
 Sophisticated algorithms:
 searching through a maze with "backtracking"
 many programs use an "undo stack" of previous operations
6
method
3
return var
local vars
parameters
method
2
return var
local vars
parameters
method
1
return var
local vars
parameters
Class Stack
7
Stack<Integer> s = new Stack<Integer>();
s.push(42);
s.push(-3);
s.push(17); // bottom [42, -3, 17] top
System.out.println(s.pop()); // 17
Stack<E>() constructs a new stack with elements of type E
push(value) places given value on top of stack
pop() removes top value from stack and returns it;
throws EmptyStackException if stack is
empty
peek() returns top value from stack without removing
it;
throws EmptyStackException if stack is
empty
size() returns number of elements in stack
isEmpty() returns true if stack has no elements
Stack limitations/idioms
 Remember: You can’t loop over a stack like you do a list.
Stack<Integer> s = new Stack<Integer>();
...
for (int i = 0; i < s.size(); i++) {
do something with s.get(i);
}
 Instead, you pull contents out of the stack to view them.
 Idiom: Remove each element until the stack is empty.
while (!s.isEmpty()) {
do something with s.pop();
}
8
Exercise
9
 Write a method symbolsBalanced that accepts a
String as a parameter and returns whether or not the
parentheses and the curly brackets in that String are
balanced as they would have to be in a valid Java
program.
 Use a Stack to solve this problem.
Eclipse concepts
10
 workspace: a collection of projects
 stored as a directory
 project: a Java program
 must have your files in a project in order to be able to
compile, debug and run them
 by default stored in a directory in your workspace
 perspective: a view of your current project using a set
of pre-laid-out windows and menus
 Java perspective
 debugging perspective
Ad

Recommended

Lec2
Lec2
Anjneya Varshney
 
LectureNotes-06-DSA
LectureNotes-06-DSA
Haitham El-Ghareeb
 
Basic data-structures-v.1.1
Basic data-structures-v.1.1
BG Java EE Course
 
Stack and Queue
Stack and Queue
Apurbo Datta
 
Collections framework
Collections framework
Anand Buddarapu
 
2 a stacks
2 a stacks
Nguync91368
 
Introduction and BackgroundIn recent lectures we discussed usi.pdf
Introduction and BackgroundIn recent lectures we discussed usi.pdf
arpitaeron555
 
queuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbb
queuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbb
RAtna29
 
Collections
Collections
sagsharma
 
Collections and its types in C# (with examples)
Collections and its types in C# (with examples)
Aijaz Ali Abro
 
Data structures in c#
Data structures in c#
SivaSankar Gorantla
 
stack.ppt
stack.ppt
ssuserec1395
 
DS UNIT 1.pdf
DS UNIT 1.pdf
SeethaDinesh
 
DS UNIT 1.pdf
DS UNIT 1.pdf
SeethaDinesh
 
Lab Manual-OOP.pdf
Lab Manual-OOP.pdf
MUNAZARAZZAQELEA
 
Lec2
Lec2
Nikhil Chilwant
 
Array properties
Array properties
Shravan Sharma
 
stack_presentaton_HUSNAIN[2].pojklklklptx
stack_presentaton_HUSNAIN[2].pojklklklptx
HusnainNaqvi2
 
TSAT Presentation1.pptx
TSAT Presentation1.pptx
Rajitha Reddy Alugati
 
DS Complete notes for Computer science and Engineering
DS Complete notes for Computer science and Engineering
RAJASEKHARV8
 
Collection Framework.power point presentation.......
Collection Framework.power point presentation.......
Betty333100
 
Stack linked list
Stack linked list
bhargav0077
 
Data -structures for class 12 , easy ppt
Data -structures for class 12 , easy ppt
anikedheikhamsingh
 
Array list(1)
Array list(1)
abdullah619
 
Unit i(dsc++)
Unit i(dsc++)
Durga Devi
 
Lec3
Lec3
Anjneya Varshney
 
U-III-part-1.pptxpart 1 of Java and hardware coding questions are answered
U-III-part-1.pptxpart 1 of Java and hardware coding questions are answered
zainmkhan20
 
Data Structure In C#
Data Structure In C#
Shahzad
 
Emvigo Capability Deck 2025: Accelerating Innovation Through Intelligent Soft...
Emvigo Capability Deck 2025: Accelerating Innovation Through Intelligent Soft...
Emvigo Technologies
 
Why Every Growing Business Needs a Staff Augmentation Company IN USA.pdf
Why Every Growing Business Needs a Staff Augmentation Company IN USA.pdf
mary rojas
 

More Related Content

Similar to introduction stacks in data structures and algorithms (20)

Collections
Collections
sagsharma
 
Collections and its types in C# (with examples)
Collections and its types in C# (with examples)
Aijaz Ali Abro
 
Data structures in c#
Data structures in c#
SivaSankar Gorantla
 
stack.ppt
stack.ppt
ssuserec1395
 
DS UNIT 1.pdf
DS UNIT 1.pdf
SeethaDinesh
 
DS UNIT 1.pdf
DS UNIT 1.pdf
SeethaDinesh
 
Lab Manual-OOP.pdf
Lab Manual-OOP.pdf
MUNAZARAZZAQELEA
 
Lec2
Lec2
Nikhil Chilwant
 
Array properties
Array properties
Shravan Sharma
 
stack_presentaton_HUSNAIN[2].pojklklklptx
stack_presentaton_HUSNAIN[2].pojklklklptx
HusnainNaqvi2
 
TSAT Presentation1.pptx
TSAT Presentation1.pptx
Rajitha Reddy Alugati
 
DS Complete notes for Computer science and Engineering
DS Complete notes for Computer science and Engineering
RAJASEKHARV8
 
Collection Framework.power point presentation.......
Collection Framework.power point presentation.......
Betty333100
 
Stack linked list
Stack linked list
bhargav0077
 
Data -structures for class 12 , easy ppt
Data -structures for class 12 , easy ppt
anikedheikhamsingh
 
Array list(1)
Array list(1)
abdullah619
 
Unit i(dsc++)
Unit i(dsc++)
Durga Devi
 
Lec3
Lec3
Anjneya Varshney
 
U-III-part-1.pptxpart 1 of Java and hardware coding questions are answered
U-III-part-1.pptxpart 1 of Java and hardware coding questions are answered
zainmkhan20
 
Data Structure In C#
Data Structure In C#
Shahzad
 
Collections and its types in C# (with examples)
Collections and its types in C# (with examples)
Aijaz Ali Abro
 
stack_presentaton_HUSNAIN[2].pojklklklptx
stack_presentaton_HUSNAIN[2].pojklklklptx
HusnainNaqvi2
 
DS Complete notes for Computer science and Engineering
DS Complete notes for Computer science and Engineering
RAJASEKHARV8
 
Collection Framework.power point presentation.......
Collection Framework.power point presentation.......
Betty333100
 
Stack linked list
Stack linked list
bhargav0077
 
Data -structures for class 12 , easy ppt
Data -structures for class 12 , easy ppt
anikedheikhamsingh
 
U-III-part-1.pptxpart 1 of Java and hardware coding questions are answered
U-III-part-1.pptxpart 1 of Java and hardware coding questions are answered
zainmkhan20
 
Data Structure In C#
Data Structure In C#
Shahzad
 

Recently uploaded (20)

Emvigo Capability Deck 2025: Accelerating Innovation Through Intelligent Soft...
Emvigo Capability Deck 2025: Accelerating Innovation Through Intelligent Soft...
Emvigo Technologies
 
Why Every Growing Business Needs a Staff Augmentation Company IN USA.pdf
Why Every Growing Business Needs a Staff Augmentation Company IN USA.pdf
mary rojas
 
Reimagining Software Development and DevOps with Agentic AI
Reimagining Software Development and DevOps with Agentic AI
Maxim Salnikov
 
Key Challenges in Troubleshooting Customer On-Premise Applications
Key Challenges in Troubleshooting Customer On-Premise Applications
Tier1 app
 
Automated Migration of ESRI Geodatabases Using XML Control Files and FME
Automated Migration of ESRI Geodatabases Using XML Control Files and FME
Safe Software
 
Modern Platform Engineering with Choreo - The AI-Native Internal Developer Pl...
Modern Platform Engineering with Choreo - The AI-Native Internal Developer Pl...
WSO2
 
Streamlining CI/CD with FME Flow: A Practical Guide
Streamlining CI/CD with FME Flow: A Practical Guide
Safe Software
 
IObit Driver Booster Pro 12 Crack Latest Version Download
IObit Driver Booster Pro 12 Crack Latest Version Download
pcprocore
 
ERP Systems in the UAE: Driving Business Transformation with Smart Solutions
ERP Systems in the UAE: Driving Business Transformation with Smart Solutions
dheeodoo
 
Introduction to Agile Frameworks for Product Managers.pdf
Introduction to Agile Frameworks for Product Managers.pdf
Ali Vahed
 
CodeCleaner: Mitigating Data Contamination for LLM Benchmarking
CodeCleaner: Mitigating Data Contamination for LLM Benchmarking
arabelatso
 
SAP PM Module Level-IV Training Complete.ppt
SAP PM Module Level-IV Training Complete.ppt
MuhammadShaheryar36
 
Advance Doctor Appointment Booking App With Online Payment
Advance Doctor Appointment Booking App With Online Payment
AxisTechnolabs
 
Simplify Task, Team, and Project Management with Orangescrum Work
Simplify Task, Team, and Project Management with Orangescrum Work
Orangescrum
 
arctitecture application system design os dsa
arctitecture application system design os dsa
za241967
 
Application Modernization with Choreo - The AI-Native Internal Developer Plat...
Application Modernization with Choreo - The AI-Native Internal Developer Plat...
WSO2
 
Threat Modeling a Batch Job Framework - Teri Radichel - AWS re:Inforce 2025
Threat Modeling a Batch Job Framework - Teri Radichel - AWS re:Inforce 2025
2nd Sight Lab
 
Canva Pro Crack Free Download 2025-FREE LATEST
Canva Pro Crack Free Download 2025-FREE LATEST
grete1122g
 
Microsoft-365-Administrator-s-Guide1.pdf
Microsoft-365-Administrator-s-Guide1.pdf
mazharatknl
 
Decipher SEO Solutions for your startup needs.
Decipher SEO Solutions for your startup needs.
mathai2
 
Emvigo Capability Deck 2025: Accelerating Innovation Through Intelligent Soft...
Emvigo Capability Deck 2025: Accelerating Innovation Through Intelligent Soft...
Emvigo Technologies
 
Why Every Growing Business Needs a Staff Augmentation Company IN USA.pdf
Why Every Growing Business Needs a Staff Augmentation Company IN USA.pdf
mary rojas
 
Reimagining Software Development and DevOps with Agentic AI
Reimagining Software Development and DevOps with Agentic AI
Maxim Salnikov
 
Key Challenges in Troubleshooting Customer On-Premise Applications
Key Challenges in Troubleshooting Customer On-Premise Applications
Tier1 app
 
Automated Migration of ESRI Geodatabases Using XML Control Files and FME
Automated Migration of ESRI Geodatabases Using XML Control Files and FME
Safe Software
 
Modern Platform Engineering with Choreo - The AI-Native Internal Developer Pl...
Modern Platform Engineering with Choreo - The AI-Native Internal Developer Pl...
WSO2
 
Streamlining CI/CD with FME Flow: A Practical Guide
Streamlining CI/CD with FME Flow: A Practical Guide
Safe Software
 
IObit Driver Booster Pro 12 Crack Latest Version Download
IObit Driver Booster Pro 12 Crack Latest Version Download
pcprocore
 
ERP Systems in the UAE: Driving Business Transformation with Smart Solutions
ERP Systems in the UAE: Driving Business Transformation with Smart Solutions
dheeodoo
 
Introduction to Agile Frameworks for Product Managers.pdf
Introduction to Agile Frameworks for Product Managers.pdf
Ali Vahed
 
CodeCleaner: Mitigating Data Contamination for LLM Benchmarking
CodeCleaner: Mitigating Data Contamination for LLM Benchmarking
arabelatso
 
SAP PM Module Level-IV Training Complete.ppt
SAP PM Module Level-IV Training Complete.ppt
MuhammadShaheryar36
 
Advance Doctor Appointment Booking App With Online Payment
Advance Doctor Appointment Booking App With Online Payment
AxisTechnolabs
 
Simplify Task, Team, and Project Management with Orangescrum Work
Simplify Task, Team, and Project Management with Orangescrum Work
Orangescrum
 
arctitecture application system design os dsa
arctitecture application system design os dsa
za241967
 
Application Modernization with Choreo - The AI-Native Internal Developer Plat...
Application Modernization with Choreo - The AI-Native Internal Developer Plat...
WSO2
 
Threat Modeling a Batch Job Framework - Teri Radichel - AWS re:Inforce 2025
Threat Modeling a Batch Job Framework - Teri Radichel - AWS re:Inforce 2025
2nd Sight Lab
 
Canva Pro Crack Free Download 2025-FREE LATEST
Canva Pro Crack Free Download 2025-FREE LATEST
grete1122g
 
Microsoft-365-Administrator-s-Guide1.pdf
Microsoft-365-Administrator-s-Guide1.pdf
mazharatknl
 
Decipher SEO Solutions for your startup needs.
Decipher SEO Solutions for your startup needs.
mathai2
 
Ad

introduction stacks in data structures and algorithms

  • 1. CSE 373 Data Structures and Algorithms Lecture 1: Introduction; ADTs; Stacks; Eclipse
  • 2. Course objectives  Learn basic data structures and algorithms  data structures – how data is organized  algorithms – unambiguous sequence of steps to compute something  algorithm analysis – determining how long an algorithm will take to solve a problem  Become a better software developer  "Data Structures + Algorithms = Programs" -- Niklaus Wirth, author of Pascal language 2
  • 3. Abstract Data Types  abstract data type (ADT): A specification of a collection of data and the operations that can be performed on it.  Describes what a collection does, not how it does it  Described in Java with interfaces (e.g., List, Map, Set)  Separate from implementation  ADTs can be implemented in multiple ways by classes:  ArrayList and LinkedList implement List  HashSet and TreeSet implement Set  LinkedList , ArrayDeque, etc. implement Queue  Java messed up on Stack—there's no Stack interface, just a class. 3
  • 4. List ADT  An ordered collection the form A0, A1, ..., AN-1, where N is the size of the list  Operations described in Java's List interface (subset):  ArrayList and LinkedList are implementations 4 add(elt, index) inserts the element at the specified position in the list remove(index) removes the element at the specified position get(index) returns the element at the specified position set(index, elt) replaces the element at the specified position with the specified element contains(elt) returns true if the list contains the element size() returns the number of elements in the list
  • 5. Stack ADT 5  stack: a list with the restriction that insertions/deletions can only be performed at the top/end of the list  Last-In, First-Out ("LIFO")  The elements are stored in order of insertion, but we do not think of them as having indexes.  The client can only add/remove/examine the last element added (the "top").  basic stack operations:  push: Add an element to the top.  pop: Remove the top element.  peek: Examine the top element.
  • 6. Applications of Stacks  Programming languages:  method calls are placed onto a stack (call=push, return=pop)  Matching up related pairs of things:  find out whether a string is a palindrome  examine a file to see if its braces { } and other operators match  Sophisticated algorithms:  searching through a maze with "backtracking"  many programs use an "undo stack" of previous operations 6 method 3 return var local vars parameters method 2 return var local vars parameters method 1 return var local vars parameters
  • 7. Class Stack 7 Stack<Integer> s = new Stack<Integer>(); s.push(42); s.push(-3); s.push(17); // bottom [42, -3, 17] top System.out.println(s.pop()); // 17 Stack<E>() constructs a new stack with elements of type E push(value) places given value on top of stack pop() removes top value from stack and returns it; throws EmptyStackException if stack is empty peek() returns top value from stack without removing it; throws EmptyStackException if stack is empty size() returns number of elements in stack isEmpty() returns true if stack has no elements
  • 8. Stack limitations/idioms  Remember: You can’t loop over a stack like you do a list. Stack<Integer> s = new Stack<Integer>(); ... for (int i = 0; i < s.size(); i++) { do something with s.get(i); }  Instead, you pull contents out of the stack to view them.  Idiom: Remove each element until the stack is empty. while (!s.isEmpty()) { do something with s.pop(); } 8
  • 9. Exercise 9  Write a method symbolsBalanced that accepts a String as a parameter and returns whether or not the parentheses and the curly brackets in that String are balanced as they would have to be in a valid Java program.  Use a Stack to solve this problem.
  • 10. Eclipse concepts 10  workspace: a collection of projects  stored as a directory  project: a Java program  must have your files in a project in order to be able to compile, debug and run them  by default stored in a directory in your workspace  perspective: a view of your current project using a set of pre-laid-out windows and menus  Java perspective  debugging perspective

Editor's Notes

  • #5: analogy: trays of food at the sizzler