Professional Documents
Culture Documents
1
Dr. Sharaf Hussain
CS211 - Data Structure and Algorithms
Arrays
• A one-dimensional array is composed of multiple sequential elements
stored in contiguous bytes of memory and allows for random access
to the individual elements.
• Array contains fixed number of elements
• Individual elements within the array can be accessed directly form
their index values.
• Occupy less memory as compared to python list
• Internal processing is faster than python lists
2
Dr. Sharaf Hussain
CS211 - Data Structure and Algorithms
Array ADT
3
Dr. Sharaf Hussain
CS211 - Data Structure and Algorithms
6
Dr. Sharaf Hussain
CS211 - Data Structure and Algorithms
7
Dr. Sharaf Hussain
CS211 - Data Structure and Algorithms
8
Dr. Sharaf Hussain
CS211 - Data Structure and Algorithms
9
Dr. Sharaf Hussain
CS211 - Data Structure and Algorithms
10
Dr. Sharaf Hussain
CS211 - Data Structure and Algorithms
11
Dr. Sharaf Hussain
CS211 - Data Structure and Algorithms
13
Dr. Sharaf Hussain
CS211 - Data Structure and Algorithms
14
Dr. Sharaf Hussain
CS211 - Data Structure and Algorithms
15
Dr. Sharaf Hussain
CS211 - Data Structure and Algorithms
17
Dr. Sharaf Hussain
CS211 - Data Structure and Algorithms
Two-Dimensional Arrays
• Two-dimensional array arrange
data in rows and columns.
• The individual elements are
accessed by specifying two
indices, one for the row and one
for the column, [i,j].
18
Dr. Sharaf Hussain
CS211 - Data Structure and Algorithms
19
Dr. Sharaf Hussain
CS211 - Data Structure and Algorithms
20
Dr. Sharaf Hussain
CS211 - Data Structure and Algorithms
class Array2D:
def numRows(self):
return len(self._theRows)
def numCols(self):
return len(self._theRows[0])
for i in range(twoDArray.numRows()):
print('')
for j in range(twoDArray.numCols()):
twoDArray[i,j] = int(input('enter value %d,%d = '%(i,j)))
24
Dr. Sharaf Hussain
CS211 - Data Structure and Algorithms
25
Dr. Sharaf Hussain
CS211 - Data Structure and Algorithms
26
Dr. Sharaf Hussain
CS211 - Data Structure and Algorithms
27
Dr. Sharaf Hussain
CS211 - Data Structure and Algorithms
28
Dr. Sharaf Hussain
CS211 - Data Structure and Algorithms
29
Dr. Sharaf Hussain
CS211 - Data Structure and Algorithms
30
Dr. Sharaf Hussain
CS211 - Data Structure and Algorithms
31
Dr. Sharaf Hussain
CS211 - Data Structure and Algorithms
32
Dr. Sharaf Hussain
CS211 - Data Structure and Algorithms
33
Dr. Sharaf Hussain
CS211 - Data Structure and Algorithms
34
Dr. Sharaf Hussain
CS211 - Data Structure and Algorithms
35
Dr. Sharaf Hussain
CS211 - Data Structure and Algorithms
36
Dr. Sharaf Hussain
CS211 - Data Structure and Algorithms
Assignment – 1
1. Implement Matrix class that can perform following operations,
• Addition
• Subtraction
• Scaling
• Transpose
• Multiplication
• Inverse of Matrix
37
Dr. Sharaf Hussain
CS211 - Data Structure and Algorithms
Assignment – 1
2. Implement the numLiveNeighbors() method of the
LifeGrid class.
3. Complete the implementation of the gameoflife.py program by
implementing the draw() function. The output should look
similar to the following, where dead cells are indicated using a
period and live cells are indicated using the @ symbol.
4. Modify the gameoflife.py program to prompt the user for the grid
size and the number of generations to evolve.
Due Date:
Submission: Microsoft Teams
38
Dr. Sharaf Hussain