beginning with a tree T containing a single vertex
repeatedly adding the least cost edge between T and the rest of the graph
terminating when T spans all vertices
- The document discusses graphs and graph algorithms including definitions of graph terminology, representations of graphs, graph traversal algorithms like depth-first search and breadth-first search, and algorithms for finding minimum spanning trees like Kruskal's algorithm and Prim's algorithm.
- It provides detailed descriptions and pseudocode for graph traversal algorithms, algorithms to find connected components and articulation points, and minimum cost spanning tree algorithms.
- The document is intended as a curriculum for teaching graph algorithms and data structures.
An equivalence relation is a binary relation that is reflexive, symmetric, and transitive. To determine if a relation is an equivalence relation, one must check that for any elements a and b, a is related to a (reflexive), if a is related to b then b is related to a (symmetric), and if a is related to b and b is related to c, then a is related to c (transitive). To find the equivalence classes, one identifies all element pairs in the relation and finds those that contain a specific element like 0.
The document describes how to represent a sparse matrix using a linked list structure. Head nodes are used to represent rows and columns, with entry nodes linked below to store nonzero elements. An algorithm is provided to read in a matrix and build this linked representation by adding entry nodes and linking head and entry nodes. Analyzing the algorithm, building the linked structure takes O(n+m+p) time where n is the number of rows, m is the number of columns, and p is the number of nonzero elements. Functions to write and erase the matrix are also discussed, both taking O(n+p) time.
The document discusses representing polynomials using linked lists. Polynomials can be represented as singly linked lists by storing the coefficient and exponent of each term in a node. Adding polynomials involves traversing the lists and combining terms with matching exponents. Polynomials can also be represented using circular linked lists. This allows nodes to be reused by maintaining a list of available nodes, and getting nodes from this list or returning nodes to it.
beginning with a tree T containing a single vertex
repeatedly adding the least cost edge between T and the rest of the graph
terminating when T spans all vertices
- The document discusses graphs and graph algorithms including definitions of graph terminology, representations of graphs, graph traversal algorithms like depth-first search and breadth-first search, and algorithms for finding minimum spanning trees like Kruskal's algorithm and Prim's algorithm.
- It provides detailed descriptions and pseudocode for graph traversal algorithms, algorithms to find connected components and articulation points, and minimum cost spanning tree algorithms.
- The document is intended as a curriculum for teaching graph algorithms and data structures.
An equivalence relation is a binary relation that is reflexive, symmetric, and transitive. To determine if a relation is an equivalence relation, one must check that for any elements a and b, a is related to a (reflexive), if a is related to b then b is related to a (symmetric), and if a is related to b and b is related to c, then a is related to c (transitive). To find the equivalence classes, one identifies all element pairs in the relation and finds those that contain a specific element like 0.
The document describes how to represent a sparse matrix using a linked list structure. Head nodes are used to represent rows and columns, with entry nodes linked below to store nonzero elements. An algorithm is provided to read in a matrix and build this linked representation by adding entry nodes and linking head and entry nodes. Analyzing the algorithm, building the linked structure takes O(n+m+p) time where n is the number of rows, m is the number of columns, and p is the number of nonzero elements. Functions to write and erase the matrix are also discussed, both taking O(n+p) time.
The document discusses representing polynomials using linked lists. Polynomials can be represented as singly linked lists by storing the coefficient and exponent of each term in a node. Adding polynomials involves traversing the lists and combining terms with matching exponents. Polynomials can also be represented using circular linked lists. This allows nodes to be reused by maintaining a list of available nodes, and getting nodes from this list or returning nodes to it.
This document describes dynamically linked queues. It defines a Queue class with an item and link field. It shows how to add an item to the rear of the queue by creating a new Queue node, linking it to the current rear, and updating the rear pointer. It also shows how to delete from the rear by getting the front node, returning its item, and updating front to the next node. Diagrams illustrate the queue changes during add and delete operations.
This document describes dynamically linked stacks which allow for adding and removing elements from multiple stacks. It discusses using a linked list structure with Stack nodes that point to the top element of each stack. Elements can be added by creating a new Stack node, assigning its item field, and updating the top pointer. Elements are removed by saving the top item, updating top to point to the next node, and returning the item. This allows efficient insertion and removal from multiple stacks using linked lists.
Singly linked lists are data structures made up of nodes that contain data and a link to the next node. The nodes are not stored sequentially in memory. New nodes can be added by allocating a new node, filling its data field, and linking it to the next node. Nodes can be removed by linking the previous node's link to the node after the one being removed. Code examples demonstrate how to create a two node list and insert a new node in the middle.
The document describes a maze problem that can be solved using a stack data structure. It represents a maze as a 2D array with 0s as open paths and 1s as barriers. It stores the current position and direction in a class and pushes positions to a stack as it recursively searches the maze. Allowed movements are defined by offsets. The algorithm initializes the stack with the entrance, pops positions from the stack to search from, and pushes new positions to the stack if the path is open and unvisited.
This document discusses evaluating expressions in infix and postfix notations. It provides examples of converting infix expressions to postfix expressions by moving operators and removing parentheses. To evaluate a postfix expression, tokens are read from left to right and pushed onto a stack. At each operator, the top two stack elements are popped and the operation performed before pushing the result back onto the stack.
This document describes dynamically linked queues. It defines a Queue class with an item and link field. It shows how to add an item to the rear of the queue by creating a new Queue node, linking it to the current rear, and updating the rear pointer. It also shows how to delete from the rear by getting the front node, returning its item, and updating front to the next node. Diagrams illustrate the queue changes during add and delete operations.
This document describes dynamically linked stacks which allow for adding and removing elements from multiple stacks. It discusses using a linked list structure with Stack nodes that point to the top element of each stack. Elements can be added by creating a new Stack node, assigning its item field, and updating the top pointer. Elements are removed by saving the top item, updating top to point to the next node, and returning the item. This allows efficient insertion and removal from multiple stacks using linked lists.
Singly linked lists are data structures made up of nodes that contain data and a link to the next node. The nodes are not stored sequentially in memory. New nodes can be added by allocating a new node, filling its data field, and linking it to the next node. Nodes can be removed by linking the previous node's link to the node after the one being removed. Code examples demonstrate how to create a two node list and insert a new node in the middle.
The document describes a maze problem that can be solved using a stack data structure. It represents a maze as a 2D array with 0s as open paths and 1s as barriers. It stores the current position and direction in a class and pushes positions to a stack as it recursively searches the maze. Allowed movements are defined by offsets. The algorithm initializes the stack with the entrance, pops positions from the stack to search from, and pushes new positions to the stack if the path is open and unvisited.
This document discusses evaluating expressions in infix and postfix notations. It provides examples of converting infix expressions to postfix expressions by moving operators and removing parentheses. To evaluate a postfix expression, tokens are read from left to right and pushed onto a stack. At each operator, the top two stack elements are popped and the operation performed before pushing the result back onto the stack.
2. Question
•
•
•
•
문제는 올림피아드 대회가 모두 해외에서 열리는 관계로 비행기 값이 굉장히 많이 들어간다는 것이다. 결국에는 집
으로 다시 돌아와야 하는데, 모든 대회에 1번씩만 참가하고 집으로 돌아오는 경비를 가장 최소화하고 싶다. 도경이
는 이것을 해결하지 못하면, 대회에 참가하기가 어렵게 된다. 대회는 참가하기만 하면 언제든지 알고리즘 문제를 풀
수 있기 때문에 경비를 계산하는 것 이외의 사항은 고려하지 않아도 된다.
입력 형식
첫 줄은 참가하는 대회의 수 N(1≤N≤12)을 입력 받는다. 이때, 출발지(집)는 1번으로 한다.
둘째 줄은 N X N 크기의 대회 개최지와 개최지를 이동하는 항공료(0 ≤ 항공료< 100)가 나온다. 각 항공료는 한 칸
의 공백으로 구분된다. 만약에 개최지에서 개최지로 이동할 수 있는 항공로가 없다면 항공료의 값을 0으로 표시한
다.
출력 형식
집에서 출발하여 전체 대회를 모두 참가하고 돌아올 때, 최소의 항공료를 출력한다.
입력 예
5
0 14 4 10 20
14 0 7 8 7
4 5 0 7 16
11 7 9 0 2
18 7 17 4 0
•
출력 예
30
Hint.
비용 (경로)
10 (1->4)
+ 2 (4->5)
+ 7 (5->2)
+ 7 (2->3)
+ 4 (3->1)
= 30
5. Core methods
• makeAvailableCircuit()
–
가능한 루트를 찾음
• containsSite(int)
–
사이트를 반복해서 방문하는 지 검토
• findMinCircuit()
–
–
모든 사이트를 순회 한 경우
지나 온 경로의 비용을 합하여 가능한 다른 경로에서 발생한 비용과 비교 후 작으면 최소경로로 지정