
개발자로서 꼭 갖춰야할 핵심 역량 ->
문제 해결 능력
논리적 사고, 전산화 능력, 엣지 케이스 탐색(버그 줄이기)

O(1) < O(log n) < O(n) < O(n log n) < O(n²) < O(2ⁿ) < O(n!)
for(let i=0; i<n; i++){
//선형시간 O(n)
}
for(let i=1; i<=n; i*=2){
//O(log n)
}
for(let i=0; i<n; i++){
for(let j=1; j<=n; j*=2){
//O(n log n)
}
}
for(let i=0; i<n; i++){
for(let j=0; j<n; j++){
// O(n²)
}
}
// Date 객체를 이용
//시작 시간을 구함
const start = new Date().getTime();
//코드 구현
//끝 시간을 구함
const end = new Date().getTime();
console.log(end - start);
//빈 Array 생성
let arr1 = [];
console.log(arr1);
//미리 초기화된 Array 생성
let arr2 = [1,2,3,4,5];
console.log(arr2);
//많은 값을 같은 값으로 초기화한 배열 생성 fill
let arr3 = Array(10).fill(1);
console.log(arr3);
//특정 로직을 사용해 초기화 할 경우 from
let arr4 = Array.from({length : 100}, (_,i) => i);
console.log(arr4);
const arr = [1,2,3,4];
console.log(arr);
//끝에 5 추가
arr.push(5);
//여러 개 추가도 가능
arr.push(6,7);
//3번 인덱스에 100 추가
arr.splice(3,0,100); //O(n)
console.log(arr);
//3번 인덱스 값 제거
arr.splice(3,1); //O(n)
console.log(arr);

const arr = [1,1,2,3];
arr["string"] = 10;
arr[false] = 0;
console.log(arr);
console.log(arr.length);
arr[4] = 15;
console.log(arr);
console.log(arr.length);

포인터로 연결하여 관리하는 선형 자료구조이다. 각 요소는 노드라고 부르며 데이터 영역, 포인트 영역을 가지고 있다.
Head(시작)에서 Tail(끝)까지 단방향으로 이어지는 연결 리스트
O(n), 요소 추가, 요소 삭제 O(1)class Node{
constructor(value){
this.value = value;
this.next = null;
}
}
class SinglyLinkedList{
constructor(){
this.head = null;
this.tail = null;
this.length = 0; // 길이 추가
}
find(value){ //요소 찾기
let curNode = this.head;
while(curNode.value !== value){
curNode = curNode.next;
}
return curNode;
}
append(newValue){ //요소 추가 > 끝 부분에
const newNode = new Node(newValue); //새로운 노드 생성
if(this.head === null){ //연결리스트에 아무런 값이 없을 시
this.head = newNode;
this.tail = newNode;
}else{
this.tail.next = newNode;
this.tail = newNode;
}
this.length++;
}
insert(node,newValue){ //요소 추가 > 중간에
const newNode = new Node(newValue);
newNode.next = node.next; //새로운 노드의 다음이 입력받은 노드의 다음을 가르키도록 함
node.next = newNode; //입력받은 노드의 다음이 새로운 노드가 되도록 함
this.length++;
}
remove(value){ //요소 삭제 > 여기서는 값을 찾은 다음 삭제하도록 작성 O(n) 소요
// 상수 시간이 되고 싶으면 삭제할 노드의 이전 노드를 매개 변수로 작성해 주면 됨
let preNode = this.head;
while(preNode.next.value !== value){
preNode = preNode.next;
}
if(preNode.next !== null){
preNode.next = preNode.next.next;
// 다음의 다음노드를 가리키도록 설정하면 중간 노드가 아무런 노드와 연결되지 않기 때문에 자동으로 삭제된다.
// 가비지 컬렉션 통해 메모리 상에서도 자연스럽게 삭제됨
}
this.length--;
}
display(){
let curNode = this.head;
let displayString = '[';
while(curNode !== null){
displayString += `${curNode.value}, `;
curNode = curNode.next;
}
displayString = displayString
.substr(0,displayString.length-2);
displayString += ']';
console.log(displayString);
}
}
const linkedlist = new SinglyLinkedList();

class Node{
constructor(value){
this.value = value;
this.next = null;
this.prev = null;
}
}
class DoublyLinkedList{
constructor(){
this.head = null;
this.tail = null;
this.length = 0;
}
find(value){
let curNode = this.head;
while(curNode.value !== value){
curNode = curNode.next
}
return curNode;
}
append(newValue){
const newNode = new Node(newValue);
if(this.head === null){
this.head = newNode;
this.tail = this.head;
}else{
this.tail.next = newNode;
newNode.prev = this.tail;
this.tail = newNode;
}
this.length++;
}
insert(node,newValue){
const newNode = new Node(newValue);
const next = node.next;
next.prev = newNode;
node.next = newNode;
newNode.next = next;
newNode.prev = node;
this.length++;
}
remove(preNode,value){
if(preNode.next !== null){
const next = preNode.next.next;
preNode.next = next;
next.prev = preNode;
}
this.length--;
}
display(){
let curNode = this.head;
let displayString = '[';
while(curNode !== null){
displayString += `${curNode.value}, `;
curNode = curNode.next;
}
displayString = displayString
.substr(0,displayString.length-2);
displayString += ']';
console.log(displayString);
}
}
const example = new DoublyLinkedList();

topconst stack = [];
stack.push(1);
stack.push(2);
stack.push(3);
console.log(stack); //[ 1, 2, 3 ]
stack.pop();
console.log(stack); //[ 1, 2 ]
head가 top > head를 추가하고 제거하는 방식class Node{
constructor(value){
this.value = value;
this.next = null;
}
}
class Stack{
constructor(){
this.top = null;
this.size = null;
}
push(value){
const newNode = new Node(value);
newNode.next = this.top;
this.top = newNode;
this.size++;
}
pop(){
const value = this.top.value;
this.top = this.top.next;
this.size--;
return value;
}
size(){
return this.size;
}
}
const stack1 = new Stack();