Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
3 views

CSC 305 Tutorial 3-Introduction to Data Structures and Array

The document provides an introduction to data structures and arrays, defining data structures as organized data patterns that facilitate efficient program design. It categorizes data structures into primitive and non-primitive types, detailing their characteristics and examples. Additionally, it discusses operations on data structures, the procedure for selecting appropriate data structures, and the concept of sparse arrays to optimize memory usage.

Uploaded by

camelidthread
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

CSC 305 Tutorial 3-Introduction to Data Structures and Array

The document provides an introduction to data structures and arrays, defining data structures as organized data patterns that facilitate efficient program design. It categorizes data structures into primitive and non-primitive types, detailing their characteristics and examples. Additionally, it discusses operations on data structures, the procedure for selecting appropriate data structures, and the concept of sparse arrays to optimize memory usage.

Uploaded by

camelidthread
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

CSC 305

Data Structure and Algorithms


Lesson III
Introduction to Data Structures and Array
By
Dr. R.M. Isiaka
Department of Computer Science
Kwara State University, Malete
Data Structure (Definition)
• Structural representation of logical
relationships between elements of data.
• It mainly specifies the structured organization
of data, by providing accessing methods with
correct degree of associativity.
• It affects the design of both the structural and
functional aspects of a program.
• They are the building blocks of a program
Data Structure (Definition)
• Algorithm + Data Structure = Program
• Data Structure = Organized data + Operations
• Data structure is a pattern of data storage /
management in the memory.
• Its representation in the main memory is
called storage structure
• Its representation in the auxiliary memory is
called file structure
Types of Data Structure
• Data structure can be classified either as
Primitive or Non-primitive.
• Primitive Data structure:
- Basic data structure that are directly operated
upon by machine instructions
- They are the basis for the discussions of the
more sophisticated Non-primitive data
structures
- Examples include: Integers, floating point
numbers, characters, string constants,
pointers etc.
Types of Data Structure
• Non-Primitive Data structure:
- They are sophisticated data structures
emphasizing on structuring of a group of
homogenous or heterogeneous data items
- Examples include: Array, linked list, files, trees
and graphs.
Types of Data Structure

Data Structure

Primitive Non-Primitive

Integer float character pointer Arrays Lists Files

Linear List Non-Linear List

Stacks Queues Graphs Trees


Constituent Terms of Data Structure
- Understanding requires establishment of
relationship between Type, Data items, Data
type and Abstract Data type.
- Type: a collection of values (simple -Integer,
boolean – T/F, logic – AND, OR, NOT, aggregate
/composite – Record)
- Data item: value drawn from a Type ( 234,
true, OR, STUDENT (matricno, sex, dept, dob)
Constituent Terms of Data Structure
- Data type: a type together with a collection of
operations to manipulate the type (IF var data:
Integer, then, +,-,*,/ are legal operations)
- Abstract Data Type: realization of Data type as a
software component defined in terms of a type
and possible operations using encapsulation.
- Data Structure is the implementation for ADT as
OOP class. Objects when created takes up
storage during execution.
Procedure for Selection of Data Structure
i. Analyse the problem to determine the basic
operations ( insertion, searching and deletion)
ii. Quantify the resource constraints for each
operation
iii. Select the best Data structure that best meet
these requirements
- Appropriate Data Structure determine the
efficiency of a solution
- A solution is efficient if it solves the problem
within the required resource constraints with
minimum cost
Overall objective of a Data Structure
To allow the data user to build
and access collection of data
as abstract tools rather than
forcing the user to think in
terms of the computer main
memory organization.
Operations on Data Structures
• Traversal – Processing each element
• Search – Finding the location of an element
with a given value
• Insertion – Adding a new element
• Deletion – Remove an element from a list
• Sorting- Arrange the element in some type of
order
• Merging – Combine elements from separate
structures
Arrays
• Set of items that can be referred to by a single
identifier and the individual element in the set
can be referenced by subscript(s).
• For array A, the elements of A can be denoted
by
• Subscript notation: a1,a2,a3 . . . An or
• Parenthesis notation: A(1), A(2), A(3) . . . A(n)
• Bracket notation: A[1], A[2], A[3] . . . A[n]
• Array can be one-dimensional (linear or
vector) or multi-dimensional (matrix).
Linear Arrays (LA)
• LA is a set of ‘n’ finite numbers of homogenous
data elements.
• Array length = UB – LB + 1
• Algorithm for Transverse LA
for k = LB to UB
Do process LA[k]
• Representation of LA in Memory
Loc (LA[k]) = Base (LA) + w(k – LB)
Where LA: Array, Base (LA): start address, k: element,
w: word length
Multidimensional Arrays (MA)
• MA (2D Array m x n array A is a collection of m.n data
elements such that each element is specified by a pair of
integer (j,k) called subscripts with 1≤ j ≤ m and 1≤ k ≤ n.
• Algorithm for Transverse MA
for p = LB to m
for q = LB to n
Do process MA[p,q]
• The memory representation for MA[j,k]) in MA[M,N] by row
or by column:
Row-Major order:
Loc (MA[j,k]) = Base (A) + w[N(j – 1) + (k-1))
Column-Major order:
Loc (MA[j,k]) = Base (A) + w[N(k – 1) + (j-1))
Activities III(a)
Application of Array and its memory representation
i. Identify and briefly explain two (2) data
structures that can be implemented using
Array
ii. Highlight Five (5) applications of Array Data
Structure
iii. Given Array A[m,n] = A[8,5] with a base
address of 2015 and word length of 32.
Calculate the memory address for A[6,4].
a. Using Row Major technique
b. Using the Column Major Technique
Application of Array
• SPARSE ARRAY (SA) : sparse array is an array where
nearly all of the elements have the same value
(usually zero) and this value is a constant. One-
dimensional sparse array is called sparse vectors
and two-dimensional sparse arrays are called sparse
matrix.
• SA allocates memory space for only non-zero
elements thereby minimize the memory space
requirement and improve the execution speed of a
program.
• SA = A[0…n][1…3]. n is number of non-zero element
Sparse Array
• SA = A[0…n][1…3].
- n is the number of non-zero element
- A[0][1] num_row; A[0][2] num_column; A[0][3]
num_non zero elements
Relevant examples
Class practice
Assignment
Activities III(b)
1. Build the Sparse Array with the memory representation shown below

1 2 3

0 5 7 7

1 1 3 8

2 2 2 1

3 2 6 9

4 3 4 3

5 4 2 31

6 4 6 4

7 5 7 7

2. a. Formulate a Sparse Matrix A(4,6) with the first 6 alphabet sparsely distributed
b. Formulate the Sparse Array representation

You might also like