CS-211 Data Structure & Algorithms - Lecture2
CS-211 Data Structure & Algorithms - Lecture2
1
Nasir Uddin
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
Nasir Uddin
CS211 - Data Structure and Algorithms
Array ADT
3
Nasir Uddin
CS211 - Data Structure and Algorithms
4
Nasir Uddin
CS211 - Data Structure and Algorithms
6
Nasir Uddin
CS211 - Data Structure and Algorithms
7
Nasir Uddin
CS211 - Data Structure and Algorithms
8
Nasir Uddin
CS211 - Data Structure and Algorithms
9
Nasir Uddin
CS211 - Data Structure and Algorithms
10
Nasir Uddin
CS211 - Data Structure and Algorithms
11
Nasir Uddin
CS211 - Data Structure and Algorithms
13
Nasir Uddin
CS211 - Data Structure and Algorithms
14
Nasir Uddin
CS211 - Data Structure and Algorithms
15
Nasir Uddin
CS211 - Data Structure and Algorithms
17
Nasir Uddin
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
Nasir Uddin
CS211 - Data Structure and Algorithms
19
Nasir Uddin
CS211 - Data Structure and Algorithms
20
Nasir Uddin
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
Nasir Uddin
CS211 - Data Structure and Algorithms
25
Nasir Uddin
CS211 - Data Structure and Algorithms
26
Nasir Uddin
CS211 - Data Structure and Algorithms
27
Nasir Uddin
CS211 - Data Structure and Algorithms
28
Nasir Uddin
CS211 - Data Structure and Algorithms
29
Nasir Uddin
CS211 - Data Structure and Algorithms
30
Nasir Uddin
CS211 - Data Structure and Algorithms
31
Nasir Uddin
CS211 - Data Structure and Algorithms
32
Nasir Uddin
CS211 - Data Structure and Algorithms
33
Nasir Uddin
CS211 - Data Structure and Algorithms
34
Nasir Uddin
CS211 - Data Structure and Algorithms
35
Nasir Uddin
CS211 - Data Structure and Algorithms
36
Nasir Uddin
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
Nasir Uddin
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
Nasir Uddin