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

More Related Content

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

Collections
CollectionsCollections
Collections
sagsharma
 
Collections and its types in C# (with examples)
Collections and its types in C# (with examples)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#Data structures in c#
Data structures in c#
SivaSankar Gorantla
 
stack.ppt
stack.pptstack.ppt
stack.ppt
ssuserec1395
 
DS UNIT 1.pdf
DS UNIT 1.pdfDS UNIT 1.pdf
DS UNIT 1.pdf
SeethaDinesh
 
DS UNIT 1.pdf
DS UNIT 1.pdfDS UNIT 1.pdf
DS UNIT 1.pdf
SeethaDinesh
 
Lab Manual-OOP.pdf
Lab Manual-OOP.pdfLab Manual-OOP.pdf
Lab Manual-OOP.pdf
MUNAZARAZZAQELEA
 
Lec2
Lec2Lec2
Lec2
Nikhil Chilwant
 
Array properties
Array propertiesArray properties
Array properties
Shravan Sharma
 
stack_presentaton_HUSNAIN[2].pojklklklptx
stack_presentaton_HUSNAIN[2].pojklklklptxstack_presentaton_HUSNAIN[2].pojklklklptx
stack_presentaton_HUSNAIN[2].pojklklklptx
HusnainNaqvi2
 
TSAT Presentation1.pptx
TSAT Presentation1.pptxTSAT Presentation1.pptx
TSAT Presentation1.pptx
Rajitha Reddy Alugati
 
DS Complete notes for Computer science and Engineering
DS Complete notes for Computer science and EngineeringDS 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.......Collection Framework.power point presentation.......
Collection Framework.power point presentation.......
Betty333100
 
Stack linked list
Stack linked listStack linked list
Stack linked list
bhargav0077
 
Data -structures for class 12 , easy ppt
Data -structures for class 12 , easy pptData -structures for class 12 , easy ppt
Data -structures for class 12 , easy ppt
anikedheikhamsingh
 
Array list(1)
Array list(1)Array list(1)
Array list(1)
abdullah619
 
Unit i(dsc++)
Unit i(dsc++)Unit i(dsc++)
Unit i(dsc++)
Durga Devi
 
Lec3
Lec3Lec3
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 answeredU-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#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)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].pojklklklptxstack_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 EngineeringDS 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.......Collection Framework.power point presentation.......
Collection Framework.power point presentation.......
Betty333100
 
Stack linked list
Stack linked listStack linked list
Stack linked list
bhargav0077
 
Data -structures for class 12 , easy ppt
Data -structures for class 12 , easy pptData -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 answeredU-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#Data Structure In C#
Data Structure In C#
Shahzad
 

Recently uploaded (20)

Medical Device Cybersecurity Threat & Risk Scoring
Medical Device Cybersecurity Threat & Risk ScoringMedical Device Cybersecurity Threat & Risk Scoring
Medical Device Cybersecurity Threat & Risk Scoring
ICS
 
Adobe Media Encoder Crack FREE Download 2025
Adobe Media Encoder  Crack FREE Download 2025Adobe Media Encoder  Crack FREE Download 2025
Adobe Media Encoder Crack FREE Download 2025
zafranwaqar90
 
Top 12 Most Useful AngularJS Development Tools to Use in 2025
Top 12 Most Useful AngularJS Development Tools to Use in 2025Top 12 Most Useful AngularJS Development Tools to Use in 2025
Top 12 Most Useful AngularJS Development Tools to Use in 2025
GrapesTech Solutions
 
Sequence Diagrams With Pictures (1).pptx
Sequence Diagrams With Pictures (1).pptxSequence Diagrams With Pictures (1).pptx
Sequence Diagrams With Pictures (1).pptx
aashrithakondapalli8
 
Wilcom Embroidery Studio Crack 2025 For Windows
Wilcom Embroidery Studio Crack 2025 For WindowsWilcom Embroidery Studio Crack 2025 For Windows
Wilcom Embroidery Studio Crack 2025 For Windows
Google
 
Adobe InDesign Crack FREE Download 2025 link
Adobe InDesign Crack FREE Download 2025 linkAdobe InDesign Crack FREE Download 2025 link
Adobe InDesign Crack FREE Download 2025 link
mahmadzubair09
 
Why Tapitag Ranks Among the Best Digital Business Card Providers
Why Tapitag Ranks Among the Best Digital Business Card ProvidersWhy Tapitag Ranks Among the Best Digital Business Card Providers
Why Tapitag Ranks Among the Best Digital Business Card Providers
Tapitag
 
The Elixir Developer - All Things Open
The Elixir Developer - All Things OpenThe Elixir Developer - All Things Open
The Elixir Developer - All Things Open
Carlo Gilmar Padilla Santana
 
Programs as Values - Write code and don't get lost
Programs as Values - Write code and don't get lostPrograms as Values - Write code and don't get lost
Programs as Values - Write code and don't get lost
Pierangelo Cecchetto
 
AEM User Group DACH - 2025 Inaugural Meeting
AEM User Group DACH - 2025 Inaugural MeetingAEM User Group DACH - 2025 Inaugural Meeting
AEM User Group DACH - 2025 Inaugural Meeting
jennaf3
 
NYC ACE 08-May-2025-Combined Presentation.pdf
NYC ACE 08-May-2025-Combined Presentation.pdfNYC ACE 08-May-2025-Combined Presentation.pdf
NYC ACE 08-May-2025-Combined Presentation.pdf
AUGNYC
 
What Do Candidates Really Think About AI-Powered Recruitment Tools?
What Do Candidates Really Think About AI-Powered Recruitment Tools?What Do Candidates Really Think About AI-Powered Recruitment Tools?
What Do Candidates Really Think About AI-Powered Recruitment Tools?
HireME
 
wAIred_LearnWithOutAI_JCON_14052025.pptx
wAIred_LearnWithOutAI_JCON_14052025.pptxwAIred_LearnWithOutAI_JCON_14052025.pptx
wAIred_LearnWithOutAI_JCON_14052025.pptx
SimonedeGijt
 
Adobe Audition Crack FRESH Version 2025 FREE
Adobe Audition Crack FRESH Version 2025 FREEAdobe Audition Crack FRESH Version 2025 FREE
Adobe Audition Crack FRESH Version 2025 FREE
zafranwaqar90
 
Digital Twins Software Service in Belfast
Digital Twins Software Service in BelfastDigital Twins Software Service in Belfast
Digital Twins Software Service in Belfast
julia smits
 
Do not let staffing shortages and limited fiscal view hamper your cause
Do not let staffing shortages and limited fiscal view hamper your causeDo not let staffing shortages and limited fiscal view hamper your cause
Do not let staffing shortages and limited fiscal view hamper your cause
Fexle Services Pvt. Ltd.
 
Serato DJ Pro Crack Latest Version 2025??
Serato DJ Pro Crack Latest Version 2025??Serato DJ Pro Crack Latest Version 2025??
Serato DJ Pro Crack Latest Version 2025??
Web Designer
 
Robotic Process Automation (RPA) Software Development Services.pptx
Robotic Process Automation (RPA) Software Development Services.pptxRobotic Process Automation (RPA) Software Development Services.pptx
Robotic Process Automation (RPA) Software Development Services.pptx
julia smits
 
Troubleshooting JVM Outages – 3 Fortune 500 case studies
Troubleshooting JVM Outages – 3 Fortune 500 case studiesTroubleshooting JVM Outages – 3 Fortune 500 case studies
Troubleshooting JVM Outages – 3 Fortune 500 case studies
Tier1 app
 
Unit Two - Java Architecture and OOPS
Unit Two  -   Java Architecture and OOPSUnit Two  -   Java Architecture and OOPS
Unit Two - Java Architecture and OOPS
Nabin Dhakal
 
Medical Device Cybersecurity Threat & Risk Scoring
Medical Device Cybersecurity Threat & Risk ScoringMedical Device Cybersecurity Threat & Risk Scoring
Medical Device Cybersecurity Threat & Risk Scoring
ICS
 
Adobe Media Encoder Crack FREE Download 2025
Adobe Media Encoder  Crack FREE Download 2025Adobe Media Encoder  Crack FREE Download 2025
Adobe Media Encoder Crack FREE Download 2025
zafranwaqar90
 
Top 12 Most Useful AngularJS Development Tools to Use in 2025
Top 12 Most Useful AngularJS Development Tools to Use in 2025Top 12 Most Useful AngularJS Development Tools to Use in 2025
Top 12 Most Useful AngularJS Development Tools to Use in 2025
GrapesTech Solutions
 
Sequence Diagrams With Pictures (1).pptx
Sequence Diagrams With Pictures (1).pptxSequence Diagrams With Pictures (1).pptx
Sequence Diagrams With Pictures (1).pptx
aashrithakondapalli8
 
Wilcom Embroidery Studio Crack 2025 For Windows
Wilcom Embroidery Studio Crack 2025 For WindowsWilcom Embroidery Studio Crack 2025 For Windows
Wilcom Embroidery Studio Crack 2025 For Windows
Google
 
Adobe InDesign Crack FREE Download 2025 link
Adobe InDesign Crack FREE Download 2025 linkAdobe InDesign Crack FREE Download 2025 link
Adobe InDesign Crack FREE Download 2025 link
mahmadzubair09
 
Why Tapitag Ranks Among the Best Digital Business Card Providers
Why Tapitag Ranks Among the Best Digital Business Card ProvidersWhy Tapitag Ranks Among the Best Digital Business Card Providers
Why Tapitag Ranks Among the Best Digital Business Card Providers
Tapitag
 
Programs as Values - Write code and don't get lost
Programs as Values - Write code and don't get lostPrograms as Values - Write code and don't get lost
Programs as Values - Write code and don't get lost
Pierangelo Cecchetto
 
AEM User Group DACH - 2025 Inaugural Meeting
AEM User Group DACH - 2025 Inaugural MeetingAEM User Group DACH - 2025 Inaugural Meeting
AEM User Group DACH - 2025 Inaugural Meeting
jennaf3
 
NYC ACE 08-May-2025-Combined Presentation.pdf
NYC ACE 08-May-2025-Combined Presentation.pdfNYC ACE 08-May-2025-Combined Presentation.pdf
NYC ACE 08-May-2025-Combined Presentation.pdf
AUGNYC
 
What Do Candidates Really Think About AI-Powered Recruitment Tools?
What Do Candidates Really Think About AI-Powered Recruitment Tools?What Do Candidates Really Think About AI-Powered Recruitment Tools?
What Do Candidates Really Think About AI-Powered Recruitment Tools?
HireME
 
wAIred_LearnWithOutAI_JCON_14052025.pptx
wAIred_LearnWithOutAI_JCON_14052025.pptxwAIred_LearnWithOutAI_JCON_14052025.pptx
wAIred_LearnWithOutAI_JCON_14052025.pptx
SimonedeGijt
 
Adobe Audition Crack FRESH Version 2025 FREE
Adobe Audition Crack FRESH Version 2025 FREEAdobe Audition Crack FRESH Version 2025 FREE
Adobe Audition Crack FRESH Version 2025 FREE
zafranwaqar90
 
Digital Twins Software Service in Belfast
Digital Twins Software Service in BelfastDigital Twins Software Service in Belfast
Digital Twins Software Service in Belfast
julia smits
 
Do not let staffing shortages and limited fiscal view hamper your cause
Do not let staffing shortages and limited fiscal view hamper your causeDo not let staffing shortages and limited fiscal view hamper your cause
Do not let staffing shortages and limited fiscal view hamper your cause
Fexle Services Pvt. Ltd.
 
Serato DJ Pro Crack Latest Version 2025??
Serato DJ Pro Crack Latest Version 2025??Serato DJ Pro Crack Latest Version 2025??
Serato DJ Pro Crack Latest Version 2025??
Web Designer
 
Robotic Process Automation (RPA) Software Development Services.pptx
Robotic Process Automation (RPA) Software Development Services.pptxRobotic Process Automation (RPA) Software Development Services.pptx
Robotic Process Automation (RPA) Software Development Services.pptx
julia smits
 
Troubleshooting JVM Outages – 3 Fortune 500 case studies
Troubleshooting JVM Outages – 3 Fortune 500 case studiesTroubleshooting JVM Outages – 3 Fortune 500 case studies
Troubleshooting JVM Outages – 3 Fortune 500 case studies
Tier1 app
 
Unit Two - Java Architecture and OOPS
Unit Two  -   Java Architecture and OOPSUnit Two  -   Java Architecture and OOPS
Unit Two - Java Architecture and OOPS
Nabin Dhakal
 
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
  翻译: