Algorithm

    [1028알고리즘 14]그래프

    그래프 연결되어 있는 정점과 정점간의 관계를 표현할수 있는 자료구조. 선형구조는 자료저장, 꺼내는것, 비선현구조는 표현에 초점. 그래프는 연결관계에 초점. 그래프는 유방향(Directed Grape)과 무방향(undirected Grape) 그래프 두가지가 있음. 1) 인접행렬(Adjacency Matrix) 2차원 배열로 그래프의 연결 관계를 표현 0 1 2 3 0xOxx 1OxOx 2xOxO 3xxOx graph = [ [false, true , false, false] [true, false, true, false] [false, true, false, true] [false, false, true, false] ] 2) 인접리스트(Adjacency List) 링크드 리스트로 그래프의 연결관계를 표..

    [1028알고리즘 13]탑송신

    #[6, 9, 5, 7, 4] →[0, 0, 2, 2, 4] # 4 는 4번째에서 수신 # 7은 2번째에서 수신 # 5는 두번째에서 수신 # 9는 수신안됨 # 6은 수신안됨 top_heights = [6, 9, 5, 7, 4] def get_resive_top_order(heights): result = [0]* len(heights) while heights: height = heights.pop() for idx in range(len(heights)-1,0,-1): print(idx) if heights[idx] > height: result[len(heights)] = idx +1 break return result print(get_resive_top_order(top_heights))

    [1028알고리즘]Queue - JAVA

    import java.util.HashMap; import java.util.Map; Map wants_dic = new HashMap(); wants_dic.put(1, 1); System.out.println(wants_dic.get(1)+1); import java.util.LinkedList; import java.util.Queue; Queue queue = new LinkedList(); System.out.println(queue.add(1)); System.out.println(queue.peek()); System.out.println(queue.poll()); System.out.println(queue.add(1)); System.out.println(queue.add(2)); Sys..

    [1028알고리즘 12] 큐 구현

    노드구현 큐 의 초기화 구현 * head, tail 큐의 enqueue data 마지막에넣음 큐의 dequeue 처음에서뺌 큐의 peek 큐의 isEmpty() class Node: def __init__(self, data): self.data = data self.next = None class Queue: def __init__(self): self.head = None self.tail = None def isEmpty(self): return self.head is None def enqueue(self,data): new_node = Node(data) if self.isEmpty(): self.head = new_node self.tail = new_node return self.tail.n..

    반응형