[완료] ...

c-clef의 이미지

스도쿠 풀이 프로그램을 만들다가 ArrayList만큼 빠르면서 중간 삽입/삭제와 특정 요소 포함 확인도 빠른 리스트가 필요해서 만들었는데요. 이런 걸 뭐라고 부르나요?

File attachments: 
첨부파일 크기
Plain text icon FastIntegerList.java_.txt1.67 KB
cleol의 이미지

음...이게 뭐지요? 단순히 boolean 배열을 wrapping 해서 특정 위치의 boolean 값을 flip 하는 몇 가지 메소드를 만들어놓은것으로만 보이는데요? ArrayList<Integer> 에 해당하는 것을 만드시려던 것 아닌가요? 그런데 이거는 정해진 capacity 이상은 크기를 늘일 수도 없고, 중간 삽입, 삭제 역시 구현하지 않은 것 같구요. 그보다도 실제 정수 데이터는 저장하지도 않는 것 같군요?? 혹시 만들던 중간 소스를 올리신 거 아닌가요?

c-clef의 이미지

조건으로 '담을 수 있는 정수는 0부터 capacity - 1'가 있습니다.

cleol의 이미지

좀 더 상상을 해보니 Set 해당하는 것을 만드시려던게 아닌가 하는 생각이 듭니다. 몇번째 위치에 어떤 데이터가 저장되어 있는가에 관심있는 것이 아니라 단지 어떤 정수가 저장되어 있는지 아닌지만 관심이 있는 것 같아서요. 그런 경우시라면 hashing 을 이용하는 HashSet 또는 binary tree 를 사용하는 TreeSet 이 좋은 선택입니다. 속도는 전자가 빠르고 메모리 사용량은 후자가 적습니다. 관심있는 정수의 범위가 작다면 지금처럼 boolean 배열을 사용하시는 것이 좋겠지만 그렇지 않다면 상당한 메모리를 낭비하게됩니다.

-----------------------------------

앗, 글을 적는 사이에 이미 답글을 다셨네요 ^^;

c-clef의 이미지

정수의 범위의 크기가 9~25 정도라서 메모리 걱정은 없습니다. 그런데 HashSet에서 contains 함수는 상수 시간 소모인가요?

cleol의 이미지

넵. 상수 시간입니다.

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.