CS/자료구조 17

Chapter 8: Tree

경희대학교 박제만 교수님의 자료구조 수업을 기반으로 정리한 글입니다.Treedata 간에 hierarchy가 존재할 때 data를 표현하는 방식을 tree라고 한다. Nodes▶ Parents and Children Nodes▶ Root Node▶ Leaf Nodes Level▶ Level 0▶ Level 1▶ Level 2 Subtree▶ Left subtree▶ Right subtree Type Data▶ Char Type Data▶ Int Type Data Unique Path▶ A unique path exists from the root node to every other node.The path from E to Z: E -> C -> Z (acyclic structure)Binary Tree..

CS/자료구조 2025.06.08

Programming Exercise: Lab #6

경희대학교 박제만 교수님의 자료구조 수업을 기반으로 정리한 글입니다.Exercise #1ProblemsImplement the SORTED LIST using doubly linked structure.1) insertItem(item): Insert the item to the proper position in the list.2) removeItem(item): Delete "item" in the listDeallocate (delete) the deleted item.template void DoubleSortedType::insertItem(ItemType item){ NodeType* newNode = new NodeType; NodeType* tempPtr = listData;..

CS/자료구조 2025.06.02

Chapter 7: Recursion

경희대학교 박제만 교수님의 자료구조 수업을 기반으로 정리한 글입니다.RecursionDefinitionsRecursive call: 재귀, 자기 자신을 호출하는 것Direct recursion: 직접적으로 자기 자신을 호출, e.g., a 함수가 a 함수 호출Indirect recursion: 다른 함수를 우회해 자기 자신을 호출, e.g., a 함수가 b 함수 호출 -> b가 a 함수 호출 Recursion의 필요성recursive한 프로그래밍은 모두 nonrecursive한 방법으로도 가능하다.즉, 반드시 필요한 것은 아니기에 recursion을 사용하지 않아도 모든 알고리즘 구현 가능하다. Recursive solutions can be less efficient than iterative solu..

CS/자료구조 2025.06.02

Programming Exercise: Lab #5

경희대학교 박제만 교수님의 자료구조 수업을 기반으로 정리한 글입니다.Exercise #1ProblemsImplement the UNSORTED LIST using linked structure and ANSWER the time complexity questions in the code.Destructor(): Deallocate (delete) all nodes in the list.appendItem(item): Append the item to the list (with the best time complexity)removeItem(item): Delete "item" in the list and Deallocate (delete) the deleted item.getItem(pos): Retur..

CS/자료구조 2025.05.20

Chapter 6: Linked Structures (2)

경희대학교 박제만 교수님의 자료구조 수업을 기반으로 정리한 글입니다.Linked StructuresReview▶ Big-O Comparison of Stack Operations▶ Big-O Comparison of Queue OperationsArray vs. Linked StructurePerformanceGenerally, array-based structures are faster than linked structures.Most operations are equally fast for both array and linked structures (O(1)).For size(), clear(), and destructor, the array is faster (O(1) vs. O(n)).But, a..

CS/자료구조 2025.05.20

Programming Exercise: Lab #4

경희대학교 박제만 교수님의 자료구조 수업을 기반으로 정리한 글입니다.Exercise #1ProblemsImplement linked structure STACK.~StackType(): destructorsize(): returns the length of stackpush(): pushes a new item into the stackpop(): pops and returns the item at the top of stack (if the stack is empty, return -1)StackType::~StackType(){ NodeType* tempPtr = topPtr; while (tempPtr != nullptr) { topPtr = topPtr->next; ..

CS/자료구조 2025.04.19

Chapter 5: Linked Structures (1)

경희대학교 박제만 교수님의 자료구조 수업을 기반으로 정리한 글입니다.Linked Structure Array-based Stack Implementation▶ In the previous implementation, we consider an entire stack (a set of items) as a single object (array). New stack Implementation▶ Here, we consider each item in the stack a single object (Node).How could we define relationships between items? (Who's on top of whom?)Node Implementation▶ A pointer can be used..

CS/자료구조 2025.04.16

Programming Exercise: Lab #3

경희대학교 박제만 교수님의 자료구조 수업을 기반으로 정리한 글입니다.Exercise #1ProblemsImplement rotateFirstItem() in Circular Queue with Reserved space.This function "ROTATES" the first item of the queue.▶ Both are OKAY (in-place or not)! HINT: It is allowed to call "other member functions" inside a member function.e.g., enqueue(), dequeue(), isEmpty(), etc.)templatevoid QueueType::rotateFirstItem(){ if(isEmpty()){ ..

CS/자료구조 2025.04.16

Chapter 4.5: Programming Tips

경희대학교 박제만 교수님의 자료구조 수업을 기반으로 정리한 글입니다.Call by X▶ Swap Example (1) - call by valueswap1_a = 3swap1_b = 5▶ Looking into 'Swap1'▶ Swap Example (2) - call by referenceswap2_a = 5swap2_b = 3▶ Swap Example (3) - call by pointer(address)swap3_a = 5 swap3_b = 3▶ Swap Example (4)swap1_a = 3swap1_b = 5 C/C++ Basics:it is almost about "copy" How C/C++ Deals with Variables: Copy▶ copyWe learned it as "inser..

CS/자료구조 2025.04.16