0% found this document useful (0 votes)
17 views64 pages

CSE 220 Week 1

Uploaded by

ohidul.hossain
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views64 pages

CSE 220 Week 1

Uploaded by

ohidul.hossain
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 64

Data Structures

Mushtari Sadia
Introduction
Faculty Name: Mushtari Sadia (MIS)
Consultation Hours:
Wednesday: 9:30AM-1:45PM
Thursday: 9:30AM-10:40AM
Room: UB-80601

Join Slack Channel:


https://join.slack.com/t/cse220summer2023/shared_invite/zt-1wrcesdkw-7bGTJMs62ihUWRIq4RVlA
A
Resources link: tiny.cc/cse220mis
What is Data Structure?
Data structure is a format for organizing and storing data
Reference Books

CLRS Book link:


https://drive.google.com/file/d/1JUrGXFldwjUsRRLbo0Ac6x9scMpe9Ayd/view?usp=sharing
Linear Arrays and
Circular Arrays
Week 1
Outline

1. Definition of an Array
2. Properties of an Array
3. Operations on an Array
Linear Array
Linear Array
Linear Array - Properties
1. Dimension
2. Index
3. Length
4. Single Type
Dimension
Dimension
Dimension

3rd element of the array

3rd element of 2nd row


Index
Index of an array
starts from 0;
So from now on,
always start counting
from 0!

3rd element of the array

3rd element of 2nd row


Index
Index of an array
starts from 0;
So from now on,
always start counting
from 0!
Length

When you create an array in the program, you have to specify


the length of each of its dimensions that you cannot change
later
Length
Length
Operations On Array - Read and Write
Single Type
● An array can hold elements of only a single type. That is, you cannot
mix strings with numbers in an array – not even mix integer numbers
with fractional numbers.
Single Type
Practice
Notebook Link: http://tiny.cc/cse220nb
Some other functions
Some other functions
Some other functions
Some other functions
Some other functions
Some other functions
Some other functions
Functions on array
Functions on array
Functions on array
Functions on array
Functions on array
Functions on array
Functions on array
Functions on array
Functions on array
Functions on array
Functions on array
Functions on array
How are multi-dimensional arrays stored?
How are multi-dimensional arrays stored?
Multidimensional Array Index -> Linear Index

Linear Index =
Multidimensional Array Index -> Linear Index

Linear Index =
Multidimensional Array Index -> Linear Index

Linear Index =
Multidimensional Array Index -> Linear Index

Linear Index =
Multidimensional Array Index -> Linear Index

Linear Index =
Multidimensional Array Index -> Linear Index
imagine you have a 4D array with dimensions 4x3x5x6, named box

element at the index you are interested is the box[2][1][4][3]

Linear Index = ??
Linear Index -> Multidimensional Array Index
Imagine you have a 3D array with dimensions 4x4x8.
What are the multidimensional indexes of the element stored at
location 111?

Linear Index = 111 -> box[x][y][z]

Find x,y,z
Linear Index -> Multidimensional Array Index
Imagine you have a 3D array with dimensions 4x4x8.
What are the multidimensional indexes of the element stored at
location 111?

Linear Index = x * (4*8) + y*8 + z

= 111
Linear Index -> Multidimensional Array Index
Imagine you have a 3D array with dimensions 4x4x8.
What are the multidimensional indexes of the element stored at
location 111?

Linear Index = x * (4*8) + y*8 + z where 0 <= x <= 3, 0 <= y <= 3 and
0 <= z <= 7
= 111
Linear Index -> Multidimensional Array Index
Imagine you have a 3D array with dimensions 4x4x8.
What are the multidimensional indexes of the element stored at
location 111?

Linear Index = x * (4*8) + y*8 + z where 0 <= x <= 3, 0 <= y <= 3 and
0 <= z <= 7
= 111
Remember that indexing starts from 0
in each dimension!
Linear Index -> Multidimensional Array Index
Imagine you have a 3D array with dimensions 4x4x8.
What are the multidimensional indexes of the element stored at
location 111?

Linear Index = x * (4*8) + y*8 + z where 0 <= x <= 3, 0 <= y <= 3 and
0 <= z <= 7
= 111
Remember that indexing starts from 0
in each dimension!
Quotient

4*8 =

x=3

Remainder
Linear Index -> Multidimensional Array Index
Linear Index -> Multidimensional Array Index
Practice
Find the dimension of 96, 107, and 60 of the linear
index.
Circular Array/Buffer
Indexing A Circular Array
Assume the capacity/length of a circular array, named buffer, is 10.

Suppose, you want to read the element at index 9.


a = buffer[9 % 10]
= buffer[9]
Indexing A Circular Array
Assume the capacity/length of a circular array, named buffer, is 10.

What if you ask what is the next index after 9?

a = buffer[(9 + 1) % 10]
= buffer[0]
Indexing A Circular Array
This works for going leftwards also.

For example, if you ask for the element that is two steps left of the element at
index zero; then you do the following:

a = buffer[(0 - 2) %10]

The answer is (0-2)%10 = -2%10 = 8


Circular Array Structure
Circular Array Structure
Iteration Over A Circular Array
Iteration Over A Circular Array

Self Study

You might also like