


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
This document compares the implementation of buffer and map using vector, stack, and linked list. It includes code snippets and complexity analysis for various operations such as insertion, deletion, and movement of cursor. It also discusses the space-time tradeoff and introduces the concept of chunklist.
Typology: Lecture notes
1 / 4
This page cannot be seen from the preview
Don't miss anything!



!!!!! Vector Stack Buffer() O(1) O(1) ~Buffer() O(1) O(1) moveCursorForward() O(1) O(1) moveCursorBackward() O(1) O(1) moveCursorToStart() O(1) O(N) moveCursorToEnd() O(1) O(N) insertCharacter() O(N) O(1) deleteCharacter() O(N) O(1) Space used 1N 2N
// for Buffer class private: struct cellT { char ch; cellT *next; }; cellT *head, *cursor; head cursor
E A A B^ C C D
Use of dummy cell for linked list Add "dummy cell" to front of list
E A A B^ C C D ? dummy cell Linked list insert/delete void Buffer::insertCharacter(char ch) { cellT *cp = new cellT; cp->ch = ch; cp->next = cursor->next; cursor->next = cp; cursor = cp; } void Buffer::deleteCharacter() { if (cursor->next != NULL) { cellT *old = cursor->next; cursor->next = old->next; delete old; } } Linked list cursor movement void Buffer::moveCursorToBegin() { cursor = head; } void Buffer::moveCursorForward() { if (cursor->next != NULL) cursor = cursor->next; } void Buffer::moveCursorToEnd() { while (cursor->next != NULL) moveCursorForward(); } void Buffer::moveCursorBackward() { if (cursor != head) { cellT *cp = head; while (cp->next != cursor) cp = cp->next; cursor = cp; } Compare implementations !!!!! Vector Stack List Buffer() O(1) O(1) O(1) ~Buffer() O(1) O(1) O(N) moveCursorForward() O(1) O(1) O(1) moveCursorBackward() O(1) O(1) O(N) moveCursorToStart() O(1) O(N) O(1) moveCursorToEnd() O(1) O(N) O(N) insertCharacter() O(N) O(1) O(1) deleteCharacter() O(N) O(1) O(1) Space used 1N 2N 5N
Simple Map implementation Layer on Vector