새발블로그
Arrary 본문
Arrays
- Set of finite homogeneous elements
(collection of fixed same elements) - contain one type of data (all. integer, all character)
- consecutive memory location

Array Format
- Elements : integers, floats, characters
- all elements share a common name with an index called subscript

Arrarys in c
- Declaration: int arr[10];
- int: data type
- arr : name
- [10] : size or length
array_type array_name[size]; - Read/write through loops
Advvantages of Arrary
- represents multiple data
- implement other data structure(stacks, queues,tree)
- two-dimensional arrays
- databases-one dimensional arrays
Disadvantages of Array
- must know in advance the number elements
- static structure(fixed size, constant allocated memory)
- consecutive memory location
Represent a Linear Array

size of an Array
total bytes=sizeof(data type)*size of array
Initializing arrays
- array elements must be initialized at time of declaration(if not, contained garbage valeus)
- initialization can be done either at compile time or run time
Compile Time Initialization
- int num[3]={1,1,1};
- float fl_num[5]={1.0,12.50,100.35}
: initialized first three elements
: Rest two will be initialized to 0. - exceeds size of array=> compiler error
int num=[]={5,10,-20,0,1000};
array size will automatically be set equal to the number of initial values
Basic operations of Arrays
- Traversing, Insertion, Deletion, Searching, Sorting, Merging
Traversing Arrays


Insertion into Arrary


Deletion from Arrary


Searching in Arrarys

Linear/Sequential Search

Binary Search
sort->divide one two smaller sub-arrays->recursively operate->reduceds the search space to half


Linear&Binary

Sorting
- arrangement of the elements
: Numeric array -ascending, descending - bubble, selection, shell, quick, heap, insertion
Merging


Types of Arrarys
- Single Dimension array (one subscript)
- Two Dimension Array (two subscript: Rows and Column)
- Multi Dimension Array (Multiple subscripts)
Two dimensional array
- num[m][n]
:m=row, n=column


Row-major method

- all the first-row elements are stored in sequential memory location
- second-row elements are stored and so on A[Row][Col]
Column-major Method

- all the first column elements are stored in sequential memory locations
- all the second-coulmn elements are stored and so on A[Col][Row]
store table, matrix

Multidimensional Arrays

-first dimension is called a plane-consists of rows and columns
- three-dimensional array =>array of two-dimensional array


'Computer Science > Data Structure' 카테고리의 다른 글
| Trees (0) | 2023.08.09 |
|---|---|
| Linked List (0) | 2023.08.09 |
| Queue (0) | 2023.08.09 |
| Stacks (0) | 2023.08.09 |
| Complexity Analysis (0) | 2023.08.09 |