목록열기 |
오늘의 분석 보내드립니다. HTC 가 자체적인 OS 준비하고 있다는 루머와 모토롤라가 자체의 운영체제를 사들였다는 루머는 지속적으로 확인해봐야겠습니다.^^
|
| |||||||||||||||||||
목록열기 |
오늘의 분석 보내드립니다. HTC 가 자체적인 OS 준비하고 있다는 루머와 모토롤라가 자체의 운영체제를 사들였다는 루머는 지속적으로 확인해봐야겠습니다.^^
|
| |||||||||||||||||||
String array to arraylist | ||
|---|---|---|
| vani mn Greenhorn Joined: Jan 21, 2006 Posts: 1 | posted 2006년 3월 21일 화요일 오후 1:28 | |
| How to convert a string array to arraylist?? | ||
| Garrett Rowe Ranch Hand Joined: Jan 17, 2006 Posts: 1285 | posted 2006년 3월 21일 화요일 오후 2:24 | |
If the concrete implementation doesn't matter, you can use Arrays.asList() to convert your array to a List.
| ||
1. 난수(random number) 발생기(generator) 구현의 어려움 표준 C 라이브러리에는 rand()라는 함수가 있다. 물론 각각의 시스템에 따라 이 함수의 구현(implementation)은 완전하지 않을 수 있다. 그러나, 이 함수보다 더 좋은 성능을 가진 함수를 직접 만들기란 쉬운 일이 아니다!
직접 난수 발생기를 만들려고 한다면, 읽어야 할 책이 많다! r250, RANLIB, FSULTRA 등의 라이브러리가 있긴 하지만..
2. 특정 범위 내에서 난수를 발생시키고 싶은데 다음과 같이 하는 것은 (0에서 N-1까지의 수치를 리턴) 매우 서투른 방법이다
rand() % N /* POOR */
왜냐하면, 대부분의 난수 발생기에서 하위(low-order) 비트들은 그리 랜덤하지 않기 때문이다. 따라서, 다름과 같이 하는 것이 좋다.
(int)((double)rand() / ((double)RAND_MAX + 1) * N)
실수를 쓰기 싫다면, 다음과 같이 해도 좋다.
rand() / (RAND_MAX / N + 1)
두 방법 모두 RAND_MAX를 (
(어쨌든, RAND_MAX는 rand()가 리턴할 수 있는 최대 수치를 나타낸다는 것을 기억해야 한다. RAND_MAX에 다른 수치를 대입할 수는 없으며, rand()가 다른 범위의 수치를 리턴하도록 해 주는 다른 방법은 존재하지 않는다!)
만약 0과 1사이의 범위를 가지는 난수 발생기를 가지고 있다면, 그리고 0과 N-1사이의 범위를 가지는 정수 난수를 만들고 싶다면, 단순히 그 난수 발생기의 수치에 N을 곱하면 된다!
3. 프로그램을 실행시킬 때마다, rand()는 일정한 순서로 난수를 발생시킨다. 왜 그런가 srand()함수를 불러서 가상 난수 발생기에게 (pseudo-random number generator) 초기 값을 임의로 주면 된다. 이 초기값은 'seed'라고 하며, 대개는 현재 시간이나, 유저가 어떤 키를 누르기 전까지의 시간차로 지정한다. (물론 어떤 키를 누르기 전의 시간을 얻는 방법은 이식성있게 만들기가 힘들다!) (일반적으로 프로그램 내에서는 srand() 함수를 한번만 불러주어도 충분하다! rand()를 부를 때마다, srand()를 부른다면, 충분한 임의의 수치를 얻을 수 없다.)
4. 참/거짓을 나타내는 난수가 필요하다. 그래서 rand() % 2를 썼는데, 계속 0, 1, 0, 1, 0 만을 반복하더라 엉성하게 만들어진 가상 난수 발생기는 (pseudo random number generator) 하위(low-order) 비트들에 대해서는 그렇게 랜덤하지 않다. 상위(high-order) 비트를 쓰는게 좋다.
5. 그럼 도데체 일반적이거나 정규 분포를 위한 난수는 어떻게 발생시킬 수 있는가 Marsaglia씨에 의해 개발되고 Knuth씨가 추천한 방법이다.
#include double gaussrand() if (phase == 0) { V1 = 2 * U1 - 1; X = V1 * sqrt(-2 * log(S) / S); phase = 1 - phase; return X; [출처] 난수 발생의 난해함|작성자 재즈 |
자료구조에서 빅오 (Big O) 표기법이 무엇인가요
좀 자세히 설명좀 부탁드려요.
질문자 채택된 경우, 추가 답변 등록이 불가합니다.
<<>>
<<>>
| notation은 단어 의미대로 '표기법' 이라고 생각하시면 됩니다. 그러니까
Big-O notation 은 '대문자 O 표기법' Omega 는 'Ω 표기법', (Big-omega 라고 하기도 합니다) Theta는 'Θ 표기법' (역시 Big-Theta라고 합니다)
이라고 생각하시면 됩니다.
수업을 들으셨다니 O(n), O(log n) 같은 것들을 이미 보셨으리라 생각합니다. O 대신에 Ω나 Θ가 있을 수도 있죠. 이것들이 바로 그 notation들입니다.
세 가지 다 님께서 말씀하신 '알고리즘 효율'을 함수가 얼마나 빠르게 증가하는가를 나타내는 것으로 설명할 때 쓰입니다.
예를 들어 T(n) = 2n^2 + 5n + 6 이라는 함수가 있다고 합시다. n이 점점 커진다면, 5n이나 6에 비해 2n^2 가 더욱 큰 비율로 늘어나고, 결국 n이 증가할 때 T(n)이 얼마나 빠른 속도로 증가하느냐는 것을 결정하는 것은 n^2입니다. 그렇기 때문에, 이 T(n)의 효율성을 Big-O notation으로 표현할 때
O(n^2) 라고 씁니다.
컴퓨터 프로그래밍으로 생각을 해 보겠습니다. n개의 숫자가 있는 정렬되지 않은 배열이 있고, 이 중에 가장 큰 숫자를 찾는 배열을 찾는 함수를 만든다고 생각해봅시다. 정렬이 되지 않았으므로 n개의 숫자를 일일이 체크해야하겠죠? 그렇다면 이 함수의 효율성은 그 숫자 n에 의해 좌우가 되므로 (10개면 10번을 체크해야하고, 20개이면 20번을 체크해야하죠) 이 함수의 효율은 O(n)이 됩니다.
반대로 정렬이 되어있는 배열에서 제일 큰 숫자를 찾는다고 합시다. 그럼 숫자가 몇 개든 상관없이 맨 뒤에 있는 숫자를 보면 되겠죠. n=10이든 n=20이든 걸리는 시간은 똑같습니다(constant). 이럴 땐 O(n)이 아니고 O(1)이겠죠.
이런 식으로 아래와 같은 Big-O notation들이 존재합니다. 보통 정렬할 때 걸리는 시간이라던가, 검색할 때 걸리는 시간등을 나타낼 때 가장 많이 나옵니다.
Big-O notation 은 알고리즘이 얼마나 오랜 시간이 걸릴지 측정하는 데 도움이 되며, 또 같은 분류에 속하는 알고리즘들은 대충 비슷한 시간이 걸릴 것이라는 암시도 해 줍니다.
Big-O, Big-Omega, 그리고 Big-Theta의 미묘한 차이에 대해 서술하려면 수학적인 정의를 내려야합니다. (위에선 쉽게 설명했는데, 정확한 정의를 내리면 조금 복잡해집니다)
1. Big-O Notation 정수 (integers) 또는 복소수(real numbers)를 복소수로 변환하는 함수 f, g가 있다. 만약 |f(x)| ≤ C|g(x)|, x > k 를 만족시키는 상수 C와 k가 존재할 때, f(x)는 O(g(x)) 라고 한다.
2. Big-Omega Notation 정수 (integers) 또는 복소수(real numbers)를 복소수로 변환하는 함수 f, g가 있다. 만약 |f(x)| ≥ C|g(x)|, x > k 를 만족시키는 상수 C > 0와 k가 있을 때, f(x)는 Ω(g(x)) 라고 한다.
3. Big-Theta Notation 위와 같은 상황에서 f(x) 가 동시에 O(g(x)) 이고 Ω(g(x)) 일 때 f(x)는 Θ(g(x)) 라고 한다.
다시 말하면, Big-O Notation은 upper-bound, 즉 x가 증가할 수록 f(x) 보다 항상 스케일이 큰 g(x)를 찾는 것이고, Big-Omega Notation은 x가 증가할 수록 f(x)보다 항상 스케일이 작은 g(x)를 찾는 것이죠.
예를 들어보겠습니다.
f(x) = 8x^3 + 5x^2 + 7 이라고 합시다.
이것을 O(x^2) 라고 할 수 있을까요? 아닙니다. C가 아무리 크다고 해도, x가 무한으로 커지면 8x^3이 Cx^2 보다 커질 수 있기 때문이죠. 하지만 이것을 Ω(x^2) 라고 할 수 있을까요? 예, 그렇습니다. 바로 위와 같은 이유로, x가 무한으로 커지면 C가 아무리 커도 Cx^2보다 커질 수가 있기 때문이죠. 하지만 O(x^2)는 아니기 때문에 Θ(x^2)라고는 말할 수 없습니다.
그럼 x^3은 어떨까요? 잘 보시면 O(x^3)는 C가 8보다 큰 경우 성립하먀, Ω(x^3)는 C가 8과 같거나 작은 경우 성립한다는 것을 아실 수 있습니다. 그러므로 Θ(x^3)이라고도 할 수 있습니다.
쉽게 설명하자면, x^3을 주체(?)로 하는 함수가 f(x)의 아래와 위를 막고 있다는 얘기지요. 그러므로 x^3이 이 함수의 특성을 설명하기엔 적합한 겁니다.
이런 이유로, 알고리즘이나 함수, 또는 프로그램의 효율을 나타낼때는 Θ(Big-Theta)를 사용하는 것이 가장 강력한 힘(?)을 가지고 있다고 볼 수 있습니다.
조금 복잡한 설명이 되었지만 이 중 한 마디라도 도움이 되었으면 좋겠습니다. 덕분에 저도 복습할 기회가 되었군요. 그럼.... |
Published 10:37, 14 October 10
This week IBM announced it would be supporting Oracle's OpenJDK. At first glance it seems like "Great!"
Isn't it good that two big supporters of Java are getting behind a single open source project?
Well, in my personal opinion, no. It is bad. Bad for Java. I'll try to explain why.
The first point is that IBM are not just saying they will support OpenJDK. They are also saying that are pulling effort out of Apache Harmony. Apache Harmony is a project to build an Open Source JVM under the Apache license, rather than the GPL which is the license under which OpenJDK is available.
Harmony significantly predates OpenJDK and parts of Harmony are widely distributed in Android phones. Unfortunately there is a huge cloud over Harmony right now, and this news just made that cloud a good deal blacker. The lack of some IBM committers on the project isn't the problem. Apache encourages enough diversity that projects live on when one company pulls out.
To understand the clouds over Harmony let's first look at the legal situation here. Intellectual property, as we all know, is protected by two main models: copyright and patents. Simplifying hugely, copyright is about copying code, patents about copying ideas.
Apache Harmony was designed and built as a clean room implementation of Java. So no code was copied from any existing copyrighted JVM. But that doesn't protect against copying ideas - because even if the developers came up with the same idea independently, the patent still applies.
So how do Open Source projects protect themselves against patent issues?
The main way is to work with Open Standards that are covered by Open Specification promises or "Royalty Free" patent licenses. This is where major IP owners such as IBM and Microsoft have stated that they will not exert patent rights over either Open Source or Open Standard implementations of a particular standard.
Likewise most new standards from organizations such as OASIS are built on a Royalty Free basis, which means that all the companies that helped author the standard offer a free patent license to anyone implementing the standard.
There is a model under which Sun (and now Oracle) offers protection from patent issues: The Java Specification patent grant says that as long as you fully implement the Java specification and pass the tests that prove it - the Technology Compatibility Kit (TCK) - then you have a perpetual royalty-free license to patent rights that Oracle has over Java.
This sounds great. Not only has Sun/Oracle has made available Java under an Open Source license (GPL), but if you don't want to use GPL you can simply write another JVM that conforms to the tests and you won't be sued for patent infringement. Perfect. So what on earth are those whiners at Apache bothered about?
Unfortunately it isn't quite so simple. I hope you are following me so far. All Apache Harmony needs to do to protect against patent suits is to pass the TCK. Can Apache Harmony pass the TCK? Well, yes and no. Would it pass the TCK if the tests were run? Probably. Can the tests be run? No.
The TCK is not available to Apache in a way that allows Apache to run it. The JDK is available as Open Source, but the TCK isn't. To protect against patent issues, you have to talk to Oracle and get the TCK. And they will only give it to Apache with restrictions. In particular restrictions of a kind called Field of Use (FOU) restrictions.
Ok, this is becoming overly legal. I apologise. But I think its important to understand this story, because this really gets to the heart of how open Java is.
Open Source is not just "published code". If you take an Open Source library, then you are allowed to redistribute the code without prejudice. This is key to Apache and the Apache license. So Apache can't build in restrictions on who is allowed to take Apache code or what they can do with it. The Apache license doesn't allow it.
Unfortunately, Sun - and now Oracle - have said that they will only give the TCK to Apache if it restricts how the Harmony code can be used. Effectively what Sun/Oracle is trying to say is that Harmony code cannot be used by mobile devices (like Android). If Apache were to go along with this, it would mean shipping Apache Harmony under a different license from the Apache License. And this would no longer be Open Source.
Why not? Well a key part of the definition of Open Source is that there is no restriction on the Fields of Endeavour. In other words, if Apache agrees to the FOU restrictions that Oracle insists on, then the result would be that Harmony would not be Open Source. Naturally Apache cannot agree to that.
Let's recap. Anyone can create an Open Source JVM, but they cannot get patent protection unless they agree to Oracle's FOU restrictions, at which point it is no longer Open Source. Therefore no-one but Oracle can create an Open Source JVM without fear of being sued.
Ok, this all sounds highly legalistic and possibly quite theoretical so far. That was until Oracle sued Google over patents breached by Android phones running code from Harmony. The gloves are off. And the real result of this is that the only Open Source JDK that you can rely on having a patent grant is the OpenJDK. And if I modify OpenJDK then I am at the mercy of Oracle to grant me a TCK license.
Unfortunately this is simply bad for Java. Java as a language is threatened by many other new and old languages. For many users its simply a commodity runtime that they will use as long as it is commonly available. And knowing there are Open Source implementations that they can use is part of that decision. Knowing that there is effectively only one Open Source project that is free from Oracle's patent claims will affect the perception and the reality of Java's openness. And for many people the fact that this is under the GPL is an issue. You can see why IBM joined OpenJDK: Oracle has Apache Harmony in a tight place.
If you want to know more - as well as hearing the official Apache line as well as my own, then please take a look at Apache's letter to Sun when this first happened.
When this first blew up Sun was a struggling company that you could have argued needed the extra revenue Java licensing to mobile phones bought them, and which Harmony and Android threatened.
The question before us now is whether the same is true of Oracle, and whether Oracle is working in the best interests of its customers, the Java community, and the Open Source community. Do you believe that Oracle should license the TCK under an open license? And are you happy that despite the move to take Java Open Source, there really is no freedom to create Open Source implementations of the Java language.
The good news for Harmony is that Apache's diversity approach means that IBM pulling out won't harm the future of the code. The bad news is that there is one less company putting pressure on Oracle to make Java truly open.
Paul Fremantle is CTO of WSO2, where he works on Open Source projects in Apache, including the Apache Synapse and Incubator projects. He has contributed to Apache since the first Apache SOAP project. While at IBM, he was instrumental in starting up the Apache WSIF and Apache Woden projects, as well as being heavily involved in the AxisC/C++ initiative, where he led IBM's involvement. Publications include co-authoring "Building Web Services in Java, 2nd Edition", articles on Web Services and SOA, and a redbook - "The XML Files: Using XML and XSL in WebSphere".
Paul will at ApacheCon 1-5 November 2010.