Download Introduction to Data Structures

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Array data structure wikipedia , lookup

Transcript
Babylon University
Science College for Women
Introduction to Data Structures and array
Second Class
Introduction to Data Structures:
Computing is all about handling data, and that data needs to be
organized in a logical manner.
The tool that are used for store the data into computer very significant
manner also retrieve this stored data very fast is data structure.
Data Structure :
Is a way of collecting and organizing data in such a way that we
can perform operations on these data in an effective way. Two types of
data structures.
Data structure
Linear data structure
Array
Stack
Queue
Non-linear data structure
List
Trees
graphs
What Abstract Data Type:
In general, abstract data types (ADT) gives us a definition
(abstraction) of the specific structure, i.e. defines the allowed operations
and properties, without being interested in the specific implementation.
This allows an abstract data type to have several different
implementations and respectively different efficiency.
What is data and Information:
Data means value or set of values, whereas information is data
contain some useful meaning that helps us in making good judgments. All
data term become information if impose the meaning.
Data Type:
A data type is a term which refers to the kind of data that may appear
in computation.
Babylon University
Science College for Women
Introduction to Data Structures and array
Second Class
What is Algorithm:
An algorithm is a finite set of instructions, written in order, to
accomplish a certain predefined task. Algorithm is not the complete code
or program, it is just the core logic(solution) of a problem, which can be
expressed either as an informal high level description as pseudo code or
using a flowchart.
An algorithm is said to be efficient and fast, if it takes less time to execute
and consumes less memory space. The performance of an algorithm is
measured on the basis of following properties :
1. Time Complexity
2. Space Complexity
Array:
Is a data structure that contains a group of elements. Typically these
elements are all of the same data type, such as an integer or string. Arrays
are commonly used in computer programs to organize data so that a
related set of values can be easily sorted or searched.
 Array elements can be accessed by their index numbers using the
subscript operator [] , as a[0], a[1], a[2], and soon.
 Characterized by the fact a fixed size does not change.
Types of Arrays:
One-dimensional Array: requires only one index to access an element.
Two-Dimensional Array: requires two indices to access an element.
Multidimensional Array: requires two or more indices to access an
element.
Representation of array in memory
1. Address calculation in one-dimensional Array:Since array elements are stored in contiguous memory locations, the
computer needs to not to know the address of every element but the
address of only first element. The address of first element is called base
Babylon University
Science College for Women
Introduction to Data Structures and array
Second Class
address of array. Given the address of first element, address of any other
element is calculated using the formula :Loc (arr [k]) =base (arr) + I
I :- Is the index of array whose address we want to calculate .
Example:- Suppose that array arr is declared as integers with size 5 and
its first element is stored at base address 1000. Calculate the address of
3th element of array.
10
arr[0]
6
arr[1]
11
arr[2]
8
arr[3]
1
arr[4]
1000
10
1001
6
Loc(arr[i]) = base address + i
1002
11
loc(arr[3])= 1000 + 3=1003
1003
8
1004
1
Solution:Here, base address=1000, i=3.
2. Address calculation in two-dimensional Array:The address of the element in the ith row and jth column is given by:
(i) Column major order:
Loc(A[I,J])= Base address + J * n+ I
where (n ) represent the number of row
(ii) Row major order:Loc(A[I,J])= Base address + I * m+ J
where (m ) represent the number of column
Example:- Suppose that array A is declared as integers with size (3×3)
and its first element is stored at base address 200. Calculate the address of
(A[1][2]) element of array.
10
1
4
2
8
7
12
20
55
Babylon University
Science College for Women
Introduction to Data Structures and array
Second Class
Solution:1- Row major method
Loc(A[I,J])= Base address + I * m+ J
Loc(A[1][0])= 200 + 1* 3+2 = 205 .
200
201
10
1
202
4
203
2
204
8
205
7
206
12
207
20
208
55