SlideShare a Scribd company logo
1 of 23
Download to read offline
College of Computing & Information Technology
King Abdulaziz University
Data Structures I
CPCS-204 – Introduction
CPCS-204 – Data Structures I
Data Structures I: An Introduction page 2
© Dr. Jonathan (Yahya) Cazalas
Data Structures 1: Introduction
 Course Learning Outcomes
 Upon completion of this course, you will be able to:
1. Describe the needs of data structures in problem solving.
2. Design and implement abstract data types.
3. Represent and implement linear/non-linear data
structures.
4. Build stacks and queues using arrays and linked lists.
5. Select and apply appropriate data structures in problem
solving.
6. Select and apply basic searching and sorting algorithms
in problem solving.
7. Apply recursion to solve simple problems.
8. Trace the output of a given piece of code or algorithm.
Data Structures I: An Introduction page 3
© Dr. Jonathan (Yahya) Cazalas
Data Structures 1: Introduction
 How is CPCS-204 different than CPCS-203?
 CPCS-203 teaches how to program in Java
 Language basics, variable declarations, conditional
expressions, if statements, loops, functions, arrays,
structures, and even Object-Oriented programming
 This will not be covered in this class
 You will need to freshen up on your Java very quickly
 If you need help, but a good Java-language book or find a
quality reference online
 With respect to Java, we will cover:
 Arrays and array processing (although already taught)
 Some of the Java Collections as needed
Data Structures I: An Introduction page 4
© Dr. Jonathan (Yahya) Cazalas
Data Structures 1: Introduction
 The goals of Data Structures I:
 Improve knowledge of standard data structures
and abstract data types
 Improve knowledge of standard algorithms used
to solve several classical problems
 Cover some mathematical concepts that are
useful for the analysis of algorithms
 Analyze the efficiency of solutions to problems
 Learn about and be comfortable with recursion
Data Structures I: An Introduction page 5
© Dr. Jonathan (Yahya) Cazalas
Data Structures 1: Introduction
 The goals of Computer Science I:
 In CPCS-202 and 203, we only cared if we
found a solution to the problem at hand
 Didn’t really pay attention to the efficiency of the
answer
 For this class:
 We learn standard ways to solve problems
 And how to analyze the efficiency of those solutions
 Finally, we simply expand upon our knowledge of our
use of the JAVA programming language
Data Structures I: An Introduction page 6
© Dr. Jonathan (Yahya) Cazalas
Data Structures 1: Introduction
 Teaching Method:
 This class is NOT used to teach you JAVA
 The focus of CPCS-202 and 203 (not this class) is to
teach you JAVA
 You should know JAVA already
 In CPCS-202 and 203, majority of time was spent going
of syntax of JAVA
 Programs were often shown in class
 Programs were even written during class
 Essentially a requirement for any course teaching a
programming language
Data Structures I: An Introduction page 7
© Dr. Jonathan (Yahya) Cazalas
Data Structures 1: Introduction
 Teaching Method:
 Majority of this class is used covering new data
structures, abstract data types, and algorithm
analysis
 The teaching of these concepts dictate more
explanation and less of a focus on “code”
 Some code will be shown on the PowerPoint slides
 Such as after we explain a new abstract data type
 We’ll show the code of how you would implement it
 However, writing of actual code will most likely
never be done in class
 Again, that is not the purpose of this class
Data Structures I: An Introduction page 8
© Dr. Jonathan (Yahya) Cazalas
Data Structures 1: Introduction
 Example Problem:
 We will now go over two solutions to a problem
 The first is a straightforward solution that a CPCS-203
student should be able to come up with
 Doesn’t’ care about efficiency
 The second solution is one that a CPCS-204 student
should be able to come up with after some thought
 Cares about efficiency
 Hopefully this example will illustrate part of the
goal of this course
Data Structures I: An Introduction page 9
© Dr. Jonathan (Yahya) Cazalas
Data Structures 1: Introduction
 Max Number of 1’s:
 You are given an nxn integer array
 Say, for example, a 100x100 sized array
 Each row is filled with several 1’s followed by all
0’s
 Example:
 Row 1 may have 38 1’s followed by 62 0’s
 Row 2 may have 73 1’s followed by 27 0’s
 Row 3 may have 12 1’s followed by 82 0’s
 You get the idea
 The goal of the problem is to identify the row
that has the maximum number of 1’s.
Data Structures I: An Introduction page 10
© Dr. Jonathan (Yahya) Cazalas
Data Structures 1: Introduction
 Max Number of 1’s:
 Straightforward CPCS-203 style solution:
 Make a variable called MaxOnes and set equal
to 0
 For each row do the following:
 Start from the beginning of the row on the left side
 Scan left to right, counting the number of 1’s until the first zero
is encountered
 If the number of 1’s is greater than the value stored in
MaxOnes, update MaxOnes with the number of 1’s seen on
this row
 Clearly, this works
 But let’s see how long this algorithm will take
Data Structures I: An Introduction page 11
© Dr. Jonathan (Yahya) Cazalas
Data Structures 1: Introduction
 Max Number of 1’s:
 Analysis of Straightforward Solution:
 Basically we iterate through each square that contains
a 1, as well as the first 0 in each row
 If all cells were 0, we would only “visit” one cell per
row, resulting in n visited cells
 However, if all cells were 1’s, we would “visit” all of the
cells (n2 total)
 So in the worst case, the number of simple steps the
algorithm takes would be approximately n2
 This makes the running time of this algorithm O(n2)
 The meaning of this Big-O will be discussed later in the
semester
Data Structures I: An Introduction page 12
© Dr. Jonathan (Yahya) Cazalas
Data Structures 1: Introduction
 Max Number of 1’s:
 Analysis of Straightforward Solution:
 There seems to be extra work done here
 Once we know that a row has 12 1’s, for example, it
seems pointless to start checking at the beginning of
the next row
 Why not just start at column 12
 If it’s a 0, then that row can’t be the winner
 If it is a 1, then clearly there is no point in going back, on
that row, and checking the previous 11 squares
 This idea leads to a more efficient algorithm
Data Structures I: An Introduction page 13
© Dr. Jonathan (Yahya) Cazalas
Data Structures 1: Introduction
 Max Number of 1’s:
 More Efficient CPCS-204 style algorithm:
1. Initialize the current row and current column to 0
2. While the current row is less than n (or before the
last row)
a. While the cell at the current row and column is 1
 Increment the current column
b. Increment the current row
3. The current column index represents the
maximum number of 1’s seen
4. Now let’s trace through a couple of examples
Data Structures I: An Introduction page 14
© Dr. Jonathan (Yahya) Cazalas
Data Structures 1: Introduction
 Max Number of 1’s:
 Example 1:
1 1 0 0 0 0
0 0 0 0 0 0
1 1 1 0 0 0
1 1 1 0 0 0
1 1 1 1 1 0
1 1 1 1 0 0
Data Structures I: An Introduction page 15
© Dr. Jonathan (Yahya) Cazalas
Data Structures 1: Introduction
 Max Number of 1’s:
 Example 2:
0 0 0 0 0 0 0 0
1 1 0 0 0 0 0 0
1 0 0 0 0 0 0 0
1 1 1 0 0 0 0 0
1 1 1 1 0 0 0 0
1 1 1 1 1 1 0 0
1 1 1 1 1 1 1 0
1 1 1 1 1 1 1 1
Data Structures I: An Introduction page 16
© Dr. Jonathan (Yahya) Cazalas
Data Structures 1: Introduction
 Max Number of 1’s:
 Analysis of Better Solution:
 How many steps will this algorithm take, in terms of n?
 Each “step” taken by the algorithm either goes to the right
or down in the table.
 There are a maximum of n-1 steps to the right
 And a maximum of n-1 steps down that could be taken
 Thus the maximum number of “steps” that can be done
during this algorithm is approximately 2n
 And this is the worst case
 So the running time of this algorithm is O(n)
 An improvement of the previous algorithm
 Input size of 100 for n
 n2 would be 10,000 steps and 2n would be 200 steps
Data Structures I: An Introduction page 17
© Dr. Jonathan (Yahya) Cazalas
Data Structures 1: Introduction
 Implementing an Algorithm in JAVA:
 In this class, you will have an opportunity to
improve upon your ability to write programs that
implement an algorithm you have learned
 You must know the syntax of JAVA in order to
properly and effective do this
 There’s no set way to create code to implement
an algorithm
 But this example shows some steps you can take in
doing so
Data Structures I: An Introduction page 18
© Dr. Jonathan (Yahya) Cazalas
Data Structures 1: Introduction
 Implementing an Algorithm in JAVA:
 Here are some issues to think about:
1. What data structures are going to be used?
2. What functions are going to be used?
3. What run-time errors should we protect
against?
4. What atypical cases may we have to deal with?
5. What is an efficient way to execute the steps in
the algorithm?
Data Structures I: An Introduction page 19
© Dr. Jonathan (Yahya) Cazalas
Data Structures 1: Introduction
 Maximum Number of 1’s
 This was a creative exercise
 Much of what you learn in class will not be
 We have many set algorithms and data
structures that you will study
 Occasionally you will have to come up with new
ideas like this one
 Mostly, however, you will simply have to apply
the data structures and algorithms shown in
class fairly directly to solve the given problems
Data Structures I: An Introduction page 20
© Dr. Jonathan (Yahya) Cazalas
Data Structures 1: Introduction
Are
You
Excited?
Data Structures I: An Introduction page 21
© Dr. Jonathan (Yahya) Cazalas
Daily FAIL Picture
 Fail pictures
 During the slides (or at the end), we will often
give a funny “fail” picture or a “human stupidity”
picture
 Helps to “lighten things up”
 So here you go:
Data Structures I: An Introduction page 22
© Dr. Jonathan (Yahya) Cazalas
Human Stupidity
College of Computing & Information Technology
King Abdulaziz University
Data Structures I
CPCS-204 – Introduction
CPCS-204 – Data Structures I

More Related Content

What's hot

Analysis of algorithms
Analysis of algorithmsAnalysis of algorithms
Analysis of algorithmsiqbalphy1
 
Data structure and algorithm notes
Data structure and algorithm notesData structure and algorithm notes
Data structure and algorithm notessuman khadka
 
Data structures and algorithms
Data structures and algorithmsData structures and algorithms
Data structures and algorithmsJulie Iskander
 
UNIT II LINEAR DATA STRUCTURES – STACKS, QUEUES
UNIT II 	LINEAR DATA STRUCTURES – STACKS, QUEUES	UNIT II 	LINEAR DATA STRUCTURES – STACKS, QUEUES
UNIT II LINEAR DATA STRUCTURES – STACKS, QUEUES Kathirvel Ayyaswamy
 
1 list datastructures
1 list datastructures1 list datastructures
1 list datastructuresNguync91368
 
Introduction of data structure
Introduction of data structureIntroduction of data structure
Introduction of data structureeShikshak
 
PYTHON FULL TUTORIAL WITH PROGRAMMS
PYTHON FULL TUTORIAL WITH PROGRAMMSPYTHON FULL TUTORIAL WITH PROGRAMMS
PYTHON FULL TUTORIAL WITH PROGRAMMSAniruddha Paul
 
9 big o-notation
9 big o-notation9 big o-notation
9 big o-notationirdginfo
 
Dynamic Memory & Linked Lists
Dynamic Memory & Linked ListsDynamic Memory & Linked Lists
Dynamic Memory & Linked ListsAfaq Mansoor Khan
 
Recursion and Sorting Algorithms
Recursion and Sorting AlgorithmsRecursion and Sorting Algorithms
Recursion and Sorting AlgorithmsAfaq Mansoor Khan
 
Recursion(Advanced data structure)
Recursion(Advanced data structure)Recursion(Advanced data structure)
Recursion(Advanced data structure)kurubameena1
 

What's hot (20)

Analysis of algorithms
Analysis of algorithmsAnalysis of algorithms
Analysis of algorithms
 
Data structure and algorithm notes
Data structure and algorithm notesData structure and algorithm notes
Data structure and algorithm notes
 
Data structures and algorithms
Data structures and algorithmsData structures and algorithms
Data structures and algorithms
 
UNIT II LINEAR DATA STRUCTURES – STACKS, QUEUES
UNIT II 	LINEAR DATA STRUCTURES – STACKS, QUEUES	UNIT II 	LINEAR DATA STRUCTURES – STACKS, QUEUES
UNIT II LINEAR DATA STRUCTURES – STACKS, QUEUES
 
Big O Notation
Big O NotationBig O Notation
Big O Notation
 
2 a stacks
2 a stacks2 a stacks
2 a stacks
 
Chapter 10 ds
Chapter 10 dsChapter 10 ds
Chapter 10 ds
 
Data Structure and Algorithms
Data Structure and AlgorithmsData Structure and Algorithms
Data Structure and Algorithms
 
1 list datastructures
1 list datastructures1 list datastructures
1 list datastructures
 
Introduction of data structure
Introduction of data structureIntroduction of data structure
Introduction of data structure
 
Big o notation
Big o notationBig o notation
Big o notation
 
2 b queues
2 b queues2 b queues
2 b queues
 
PYTHON FULL TUTORIAL WITH PROGRAMMS
PYTHON FULL TUTORIAL WITH PROGRAMMSPYTHON FULL TUTORIAL WITH PROGRAMMS
PYTHON FULL TUTORIAL WITH PROGRAMMS
 
Searching Algorithms
Searching AlgorithmsSearching Algorithms
Searching Algorithms
 
3 recursion
3 recursion3 recursion
3 recursion
 
9 big o-notation
9 big o-notation9 big o-notation
9 big o-notation
 
Dynamic Memory & Linked Lists
Dynamic Memory & Linked ListsDynamic Memory & Linked Lists
Dynamic Memory & Linked Lists
 
Data structure
Data structureData structure
Data structure
 
Recursion and Sorting Algorithms
Recursion and Sorting AlgorithmsRecursion and Sorting Algorithms
Recursion and Sorting Algorithms
 
Recursion(Advanced data structure)
Recursion(Advanced data structure)Recursion(Advanced data structure)
Recursion(Advanced data structure)
 

Similar to introduction

EE-232-LEC-01 Data_structures.pptx
EE-232-LEC-01 Data_structures.pptxEE-232-LEC-01 Data_structures.pptx
EE-232-LEC-01 Data_structures.pptxiamultapromax
 
End-to-End Machine Learning Project
End-to-End Machine Learning ProjectEnd-to-End Machine Learning Project
End-to-End Machine Learning ProjectEng Teong Cheah
 
Exploratory data analysis v1.0
Exploratory data analysis v1.0Exploratory data analysis v1.0
Exploratory data analysis v1.0Vishy Chandra
 
A tour of the top 10 algorithms for machine learning newbies
A tour of the top 10 algorithms for machine learning newbiesA tour of the top 10 algorithms for machine learning newbies
A tour of the top 10 algorithms for machine learning newbiesVimal Gupta
 
Data Structures- Part1 overview and review
Data Structures- Part1 overview and reviewData Structures- Part1 overview and review
Data Structures- Part1 overview and reviewAbdullah Al-hazmy
 
Troubleshooting Deep Neural Networks - Full Stack Deep Learning
Troubleshooting Deep Neural Networks - Full Stack Deep LearningTroubleshooting Deep Neural Networks - Full Stack Deep Learning
Troubleshooting Deep Neural Networks - Full Stack Deep LearningSergey Karayev
 
9th Comp Ch 1 LQ.pdf
9th Comp Ch 1 LQ.pdf9th Comp Ch 1 LQ.pdf
9th Comp Ch 1 LQ.pdfNaeem Mughal
 
Algorithm and flowchart with pseudo code
Algorithm and flowchart with pseudo codeAlgorithm and flowchart with pseudo code
Algorithm and flowchart with pseudo codehamza javed
 
Andrew NG machine learning
Andrew NG machine learningAndrew NG machine learning
Andrew NG machine learningShareDocView.com
 
Lecture#1(Algorithmic Notations).ppt
Lecture#1(Algorithmic Notations).pptLecture#1(Algorithmic Notations).ppt
Lecture#1(Algorithmic Notations).pptMuhammadTalhaAwan1
 
MICRO PROJECT 22319 DMS
MICRO PROJECT 22319 DMSMICRO PROJECT 22319 DMS
MICRO PROJECT 22319 DMSARVIND SARDAR
 
notes as .ppt
notes as .pptnotes as .ppt
notes as .pptbutest
 

Similar to introduction (20)

algo 1.ppt
algo 1.pptalgo 1.ppt
algo 1.ppt
 
EE-232-LEC-01 Data_structures.pptx
EE-232-LEC-01 Data_structures.pptxEE-232-LEC-01 Data_structures.pptx
EE-232-LEC-01 Data_structures.pptx
 
Lecture 1.pptx
Lecture 1.pptxLecture 1.pptx
Lecture 1.pptx
 
End-to-End Machine Learning Project
End-to-End Machine Learning ProjectEnd-to-End Machine Learning Project
End-to-End Machine Learning Project
 
Exploratory data analysis v1.0
Exploratory data analysis v1.0Exploratory data analysis v1.0
Exploratory data analysis v1.0
 
A tour of the top 10 algorithms for machine learning newbies
A tour of the top 10 algorithms for machine learning newbiesA tour of the top 10 algorithms for machine learning newbies
A tour of the top 10 algorithms for machine learning newbies
 
Data Structures- Part1 overview and review
Data Structures- Part1 overview and reviewData Structures- Part1 overview and review
Data Structures- Part1 overview and review
 
Intro_2.ppt
Intro_2.pptIntro_2.ppt
Intro_2.ppt
 
Intro.ppt
Intro.pptIntro.ppt
Intro.ppt
 
Intro.ppt
Intro.pptIntro.ppt
Intro.ppt
 
Lect1.pptx
Lect1.pptxLect1.pptx
Lect1.pptx
 
Troubleshooting Deep Neural Networks - Full Stack Deep Learning
Troubleshooting Deep Neural Networks - Full Stack Deep LearningTroubleshooting Deep Neural Networks - Full Stack Deep Learning
Troubleshooting Deep Neural Networks - Full Stack Deep Learning
 
9th Comp Ch 1 LQ.pdf
9th Comp Ch 1 LQ.pdf9th Comp Ch 1 LQ.pdf
9th Comp Ch 1 LQ.pdf
 
Algorithm
AlgorithmAlgorithm
Algorithm
 
Algorithm and flowchart with pseudo code
Algorithm and flowchart with pseudo codeAlgorithm and flowchart with pseudo code
Algorithm and flowchart with pseudo code
 
Andrew NG machine learning
Andrew NG machine learningAndrew NG machine learning
Andrew NG machine learning
 
Lecture#1(Algorithmic Notations).ppt
Lecture#1(Algorithmic Notations).pptLecture#1(Algorithmic Notations).ppt
Lecture#1(Algorithmic Notations).ppt
 
MICRO PROJECT 22319 DMS
MICRO PROJECT 22319 DMSMICRO PROJECT 22319 DMS
MICRO PROJECT 22319 DMS
 
RAJAT PROJECT.pptx
RAJAT PROJECT.pptxRAJAT PROJECT.pptx
RAJAT PROJECT.pptx
 
notes as .ppt
notes as .pptnotes as .ppt
notes as .ppt
 

More from Mohamed Elsayed (20)

binary_trees4
binary_trees4binary_trees4
binary_trees4
 
binary_trees3
binary_trees3binary_trees3
binary_trees3
 
binary_trees2
binary_trees2binary_trees2
binary_trees2
 
binary_trees1
binary_trees1binary_trees1
binary_trees1
 
queues
queuesqueues
queues
 
stacks2
stacks2stacks2
stacks2
 
algorithm_analysis2
algorithm_analysis2algorithm_analysis2
algorithm_analysis2
 
algorithm_analysis1
algorithm_analysis1algorithm_analysis1
algorithm_analysis1
 
recursion3
recursion3recursion3
recursion3
 
recursion2
recursion2recursion2
recursion2
 
recursion1
recursion1recursion1
recursion1
 
linked_lists4
linked_lists4linked_lists4
linked_lists4
 
linked_lists3
linked_lists3linked_lists3
linked_lists3
 
Linked_lists2
Linked_lists2Linked_lists2
Linked_lists2
 
linked_lists
linked_listslinked_lists
linked_lists
 
sorted_listmatch
sorted_listmatchsorted_listmatch
sorted_listmatch
 
binary_search
binary_searchbinary_search
binary_search
 
heaps2
heaps2heaps2
heaps2
 
heaps
heapsheaps
heaps
 
hash_tables
hash_tableshash_tables
hash_tables
 

Recently uploaded

URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991RKavithamani
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 

Recently uploaded (20)

URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 

introduction

  • 1. College of Computing & Information Technology King Abdulaziz University Data Structures I CPCS-204 – Introduction CPCS-204 – Data Structures I
  • 2. Data Structures I: An Introduction page 2 © Dr. Jonathan (Yahya) Cazalas Data Structures 1: Introduction  Course Learning Outcomes  Upon completion of this course, you will be able to: 1. Describe the needs of data structures in problem solving. 2. Design and implement abstract data types. 3. Represent and implement linear/non-linear data structures. 4. Build stacks and queues using arrays and linked lists. 5. Select and apply appropriate data structures in problem solving. 6. Select and apply basic searching and sorting algorithms in problem solving. 7. Apply recursion to solve simple problems. 8. Trace the output of a given piece of code or algorithm.
  • 3. Data Structures I: An Introduction page 3 © Dr. Jonathan (Yahya) Cazalas Data Structures 1: Introduction  How is CPCS-204 different than CPCS-203?  CPCS-203 teaches how to program in Java  Language basics, variable declarations, conditional expressions, if statements, loops, functions, arrays, structures, and even Object-Oriented programming  This will not be covered in this class  You will need to freshen up on your Java very quickly  If you need help, but a good Java-language book or find a quality reference online  With respect to Java, we will cover:  Arrays and array processing (although already taught)  Some of the Java Collections as needed
  • 4. Data Structures I: An Introduction page 4 © Dr. Jonathan (Yahya) Cazalas Data Structures 1: Introduction  The goals of Data Structures I:  Improve knowledge of standard data structures and abstract data types  Improve knowledge of standard algorithms used to solve several classical problems  Cover some mathematical concepts that are useful for the analysis of algorithms  Analyze the efficiency of solutions to problems  Learn about and be comfortable with recursion
  • 5. Data Structures I: An Introduction page 5 © Dr. Jonathan (Yahya) Cazalas Data Structures 1: Introduction  The goals of Computer Science I:  In CPCS-202 and 203, we only cared if we found a solution to the problem at hand  Didn’t really pay attention to the efficiency of the answer  For this class:  We learn standard ways to solve problems  And how to analyze the efficiency of those solutions  Finally, we simply expand upon our knowledge of our use of the JAVA programming language
  • 6. Data Structures I: An Introduction page 6 © Dr. Jonathan (Yahya) Cazalas Data Structures 1: Introduction  Teaching Method:  This class is NOT used to teach you JAVA  The focus of CPCS-202 and 203 (not this class) is to teach you JAVA  You should know JAVA already  In CPCS-202 and 203, majority of time was spent going of syntax of JAVA  Programs were often shown in class  Programs were even written during class  Essentially a requirement for any course teaching a programming language
  • 7. Data Structures I: An Introduction page 7 © Dr. Jonathan (Yahya) Cazalas Data Structures 1: Introduction  Teaching Method:  Majority of this class is used covering new data structures, abstract data types, and algorithm analysis  The teaching of these concepts dictate more explanation and less of a focus on “code”  Some code will be shown on the PowerPoint slides  Such as after we explain a new abstract data type  We’ll show the code of how you would implement it  However, writing of actual code will most likely never be done in class  Again, that is not the purpose of this class
  • 8. Data Structures I: An Introduction page 8 © Dr. Jonathan (Yahya) Cazalas Data Structures 1: Introduction  Example Problem:  We will now go over two solutions to a problem  The first is a straightforward solution that a CPCS-203 student should be able to come up with  Doesn’t’ care about efficiency  The second solution is one that a CPCS-204 student should be able to come up with after some thought  Cares about efficiency  Hopefully this example will illustrate part of the goal of this course
  • 9. Data Structures I: An Introduction page 9 © Dr. Jonathan (Yahya) Cazalas Data Structures 1: Introduction  Max Number of 1’s:  You are given an nxn integer array  Say, for example, a 100x100 sized array  Each row is filled with several 1’s followed by all 0’s  Example:  Row 1 may have 38 1’s followed by 62 0’s  Row 2 may have 73 1’s followed by 27 0’s  Row 3 may have 12 1’s followed by 82 0’s  You get the idea  The goal of the problem is to identify the row that has the maximum number of 1’s.
  • 10. Data Structures I: An Introduction page 10 © Dr. Jonathan (Yahya) Cazalas Data Structures 1: Introduction  Max Number of 1’s:  Straightforward CPCS-203 style solution:  Make a variable called MaxOnes and set equal to 0  For each row do the following:  Start from the beginning of the row on the left side  Scan left to right, counting the number of 1’s until the first zero is encountered  If the number of 1’s is greater than the value stored in MaxOnes, update MaxOnes with the number of 1’s seen on this row  Clearly, this works  But let’s see how long this algorithm will take
  • 11. Data Structures I: An Introduction page 11 © Dr. Jonathan (Yahya) Cazalas Data Structures 1: Introduction  Max Number of 1’s:  Analysis of Straightforward Solution:  Basically we iterate through each square that contains a 1, as well as the first 0 in each row  If all cells were 0, we would only “visit” one cell per row, resulting in n visited cells  However, if all cells were 1’s, we would “visit” all of the cells (n2 total)  So in the worst case, the number of simple steps the algorithm takes would be approximately n2  This makes the running time of this algorithm O(n2)  The meaning of this Big-O will be discussed later in the semester
  • 12. Data Structures I: An Introduction page 12 © Dr. Jonathan (Yahya) Cazalas Data Structures 1: Introduction  Max Number of 1’s:  Analysis of Straightforward Solution:  There seems to be extra work done here  Once we know that a row has 12 1’s, for example, it seems pointless to start checking at the beginning of the next row  Why not just start at column 12  If it’s a 0, then that row can’t be the winner  If it is a 1, then clearly there is no point in going back, on that row, and checking the previous 11 squares  This idea leads to a more efficient algorithm
  • 13. Data Structures I: An Introduction page 13 © Dr. Jonathan (Yahya) Cazalas Data Structures 1: Introduction  Max Number of 1’s:  More Efficient CPCS-204 style algorithm: 1. Initialize the current row and current column to 0 2. While the current row is less than n (or before the last row) a. While the cell at the current row and column is 1  Increment the current column b. Increment the current row 3. The current column index represents the maximum number of 1’s seen 4. Now let’s trace through a couple of examples
  • 14. Data Structures I: An Introduction page 14 © Dr. Jonathan (Yahya) Cazalas Data Structures 1: Introduction  Max Number of 1’s:  Example 1: 1 1 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 1 1 1 0 0 0 1 1 1 1 1 0 1 1 1 1 0 0
  • 15. Data Structures I: An Introduction page 15 © Dr. Jonathan (Yahya) Cazalas Data Structures 1: Introduction  Max Number of 1’s:  Example 2: 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 1 1 0 0 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1
  • 16. Data Structures I: An Introduction page 16 © Dr. Jonathan (Yahya) Cazalas Data Structures 1: Introduction  Max Number of 1’s:  Analysis of Better Solution:  How many steps will this algorithm take, in terms of n?  Each “step” taken by the algorithm either goes to the right or down in the table.  There are a maximum of n-1 steps to the right  And a maximum of n-1 steps down that could be taken  Thus the maximum number of “steps” that can be done during this algorithm is approximately 2n  And this is the worst case  So the running time of this algorithm is O(n)  An improvement of the previous algorithm  Input size of 100 for n  n2 would be 10,000 steps and 2n would be 200 steps
  • 17. Data Structures I: An Introduction page 17 © Dr. Jonathan (Yahya) Cazalas Data Structures 1: Introduction  Implementing an Algorithm in JAVA:  In this class, you will have an opportunity to improve upon your ability to write programs that implement an algorithm you have learned  You must know the syntax of JAVA in order to properly and effective do this  There’s no set way to create code to implement an algorithm  But this example shows some steps you can take in doing so
  • 18. Data Structures I: An Introduction page 18 © Dr. Jonathan (Yahya) Cazalas Data Structures 1: Introduction  Implementing an Algorithm in JAVA:  Here are some issues to think about: 1. What data structures are going to be used? 2. What functions are going to be used? 3. What run-time errors should we protect against? 4. What atypical cases may we have to deal with? 5. What is an efficient way to execute the steps in the algorithm?
  • 19. Data Structures I: An Introduction page 19 © Dr. Jonathan (Yahya) Cazalas Data Structures 1: Introduction  Maximum Number of 1’s  This was a creative exercise  Much of what you learn in class will not be  We have many set algorithms and data structures that you will study  Occasionally you will have to come up with new ideas like this one  Mostly, however, you will simply have to apply the data structures and algorithms shown in class fairly directly to solve the given problems
  • 20. Data Structures I: An Introduction page 20 © Dr. Jonathan (Yahya) Cazalas Data Structures 1: Introduction Are You Excited?
  • 21. Data Structures I: An Introduction page 21 © Dr. Jonathan (Yahya) Cazalas Daily FAIL Picture  Fail pictures  During the slides (or at the end), we will often give a funny “fail” picture or a “human stupidity” picture  Helps to “lighten things up”  So here you go:
  • 22. Data Structures I: An Introduction page 22 © Dr. Jonathan (Yahya) Cazalas Human Stupidity
  • 23. College of Computing & Information Technology King Abdulaziz University Data Structures I CPCS-204 – Introduction CPCS-204 – Data Structures I