for Robot Artificial Inteligence

3.N-Notation

|

Introduction

  • In computer science we need a way to be able to compare different algorithms with each other. We typically use the n-Notation for this.

Why is it Important?

  • Run times of different programs are usually written in n-Notation. So if we want to look up how fast a certain algorithm is, we will need to know this notation to be able to understand it.

Lesson Notes

  • N-Notation is represented as a function of n. This simply means that the program is going to be related to the variable n in some way.

  • N-notation is NOT an analysis of how long an algorithm will take to run, but an analysis of how the algorithm will scale with more and more input data.

  • This method is based off looking at the input of the algorithm and analyzing how the algorithm works with this input. However, we don’t particularly know how many pieces of data will come in at any given moment. What we do is replace this input number with a variable, n.

  • For example, let’s say we have an algorithm which runs through the amount of Facebook friends you have. When we are writing the algorithm, we have no clue how many friends are going to be added as input. You could have 250, or 2,000, or 2. So instead of giving an actual number, we just say n pieces of data will be put into this algorithm

  • (The n here is just a variable, it could be x, or w, or z, but we typically use n). It is usually a count of how many operations are being run by a program. This can be the amount of inputs, the calculations, or the outputs

  • The reason we use n is because it will show us how our program might react differently to different amounts of data. We as computer scientists never know how many pieces of data our programs are going to handle. So instead, we look at how our program is going to grow with different amounts of inputs.

  • As you can see with this chart, the different values yield vastly different results. The difference between n and n^2 is substantial. If you brought this out to infinity, the difference would almost be a 90-degree angle. (As the difference between them would grow to nearly infinity)

  • We can use these different values to compare how our different algorithms might react to different amounts of data.

  • The above table represents the change. It inputs some different numbers as n and then displays what different n values would give. These numbers vary a lot with the given n-formulas.

  • For example, with only 1,000 pieces of data, the difference between n^2 and nlog(n) is from 1,000,000 to 9965. Even though they look decently close on the line-chart above, nlog(n) will only take 1% of the time as n^2. This difference will grow the larger our n becomes.

  • This is the key concept behind n-notation. Even though we don’t know the specific amount of data that is coming through our program, we can atleast compare it to another that accomplishes the same task. If one runs at n^2 while the other runs at n, we know the n will be faster in every case.

BIG O

  • We usually don’t use n by itself however. Typically we tie it together with a Greek letter to give it some context. Rarely does our program operate at the same timing for every single step. So instead of having exact values for things, we want to look at them in boundaries, or cases in which they are greater, less than, or equal.

  • For this notation, we just use one of the Greek symbols above, with our n notation inside of the parenthesis. So for example, O(nlogn) would mean that the program is faster or equal to nlogn.

  • The most important notation above is the Omicron, or “Big O”. The reason for this is because it gives us a worse case scenario. That means we know the absolute worse case scenario of our program, meaning if we plan for this, we won’t have any surprises or weird corner cases that come up.

  • We can then compare the worst case scenarios of programs to see which are faster. Since this is the absolute slowest the program can run, we know that one program will always run slower than another program!

  • For example let’s say that we have two programs, program A which runs at Ω(n) and program B which runs at Ω(n^2). Which of these two programs is better? Well all we know is that program A is slower or equal to n and program B is slower or equal to n^2. However that doesn’t guarantee anything. Program A could end up running around n^3 or n! and meet the requirements of Ω(n). B could do the exact same thing, so their speed is still arbitrary. So with these symbols, we don’t learn too much about the two programs.

  • However, if we used O(n) for A and O(n^2) for B, we can now compare the two. We know without a doubt that A will not run slower than n while B can run up to n^2. Therefore the faster is Program A, because it can never get slower than B

  • Let’s use some numbers to drive this point home a little more.

  • Let’s say we have a time scale to determine how fast our algorithm runs. In this scale the closer to 0 we go, the faster our algorithm. We can use to show why Big O is typically the most useful of these notations.

Notation of other comparison

  • ω(7) - The algorithm will run slower, or > 7. How much greater? 1,000. 1,000,000? There is no way to know. This algorithm could take years to complete the simplest of tasks.

  • Ω(7) - The algorithm will run “slower or equal” to 7, or >=7. Still could run in to infinity or really large run times

  • Θ(7) - The algorithm is equal to 7, or = 7. This would be great. If we can guarantee an algorithm will always run equal to something we would use this. However, this is highly unlikely in the real world, so it’s not used too often.

  • O(7) - The algorithm will run “faster or equal” to 7, or <=7. This is good. We have a limit on the algorithm. We know in all cases, 7 is the worst this algorithm can do. This can be used to plan with. No surprises will come up here.

  • o(7) - The algorithm will run faster than 7, or < 7. There is nothing inherently wrong with this, except that it’s just less accurate than O(7). How much faster will it run? 6? 2?. We don’t know the limit. Although we can still plan a worst case scenario with this, it’s less accurate than O(7) which is why it’s rarely used.

  • There you have it, BIg O notation. This is used all across computer science, and now you know how to read it!

Comment  Read more

2. Math Refresher Notes for Computer science.

|

Introduction

  • A quick refresher on some of the key math concepts we will see throughout the course.

Why is it Important?

  • Computer science in its essence is applied mathematics. This means it has a strong foundation in many different types of math. Understanding the basics of some math functions will help to get a better picture of computer science as a whole

Lesson Notes

Logarithmic Functions

  • Log (short for logarithmic) functions are commonly referred to in computer science. This is because they are the inverse of exponential functions. Where an exponential function grows more and more over time, a log function grows less and less over time.

  • Below you can see the difference between these functions. On the bottom you will see a log(n), and then it’s inverse, near the top, the 2^n. Note how the log has a little two with it, this means it is using base two. Remember from the binary lesson, base 2 uses only 1 and 0. This is important when using with an online calculator. Make sure the log is set to base 2. Notice how the log function becomes almost horizontal, while the exponential function becomes almost vertical.

  • Let’s say for example this is a graph of run times. So the bottom is how many pieces of data are inserted, and the left is how long it will take. You will notice with a log function, we can insert 100 pieces of data and have a run-time below 5. With an exponential function however, we only have to insert around 5 pieces of data before our run-time exceeds 100.

  • Here is a good link that describes them in a slightly different way and has some practice examples. Understanding log functions in their entirety IS NOT required for this class. All you need to know is that they are efficient, and that they are the inverse of exponential functions.

Factorial Expressions

  • Factorials are interesting expressions. The notation for them are n! . What this means is that we are going to multiply a series of numbers up until the variable n.

4! = 1 * 2 * 3 * 4 = 24

5! = 1 * 2 * 3 * 4 * 5 = 120

8! = 1 * 2 * 3 * 4 * 5 * 6 * 7 * 8 = 40,320

10! = 1 * 2 * 3 * 4 * 5 * 6 * 7 * 8 * 9 * 10 = 3,628,800

  • As you can see, factorials grow at an astounding rate. If any of our functions ever reach this, they will most likely never finish. Almost, if not every algorithm in computer science can be accomplished in faster than n! time.

Algebraic Expressions

  • We will encounter a few algebraic expressions throughout the course. They may look something like nlogn or 2nlog(n^2) etc. All this means is that we have a variable n that will be plugged in to the equation. Because we don’t actually know how many pieces of data will go in to the algorithm, we use this n placeholder. (More about this in the next lecture).

  • Once we know the n value however, we can plug it in, and calculate the answer. For example, if n=32, we will then have nlogn or 32 * log(32). This would come out to 32 * 5 = 160 units of time.

Comment  Read more

1. Binary Number system

|

Introduction

  • Most of us have worked in the deca(0~9) system our entire life. Computers however use an entirely different number system to operate

Why is it Important?

  • Computers at their most basic level use electricity to operate. Electricity only has two reliable states, on(1) and off(0). For this reason, computers use the binary number system, which only operate off two numbers, 0 and 1. computers don’t have the ability to use the deca system. Since computer science is the study of computers, it is helpful that we understand the math that computers use, so we can better understand their logic.

Lesson Notes

  • the deca system is the number systwm we tripically use. it runs off something called “Base 10” . this means after 10 of each number’s place. we increase the number of the next greatest magnitude. so we have 1,10,100,10000,100000 and so on.

  • If we add 1 to 9, the one’s place gets reset to 0, and then the next magnitude is increased. So we are left with 10. If we have 99 and increase by 1, the 1’s spot is reset to 0, the 10’s spot is increased by one. There is already a 9 here, so it gets reset to 0 as well and then increments the next spot by 1. So we are left with 100. This makes it easy to do math, as each spot just adds an additional zero.

  • It may help to think of the numbers with leading 0’s. So 00000998. If we add 1, it’s now 00000999. Add one more, and we have to increment each 9. They get reset, and then the zero to the left is set to 1, 00001000.

  • The binary system however is different than this. Instead of having 10 numbers it can use, it only has 2. It has a 0 and a 1. This is due to how computers work at a basic level. They are only capable of reading whether a switch is on, or if it is off. They can’t reliably read anything in between. This means all the math a computer does must be based off of this “on” (1) and this “off” (0).

  • A CPU processor has millions of these little switches all working in unison, combining and reorganizing the 1’s and 0’s to perform operations

  • This binary system means that the number system works off of “Base 2” instead of “Base 10”. This means it goes up in order of 2’s.

  • Let’s compare the deca and binary system with some tables. Below we have the number 1,578,483 broken out into it’s magnitudes (number’s places).

  • Each new position is an order of 10. So the 100’s position is 10^2, the 1,000’s position is 10^3 and so on. Since it is the deca system, we just move up by an order of 10 each time we run out of space in the current number. To get our final number, we just add up the top number multiplied by it’s spot.

  • So in this situation we have 1,000,000 + 500,000 + 70,000 + 8,000 + 400 + 80 + 3 = 1,578,483

  • The Binary system however works a little bit differently.

  • The number above is 1011111, which is the binary representation of the deca number 95. Notice the differences between the first table and this table. Instead of 10^x, it is 2^x. This makes for a much smaller transition between each number. Where the 6th place represents 1,000,000 in the deca system, it only represents 64 in the binary system.

  • We can get the number above from just adding like with the previous table. So we have 64+0+16+8+4+2+1 = 95.

Converting Binary to Decimal

  • To convert from a binary number back in to a deca number, all you have to do is what we just did above. Just add up the magnitudes with a 1 in them. In this case it would 64+0 +16+8+4+2+1 = 95. The number 1011 would be 8 + 0 + 2 + 1 = 11.

  • If you don’t want to draw a table. You can just add the magnitudes into the equation. So 1011 would be:

    • (1(2^3)) + (0(2^2)) + (1(2^1)) + (1(2^0)) => (1 * 8) + (04) + (12) + (1*1) => 8 + 0 + 2 + 1 = 11

Converting Decimal to Binary

  • Converting from a deca number to a binary number is a little tricky, but not too hard. To do this, you just subtract the largest number you can from the deca number, and add that to your binary number. It works a little like this.
    • Deca Number = 55
  • First we look for the column that will take out the most from our number without going over. In this case it is the 32. We put a one in this column and subtract this number from our original

55 – 32 = 23

  • We then repeat this step over and over until our number hits zero. Any numbers that don’t have a 1, get filled in as a 0.

23 – 16 = 7

  • Note our largest number here isn’t the 8’s spot. That would go over our 7, so we go to the next spot of 4.

7 – 4 = 3

3 – 2 = 1

1 – 1 = 0

  • So our final number comes out to be 55 = 110111.

Comment  Read more

마이크로 소프트 인턴 면접 후기

|

대망의 날이 다가왔다.

오늘 나는 마이크로소프트 Support Enginnering 인턴 직무 면접을 보았다.

면접은 약 한시간, 기술면접 30분씩 2번 본다.

면접 준비는 주로 TCP와 네트워크 위주로 질문을 준비해갔다.

첫 면접 9시 30분

마이크로소프트 팀을 이용하여 메일에 받은 링크를 통해 면접장에 입장했다.

첫 면접은 중국어 면접이였다.

자기소개를 끝 맞친 후에, 면접관은 이것 저것 내 이력서 위주로 많이 물어봤다.

  1. 이전에 일해보았던 직장에 대해서 말해주세요
  2. 어떤 직장입니까
  3. 트러블 슈팅하는데 어려운점은 무엇이었나요.
  4. 프로젝트하면서 가장 어려웠던 일이 무엇인가요.
    • 중국 또우먼으로 출장 갔던 얘기를 했다
  5. 왜 우리 직책에대해서 지원하였나요
  6. 리눅스 시스템에 관리자 모드에 관한 질문을 하였는데 이해가 잘 안되었다.
  7. python이나 C++로 개발해본적 있나요
  8. 예를 들어 시스템에 관해 주어진 task에 관해 아무것도 모르는 상태에서 일을 해야하는데, 어떻게 시작할껀가요?
  9. Customer가 갑자기 급한일이라고 일 처리해달라는데 어떻게 할 건가요?
    • Manager한테 먼저 여쭤본다.
  10. 만약 하루 안에 일을 끝을 못하고, 문제에 대한 해결이 잘 안된다면 어떻게 할 건가요?
    • 선배들이나 R&D에 에스컬레이터 한다.
  11. 클라우드 서비스에 대해 설명해보세요.

생각나는것인 이정도 였던것 같다.

제 1 기술 면접이 끝나고 질문은

  • 마이크로소프트에서 일을하면서 장점이 무엇인가요?
  • 만약 새로운 신입이 들어왔을때 매니저들은 신입의 의견을 존중해주는 편인가요??

이정도 였던 것 같다.

제 2 기술 면접에서 질문은 영어로 진행 되었다.

  1. SQL 데이터 베이스에서 두 테이블이 있는데 한테이블을 쓰려면 어떻게 해야하나요?
  2. OS 시스템 설명
    • OS 시스템에서 중요한 것이 무엇인가요
  3. Parallel processing 하는 방법
  4. Thread와 Processing에 대해 설명해보세요
  5. Http 와 Https의 차이점
  6. Ram 메모리 주소에서 프로세스로 데이터 전송을 어떻게 하는지
  7. http 프로세스에 대한 설명을 해보세요
  8. 2000명의 사람이 있고 테니스를 치는데 테니스에 이긴사람은 남고, 테니스에 진사람은 떠나야 한다. 얼마나 많은 매치가 있어야 하나

제 2 기술 면접에는 1 기술 면전과 같은 질문을 하였다.

느낌은 좋다. 나쁘지 않다. 그래도 기다려봐야지.

꼭 되서 부모님을 기쁘게 하고 싶다.

그리고 세계 최고 IT기업에서 일해보고 싶다.

합격을 한다면 매니저 면접이 남았지만, 부디 면접관들에게 좋은 인상을 주어서 합격했으면 좋겠다.

Comment  Read more

TCP와 UPT의 차이

|

TCP

일반적으로 TCP와 IP를 함께 사용하는데, IP가 데이터의 배달을 처리한다면 TCP는 패킷을 추적 및 관리

[TCP 특징]

  • 연결형 서비스로 가상 회선 방식을
  • 3-way handshaking과정을 통해 연결을 설정하고 4-way handshaking을 통해 해제
  • 흐름 제어 및 혼잡 제어.
  • 높은 신뢰성을 보장
  • UDP보다 속도가 느리다.
  • 전이중(Full-Duplex), 점대점(Point to Point) 방식.
  • TCP는 연속성보다 신뢰성있는 전송이 중요할 때에 사용하는 프로토콜

[TCP 서버 특징]

  • 서버소켓은 연결만을 담당한다.
  • 연결과정에서 반환된 클라이언트 소켓은 데이터의 송수신에 사용된다, 서비스로 가상 회선 방식을 제공한다.
  • 서버와 클라이언트는 1대1로 연결된다.
  • 스트림 전송으로 전송 데이터의 크기가 무제한이다.
  • 패킷에 대한 응답을 해야하기 때문에(시간 지연, CPU 소모) 성능이 낮다.
  • Streaming 서비스에 불리하다.(손실된 경우 재전송 요청을 하므로)

UDP(User Datagram protocol)

데이터를 데이터그램 단위로 처리하는 프로토콜

여기서 데이터그램이란 독립적인 관계를 지니는 패킷이라는 뜻으로, UDP의 동작방식을 설명하자면 다음과 같다.

  • TCP와 달리 UDP는 비연결형 프로토콜
  • 즉, 연결을 위해 할당되는 논리적인 경로가 없는데, 그렇기 때문에 각각의 패킷은 다른 경로로 전송되고, 각각의 패킷은 독립적인 관계를 지니게 되는데 이렇게 데이터를 서로 다른 경로로 독립적으로 처리하게 되고, 이러한 프로토콜을 UDP

[UDP 특징]

  • 비연결형 서비스로 데이터그램 방식
  • 정보를 주고 받을 때 정보를 보내거나 받는다는 신호절차를 거치지 않는다.
  • UDP헤더의 CheckSum 필드를 통해 최소한의 오류만 검출한다.
  • 신뢰성이 낮다
  • TCP보다 속도가 빠르다
  • UDP는 비연결형 서비스이기 때문에, 연결을 설정하고 해제하는 과정이 존재하지 않다.
  • 서로 다른 경로로 독립적으로 처리함에도 패킷에 순서를 부여하여 재조립을 하거나 흐름 제어 또는 혼잡 제어와 같은 기능도 처리하지 않기에 TCP보다 속도가 빠르며 네트워크 부하가 적다는 장점
  • 신뢰성보다는 연속성이 중요한 서비스 예를 들면 실시간 서비스(streaming)에 자주 사용

[TCP 서버 특징]

  • UDP에는 연결 자체가 없어서(connect 함수 불필요) 서버 소켓과 클라이언트 소켓의 구분이 없다.
  • 소켓 대신 IP를 기반으로 데이터를 전송
  • 서버와 클라이언트는 1대1, 1대N, N대M 등으로 연결 가능
  • 데이터그램(메세지) 단위로 전송되며 그 크기는 65535바이트로, 크기가 초과하면 잘라서 보낸다.
  • 흐름제어(flow control)가 없어서 패킷이 제대로 전송되었는지, 오류가 없는지 확인할 수 없다.
  • 파일 전송과 같은 신뢰성이 필요한 서비스보다 성능이 중요시 되는 경우에 사용된다.

TCP와 UDP 비교

Reference

https://mangkyu.tistory.com/15

Comment  Read more