알파카징징이 알파카징징이 코딩하는 알파카

데이터 구조 및 분석 ch_3_2 Array

» writing

KAIST 산업및시스템공학과 문일철_ 데이터 구조 및 분석 수업을 참고하여 작성하였습니다

ch_3_2 Array

정의


Array

1. Array
   : 동일한 data를 index로 활용하여 저장
   : we will use its index function
   - Each element is accessible by indx
   - index is zero or a positive integer (0으로 시작함)
ex) x = ['a', 'b', 'c']
   index  0    1    2 

2. Search precedure in array
   : navigating from the fist to the last until hit is the only way
x = ['a', 'b', 'c']
for i in range(len(x)) :
    if 'a' in x[i] :
        print('a detect!')
# a detect!
3. Insert procedure in array
   1) make new list y = []
   2) copy a reference links x [0:a-1] to y [0:a-2]
   3) put a reference link to '~~'
   4) copy a reference links of x[a:] to y[a+1:]
   5) change x's reference to y's reference
   6) total count of retrievals = a+1+n-a-1 = n
x = ['a', 'b', 'd','e','f']
idxInsenrtn = 2
valInsert = 'c'

y = list(range(6))

for itr in range(0, idxInsenrtn) :
    y[itr] = x[itr]
y[idxInsenrtn] = valInsert
for itr in range(idxInsenrtn, len(x)) :
    y[itr+1] = x[itr]
x = y
print(x)
# ['a', 'b', 'c', 'd', 'e', 'f']
4. Delete procedure in array
    1) make new list
    2) copy reference links of x[0:a-1] to y[0:a-1]
    3) copy reference links of x[a+1] to y[a:]
    4) change x's reference to y's reference
    5) totla count of retrevals = a+n-a-1=n-1
# d 없애기 !!

x = ['a', 'b', 'c','d','e','f']
idxInsenrtn = 3

y = list(range(5))

for itr in range(0, idxInsenrtn) :
    y[itr] = x[itr]
for itr in range(idxInsenrtn, len(x)) :
    y[itr-1] = x[itr]
x = y
print(x)
# ['a', 'b', 'd', 'e', 'f']
5. problems in array
   : Whenever you put something in or get something out
        - you havet to perform line-wise retrevals
        - array -> you are bounded to the 1-dimension that you have
        - linked list -> you are bounded no more!