자료구조

시간복잡도 : bigO
메모리구조
leetcode.com (테스트)

List

queue

FIFO (First In, First Out)

stack

LIFO (Last In, First Out)텍스트

dictionary(hashtable)

graph

비선형 자료 구조 : 추상화

  • 방향/무방향 그래프
  • 다중/단순 그래프
  • 가중치/비가중치 그래프
  • 순환/비순환 그래프

구현방법

  • 인접행렬(adjacency matrix)
  • 인접리스트(adjacency list)
    graph = {
    1 : [2, 3, 4]
    2 : [1, 4]
    ..
    }
    
    for next_v in graph:
    	print(next_v)
  • 암시적그래프
    DFS
    BFS
    • 암시적 그래프 표현
        grid[r][c]

tree

heapq(우선순위큐)

알고리즘

완전탐색(+배트래킹)

재귀

반복문

DFS

깊이우선탐색 : 되돌아갈 곳을 기억 -> stack, 재귀함수..

def solution(lockers):
	visited = [False] * len(lockers)
    
    def dfs(cur_v):
    	visited[cur_v] = True
        for next_v in lockers[cur_v]:
        	if not visited[next_v]:
            	dfs(next_v)
    
    dfs(0)
    return all(visited)

BFS

너비우선탐색 : queue로 예약

def bfs(graph, start_v)
	q = deque()
    q.append(start_v)
    visited = {start_v: True} # set()
    
    while q:
    	cur_v = q.popleft()
        for next_v in graph[curl_v]:
        	q.append(next_v)
            visited[next_v] = True     

DP

Dijkstra

sort()

위상정렬

two pointer

profile
인공지능관련 작업중

0개의 댓글