2-D Arrays
Chapter 2
Part Two
Data Structures and Algorithms Using Python R. Necaise.
2-D Arrays
Arrays can be defined with multiple dimensions.
Two-dimensional arrays:
organize the data in rows and columns
element access: [i,j]
Data Structures and Algor
• Set ADT: Unsorted List
◦ implemented using an unsorted Python list
• Sorted Sequences
◦ The efﬁciency of some algorithms can be improved when working with
sorted sequences
◦ we can use a sorted sequence to improve the efﬁciency of the Set ADT
◦ th
Lang
-Jw.\o.¢|-Htm MmmcmicmmijMALlFOsmu-m
.limr Wu, A
mm} m cum MW)
3 mm
\WthkéhmmaMmmmmmlmgsmmm
you "alumina;
«H a; y.» lama. o. \33-\ um Mani-mu.
E El compnuug a; ° ' {MSW-n3 0Mme
¢ J. Hm. is mean+ 00)
Amortized cost is the average cost per use of the operation (function or
method). It can only be used when the operation is used n times in sequence.
The classication of an algorithm based on the order of magnitude on which an
algorithm executes.
Assume
Project 1
Homework 1
the sum of the minimum
values from each row in 2D array
Homework 2
Product of neighbors is odd or even(1/0)
Counting number of
nodes in a circular linked list
Takes 4D array as
param, prints contents of every cell of that array
Quiz 1
Variables and Memory
Variables are boxes in memory that hold values.
Each box has a name.
Python maintains a dictionary (keys that map to values)
that maps names to the boxes in memory.
The variable name points to the value in memory.
Names do not ha
Multidimensional Arrays
Cells inside of arrays can hold anything at all, including
other arrays.
If an array contains other arrays, it has multiple
dimensions.
Two-dimensional arrays can be thought of as rows and
columns.
Python is a row-major languag
Introduction to Algorithm Analysis
Running time of an algorithm usually depends on the
data on which it operates.
Performance is bound by the absolute worst case input
for the algorithm.
Often express performance in terms of the number of
steps needed
When Arrays Are Good
Great for storing contiguous data that do not grow,
shrink, or move very often.
Accessing items anywhere in an array is very fast, with
O(1) performance.
When Arrays Are Bad
Insertions or deletions in the middle of the array are
sl
Sets
Data Structures and Algorithms Using Python, by R. Necaise.
Chapter 3
Introduction
The Set is a common container used in
programming.
stores unique values.
represents the mathematical set structure.
Data Structures and Algorithms Using Python, by R.
Searching
Data Structures and Algorithms Using Python R. Necaise
Searching
The process of selecting particular information
from a collection of data based on specific criteria.
Can be performed on different data structures.
sequence search
search key (or
• Abstraction
◦ a concept or an idea that is not real
◦ used by computer scientist to help manage complex problems
‣ restrict the focus to those properties that are relevant in the current
context
‣ focus on the what not how
• Types of Abstractions
Algorithm Analysis
Data Structures and Algorithms Using Python R. Necaise
Part 1
Algorithms
Algorithms are designed to solve problems.
A problem can have multiple solutions.
How do we determine which
How do we determine which
solution is the most efficie
Arrays and Vectors
Data Structures and Algorithms Using Python R. Necaise.
Chapter 2
The Array Structure
An array is the most basic type of container.
Implemented at the hardware level.
Most languages provide arrays as a primitive type.
Can be used with
Maps
Data Structures and Algorithms Using Python R. Necaise
Maps
Stores a collection of records.
A unique key identifies each record.
Records are selected by key value.
aka dictionary.
Python provides a built-in dictionary.
Great example for comparing di
• In Appendix A
• Rules of Coding
◦ Readability
‣ easy to read
‣ include comments
‣ use meaningful identiﬁers
◦ Comments
‣ only use the hash symbol
‣ describe various elements of code
• Variables
◦ a named storage location that associates a name
Circular Arrays
Arrays have valid indices 0.n-1, but some applications
can wrap around, treating the array as a circle instead
of a line.
Instead of walking off the end of the array into an
invalid index error, wrap around to 0 when moving right
past in