MJay

Cracking the code interview - 4 본문

Programming/Cracking the Code interview

Cracking the code interview - 4

MJSon 2017. 12. 8. 14:50
Edit

Cracking the code interview - 4

Data Structures

Hash Tables

While not all problems can be solved with hash tables, a shocking number of interview prob-lems can be Before your interview, make sure to practice both using and implementing hash tables

1.public HashMap<Integer, Student> buildMap(Student[] students) {
2.HashMap<Integer, Student> map = new HashMap<Integer, Student>();
3.for (Student s : students) map.put(s.getId(), s);
4.return map;
5. }

ArrayList (Dynamically Resizing Array):

still providing O(1) access A typical implementation is that when a vector is full, the array doubles in size Each doubling takes O(n) time, but happens so rarely that its amortized time is still O(1)

이거 보류해야겠따 취업할꺼 아니라서

재미있는것만 정리를 해야겠습니다.

개인적으로 자료구조는 하나씩 공부해봐야겠다

오늘은 Hash Table만 공부해봐야겠다

Python에서 의 Hash Table이 Dictionary이라고 한다.

Java에서는

1.public HashMap<Integer, Student> buildMap(Student[] students){
2. HashMap<Integer, Student> map = new HashMap<Integer, Student>();
3. for (Student s : studnets) map.put(s.getId(), s);
4. return map;
5.}
%23%23%20Cracking%20the%20code%20interview%20-%204%0A@%28Cracking%20the%20Code%20interview%29%5Btistory%5D%0A%0AData%20Structures%0A%0A**Hash%20Tables**%0A%0AWhile%20not%20all%20problems%20can%20be%20solved%20with%20hash%20tables%2C%20a%20shocking%20number%20of%20interview%20prob-lems%20can%20be%20%20%20%20Before%20your%20interview%2C%20make%20sure%20to%20practice%20both%20using%20and%20implementing%20hash%20tables%20%0A%0A%60%60%60java%0Apublic%20HashMap%3CInteger%2C%20Student%3E%20buildMap%28Student%5B%5D%20students%29%20%7B%0AHashMap%3CInteger%2C%20Student%3E%20map%20%3D%20new%20HashMap%3CInteger%2C%20Student%3E%28%29%3B%0Afor%20%28Student%20s%20%3A%20students%29%20map.put%28s.getId%28%29%2C%20s%29%3B%0Areturn%20map%3B%0A%20%7D%0A%60%60%60%0A%0A**ArrayList%20%28Dynamically%20Resizing%20Array%29%3A**%0A%0A%0Astill%20providing%20O%281%29%20access%20%20%20A%20typical%20implementation%20is%20that%20when%20a%20vector%20is%20full%2C%20the%20array%20doubles%20in%20size%20%20%20Each%20doubling%20takes%20O%28n%29%20time%2C%20but%20happens%20so%20rarely%20that%20its%20amortized%20time%20is%20still%20O%281%29%20%0A%0A%0A%20%uC774%uAC70%20%uBCF4%uB958%uD574%uC57C%uACA0%uB530%20%uCDE8%uC5C5%uD560%uAEBC%20%uC544%uB2C8%uB77C%uC11C%0A%0A%uC7AC%uBBF8%uC788%uB294%uAC83%uB9CC%20%uC815%uB9AC%uB97C%20%uD574%uC57C%uACA0%uC2B5%uB2C8%uB2E4.%0A%0A%uAC1C%uC778%uC801%uC73C%uB85C%20%uC790%uB8CC%uAD6C%uC870%uB294%20%uD558%uB098%uC529%20%uACF5%uBD80%uD574%uBD10%uC57C%uACA0%uB2E4%0A%0A%uC624%uB298%uC740%20Hash%20Table%uB9CC%20%uACF5%uBD80%uD574%uBD10%uC57C%uACA0%uB2E4%0A%0A**Python%uC5D0%uC11C%20%uC758%20Hash%20Table%uC774%20Dictionary%uC774%uB77C%uACE0%20%uD55C%uB2E4.%20**%0A%0A**Java%uC5D0%uC11C%uB294**%0A%0A%60%60%60%0Apublic%20HashMap%3CInteger%2C%20Student%3E%20buildMap%28Student%5B%5D%20students%29%7B%0A%20%20%20%20HashMap%3CInteger%2C%20Student%3E%20map%20%3D%20new%20HashMap%3CInteger%2C%20Student%3E%28%29%3B%0A%20%20%20%20for%20%28Student%20s%20%3A%20studnets%29%20map.put%28s.getId%28%29%2C%20s%29%3B%0A%20%20%20%20return%20map%3B%0A%7D%0A%60%60%60