[[TableOfContents]] = ê³„íš = * Associative array * Maps in STL --* JSON-- * Binary Search Tree * Hash Table(간략하게, Tree 위주. Associative array를 ì„¤ëª…í• ë•Œ 필요는 하므로.) = ì°¸ì—¬ìž = ||강사 || [ê¶Œì˜ê¸°] || ||<|10> 참여ìž|| [ê¹€ì •ë¯¼] || || [ì´ì§€ìˆ˜] || || [최다ì¸] || || [성훈] || || [ì´íƒœê· ] || || [ì´ì›ì¤€] || || [ìœ ìž¬ë²”] || = ë‚´ìš© = == Associative array == * In computer science, an associative array, map, symbol table, or dictionary is an abstract data type composed of a collection of (key, value) pairs, such that each possible key appears at most once in the collection. * In an associative array, the association between a key and a value is often known as a "binding", and the same word "binding" may also be used to refer to the process of creating a new association. === Operations === * Add or insert: add a new (key, value) pair to the collection, binding the new key to its new value. The arguments to this operation are the key and the value. * Reassign: replace the value in one of the (key, value) pairs that are already in the collection, binding an old key to a new value. As with an insertion, the arguments to this operation are the key and the value. * Remove or delete: remove a (key, value) pair from the collection, unbinding a given key from its value. The argument to this operation is the key. * Lookup: find the value (if any) that is bound to a given key. The argument to this operation is the key, and the value is returned from the operation. If no value is found, some associative array implementations raise an exception. === Example === attachment:key_value_img.gif ==== C++ ==== {{{ #include<iostream> #include<string> #include<map> using namespace std; void printCarInfo(map <string,string> &carinfo){ cout<<"----------------------------------------------"<<endl; map <string, string>::iterator it1; for(it1 = carinfo.begin(); it1 != carinfo.end(); it1++){ cout<<it1->first<<" : "<<it1->second<<endl; } } int main(void){ map <string, string> carinfo; carinfo.insert(map<string, string>::value_type("itemType", "auto")); carinfo.insert(make_pair("subtype", "4WD")); carinfo["make"] = "Jeep"; carinfo["year"] = "1998"; carinfo["color"] = "green"; //Insert Key-Value Pair printCarInfo(carinfo); map <string, string>::iterator FindIter = carinfo.find("year"); if(FindIter != carinfo.end()){ FindIter->second = "2002"; } //Lookup & Reassign printCarInfo(carinfo); carinfo["year"] = "2013"; //Reassign printCarInfo(carinfo); carinfo.erase("year"); //delete printCarInfo(carinfo); } }}} attachment:result.PNG === Implementation === * Hash Table * Binary Search Tree == Binary Search Tree == * [http://www.cs.cmu.edu/~adamchik/15-121/lectures/Trees/trees.html] === Visualization === * [https://www.cs.usfca.edu/~galles/visualization/BST.html] == Indexed Binary Search Tree == * Binary search tree * Each node has an additional field. * leftsize = number of nodes in its left subtree attachment:sample.png === Why we use indexed binary search tree? === * Index를 ì´ìš©í•´ì„œ ê°’ì„ ê²€ìƒ‰, 삽입, ì‚ì œ, ìˆ˜ì •ì´ ê°€ëŠ¥í•˜ë‹¤. * 여기서 Index는 Rank와 ê°™ì€ ê°œë…ì´ë¼ê³ ìƒê°í•˜ìž. Tree ë‚´ë¶€ì˜ Elementì˜ Inorder ìˆœì„œì˜ ìœ„ì¹˜ë¼ê³ ìƒê°í• 수 있다. * Inorder ìˆœì„œì˜ ìœ„ì¹˜? * Binary Search Treeì—서 Inorder를 ìˆ˜í–‰í• ê²½ìš°, key ê°’ì´ ì˜¤ë¦„ì°¨ìˆœìœ¼ë¡œ(í˜¹ì€ ë‚´ë¦¼ì°¨ìˆœìœ¼ë¡œ) ë…¸ë“œë“¤ì„ íƒìƒ‰í•œ 결과가 나올 것ì´ë‹¤. * 다시 ë§í•´ì„œ, Index는 Treeì— ë‚´ë¶€ì˜ Elementê°€ 몇 번째로 ìž‘ì€ì§€(í˜¹ì€ í°ì§€)를 가리키는 ê²ƒì´ ëœë‹¤. * ê¸°ì¡´ì˜ Binary Search Tree 만으로 위와 ê°™ì€ ìˆ˜í–‰ì„ í•˜ê¸° 위해서는 ëª¨ë“ ë…¸ë“œë¥¼ 살펴보는 수 ë°–ì— ì—†ë‹¤. === Operation === * Search(index) * Delete(index) * Insert(index, value) * 여기서 í•µì‹¬ì€ ì–´ë–»ê²Œ 주어진 index로 íŠ¸ë¦¬ì˜ ë…¸ë“œë¥¼ ì ‘ê·¼í•˜ëŠ”ê°€ì´ë‹¤. * if index = x.leftSize desired element is x.element * if index < x.leftSize desired element is index’th element in left subtree of x * if index > x.leftSize desired element is (index - x.leftSize-1)’th element in right subtree of x * 나머지 Delete를 어떻게 í• ê²ƒì´ëƒ, Insert를 어떻게 í• ê²ƒì´ëƒëŠ” Binary Search Tree와 같으므로 ìƒëžµ. == Hash Table == * http://sweeper.egloos.com/viewer/925740 = 후기 = = ìˆ™ì œ = * Binary Search Tree 구현 (시간 남으면 Indexedë„ êµ¬í˜„) = 참조 = * Associative array : [http://en.wikipedia.org/wiki/Associative_array] * map : [http://www.cplusplus.com/reference/map/map/] * map : [http://www.hanbit.co.kr/network/view.html?bi_id=1618] * Binary Search Tree : [http://www.cs.cmu.edu/~adamchik/15-121/lectures/Trees/trees.html] * Binary Search Tree Visualization : [https://www.cs.usfca.edu/~galles/visualization/BST.html] * Indexed Binary Search Tree : 2013ë…„ 한ìƒìš© êµìˆ˜ë‹˜ ìžë£Œêµ¬ì¡° 5-4 BinarySearchTree ppt * Hash Table : [http://sweeper.egloos.com/viewer/925740] ---- [새싹êµì‹¤/2014], [새싹êµì‹¤/2014/다빈치ì¸ìž¬ë°˜]