맛집이나 마트에서 줄을 서는 것처럼, 데이터를 일정한 순서로 나열한 것을 선형 리스트라고 합니다.
먼저 온 손님이 먼저 순서를 갖고, 도착한 순서대로 한 줄로 서게 됩니다.
노래를 추가한 순서대로 재생목록에 나열되어 순서대로 재생됩니다.
오늘 해야 할 일을 순서대로 적어두고 위에서부터 처리합니다.
이처럼 일정한 순서로 데이터를 나열하는 방식이 컴퓨터 안에서도 그대로 쓰입니다. 이것이 바로 선형 리스트입니다.
Just like standing in line at a restaurant or store, a linear list arranges data in a specific order.
The first customer to arrive gets the first turn — everyone lines up in arrival order.
Songs are listed in the order they were added, and played back in that same order.
Tasks for today are written down in order and handled one by one from the top.
Arranging data in a fixed order like this is exactly how computers organize data too. This is called a linear list.
선형 리스트(Linear List)는 데이터를 일정한 순서로 나열한 자료구조입니다.
A Linear List is a data structure that arranges data in a specific order.
배열에 저장된 데이터는 메모리 주소를 가지고 있습니다. 인덱스가 증가할수록 메모리 주소도 일정하게 증가합니다.
우리가 인식하는 데이터의 순서. [0], [1], [2] ... 인덱스로 표현됩니다.
실제 컴퓨터 메모리에 저장되는 순서. 메모리 주소로 표현됩니다.
선형 리스트에서는 논리적 순서와 물리적 순서가 동일합니다. 즉, 인덱스가 1 증가하면 메모리 주소도 데이터 크기만큼 증가합니다.
id() 함수를 사용하면 객체가 저장된 메모리 주소를 확인할 수 있습니다.
Data stored in an array has a memory address. As the index increases, the memory address increases consistently as well.
The order we perceive the data in. Represented by index: [0], [1], [2] ...
The order data is actually stored in computer memory. Represented by memory addresses.
In a linear list, the logical order and physical order are identical. That is, as the index increases by 1, the memory address increases by the size of one element.
The id() function lets you check the memory address where an object is stored.
append(None)으로 빈 자리를 만든 뒤, len(katok)으로 길이를 구해 마지막 위치에 데이터를 대입합니다.
append(None) creates an empty slot, then len(katok) gets the length, and the new data is assigned to the last position.
선형 리스트에서 데이터를 중간에 삽입할 때, 왜 뒤에서부터 이동해야 하는지 설명하시오.
선형 리스트와 일반 배열의 차이점은 무엇인가?
5명의 친구 이름을 선형 리스트로 생성하는 코드를 작성하시오.
When inserting data in the middle of a linear list, explain why we must shift from the back.
What is the difference between a linear list and a regular array?
Write code to create a linear list with 5 friend names.
append()로 빈칸을 하나 추가한 다음, 그 자리에 데이터를 대입하면 끝에 삽입됩니다.
Use append() to add one empty slot, then assign the new data into that slot to insert at the end.
빈칸 추가 → 뒤에서부터 한 칸씩 이동 → 지정 위치에 삽입합니다.
Add an empty slot → shift elements one at a time starting from the back → insert at the specified position.
위치 2에 '솔라'를 삽입합니다. 기존 [2]번부터 끝까지의 데이터가 뒤로 한 칸씩 밀립니다.
position이 배열 길이(6)와 같으면 맨 끝에 삽입되는 경우입니다.
position이 0보다 작거나 리스트 길이보다 크면 삽입 범위를 벗어났다는 오류 메시지를 출력합니다.
Inserts 'Solar' at position 2. All existing data from index [2] onward shifts one slot to the right.
When position equals the array's length (6), the item is inserted at the very end.
If position is less than 0 or greater than the list length, an out-of-range error message is printed.
지정 위치 데이터 삭제 → 앞으로 한 칸씩 이동 → 마지막 빈칸 제거합니다.
Delete data at the given position → shift the rest forward one slot at a time → remove the last empty slot.
원본: ['다현', '정연', '쯔위', '사나', '지효']
위치 1의 '정연'을 삭제합니다.
위 결과에서 위치 3의 '지효'를 삭제합니다.
del(katok[kLen-1])을 실행하지 않으면 리스트 끝에 None이 남아 길이가 줄지 않습니다.
Original: ['다현', '정연', '쯔위', '사나', '지효']
Deletes '정연' at position 1.
From the result above, deletes '지효' at position 3.
Without del(katok[kLen-1]), a leftover None stays at the end and the list's length never shrinks.
katok.append(None) — 배열 끝에 빈칸(None)을 추가합니다.kLen = len(katok) — 현재 배열의 길이를 구합니다.katok[kLen-1] = friend — 방금 만든 마지막 빈칸에 데이터를 넣습니다.katok.append(None) — appends an empty slot (None) to the end of the array.kLen = len(katok) — gets the current length of the array.katok[kLen-1] = friend — assigns the data into the newly created last slot.range(kLen-1, position, -1)로 뒤에서부터 앞으로 한 칸씩 값을 옮깁니다.앞에서부터 이동하면 옮기기 전에 다음 데이터를 덮어써서 잃어버립니다. 반드시 뒤(끝)에서부터 앞으로 이동해야 데이터가 보존됩니다.
range(kLen-1, position, -1), move values from back to front one slot at a time.Shifting from the front would overwrite and lose the next value before it's moved. You must shift from the back (end) toward the front to preserve all data.
range(position+1, kLen)로 앞으로 한 칸씩 값을 옮깁니다.del(katok[kLen-1])로 완전히 제거합니다.삽입은 뒤에서 앞으로 이동, 삭제는 앞에서 뒤로 이동합니다. 이동 방향이 반대입니다.
range(position+1, kLen), move values forward one slot at a time.del(katok[kLen-1]).Insertion shifts from back to front, while deletion shifts from front to back — the direction is reversed.
1:추가, 2:삽입, 3:삭제, 4:종료 메뉴로 동작하는 대화형 프로그램입니다.
add_data(), insert_data(), delete_data() 함수를 모두 정의한 뒤, 무한 반복문(while)으로 사용자 선택을 처리합니다.
An interactive program driven by a menu: 1:Add, 2:Insert, 3:Delete, 4:Exit.
After defining add_data(), insert_data(), and delete_data(), an infinite while loop handles the user's menu choices.
Code03-02.py에서 position 검증이 없으면 어떤 문제가 발생하는지 설명하시오.
삭제 함수에서 del(katok[kLen-1])을 하지 않으면 결과가 어떻게 달라지는가?
Code03-04.py를 수정하여 '검색' 기능(특정 데이터 위치 찾기)을 추가하시오.
In Code03-02.py, what problems occur if position validation is missing?
In the delete function, how does the result change if we skip del(katok[kLen-1])?
Modify Code03-04.py to add a 'search' feature (find position of specific data).
각 항의 계수(coefficient)만 순서대로 배열에 저장하면 다항식을 표현할 수 있습니다.
계수를 배열로 저장: [7, -4, 0, 5]
인덱스 i의 지수는 (전체 항 개수 - 1) - i로 계산됩니다.
Storing only the coefficients of each term, in order, is enough to represent the polynomial.
Coefficient array: [7, -4, 0, 5]
The exponent for index i is computed as (total number of terms - 1) - i.
최고차항부터 순서대로 문자열을 만들어 다항식을 출력합니다.
term = len(p_x) - 1 — 최고차항의 지수부터 시작합니다."+"기호를 붙입니다(음수는 자체 부호 사용).term을 1씩 줄입니다.Builds a string term by term, from the highest degree down, to print the polynomial.
term = len(p_x) - 1 — start from the exponent of the highest-degree term."+" sign (negatives already have their own sign).term by 1 after processing each term.특정 x값을 대입하여 다항식의 값을 계산합니다.
P(x) = 7x³ - 4x² + 0x¹ + 5x⁰, x = 2일 때:
7×2³ - 4×2² + 0×2¹ + 5×2⁰ = 56 - 16 + 0 + 5 = 45
※ 교재 예제와 값이 다를 수 있으므로 직접 계산해 확인해 봅시다.
Substitutes a specific x value to compute the polynomial's result.
For P(x) = 7x³ - 4x² + 0x¹ + 5x⁰ with x = 2:
7×2³ - 4×2² + 0×2¹ + 5×2⁰ = 56 - 16 + 0 + 5 = 45
※ Verify the exact value yourself — it may differ slightly from the textbook.
이 방식은 지수가 매우 큰 경우(예: x³⁰⁰) 배열에 사용하지 않는 항까지 모두 저장해야 해서 메모리가 낭비됩니다.
For very large exponents (e.g., x³⁰⁰), this approach must store every unused term in the array, wasting memory.
이런 경우 모든 지수 자리를 배열에 저장하면 매우 비효율적입니다.
0이 아닌 계수와 그 차수만 별도로 저장하는 방식을 사용합니다.
tx = [300, 20, 0] (차수), px = [7, -4, 5] (계수)
Storing every possible exponent slot in an array here would be extremely inefficient.
Instead, store only the non-zero coefficients and their degrees.
tx = [300, 20, 0] (degrees), px = [7, -4, 5] (coefficients)
t_x[i]로 실제 지수를 바로 읽어오므로, 지수를 1씩 감소시키는 term -= 1 코드가 필요 없습니다.
Since t_x[i] gives the actual exponent directly, there's no need for a term -= 1 decrement.
카톡 횟수(count)에 따라 자동으로 알맞은 순위 위치에 삽입하는 함수입니다.
len(katok))에 삽입합니다.Automatically inserts a friend into the correct ranking position based on their chat count.
len(katok)).기존에 tx, px 두 배열로 나누어 쓰던 것을 2차원 배열 하나로 통합합니다.
px[0] = 차수 배열 [300, 20, 0]px[1] = 계수 배열 [7, -4, 5]
관련된 두 배열을 하나의 변수로 관리하므로, 함수에 넘길 인자가 줄어들고 데이터 관리가 편리해집니다.
Merges what used to be two separate arrays (tx, px) into a single 2D array.
px[0] = degree array [300, 20, 0]px[1] = coefficient array [7, -4, 5]
Managing two related arrays as a single variable reduces the number of function arguments and simplifies data handling.
다항식 P(x) = 3x⁴ + 2x² - 1을 배열로 표현하시오.
Code03-06.py의 방식으로 P(x) = 5x¹⁰⁰ + 3x⁵⁰ - 2x¹⁰ + 1을 표현하시오.
Ex03-01.py에서 동일한 연락 횟수일 때 새 친구가 앞에 오는 이유를 설명하시오.
Represent polynomial P(x) = 3x⁴ + 2x² - 1 as an array.
Using Code03-06.py's approach, represent P(x) = 5x¹⁰⁰ + 3x⁵⁰ - 2x¹⁰ + 1.
In Ex03-01.py, explain why a new friend with the same chat count is placed before existing ones.