1 / 15

CS342 Data Structures

CS342 Data Structures. End-of-semester Review S2002. Final Examination (open book, notes). 30-40% on low-level implementations of the operations of various data structures including stacks; queues and priority queues; lists; binary trees; sets and maps.

Download Presentation

CS342 Data Structures

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CS342 Data Structures End-of-semester Review S2002

  2. Final Examination(open book, notes) • 30-40% on low-level implementations of the operations of various data structures including stacks; queues and priority queues; lists; binary trees; sets and maps. • 60-70% on high-level abstractions (STL) and applications of various data structures mentioned above. • Must know the “template” well.

  3. Low level implementations Given a class interface such of any class or ADT: • implement member functions. • use the ADT to solve a particular problem.

  4. The STL • Must know and be able to use the frequently used member functions of string, vector, list, stack, queue, priority queue, and set ADTs to solve some simple problems. You may also be asked to describe the action of a segment of code and analyze its efficiency in terms of Big-O notation.

  5. Examples • Implement the push or pop function of a stack using dynamically allocated or static array storage. • Given nodes and pointers to nodes, implement a function or two to insert or delete a node under a specified condition. • etc.

  6. STL examples • Vector: given the following function template<typename T> void func(vector<T> &v) { if(v.size( ) >=2) { v[v.size( ) – 2] = v.back( ); v.pop_back( ): } } • What is the output of the following code? string str[ ] = {“AA”, “AB”, “AC”, “AD”, “AE”}; int strSize = sizeof(str) / sizeof(string); vector<string> v(str, str + strSize); int i; func(v); for (i = 0; i < v.size( ); i++) cout << v[i] << ‘\t’;

  7. STL examples • list: Display the list created by the following sequence of statements: intList.push_front(0); iter = intList.begin( ); for (int i = 1; i <= 4; i++) { intList.push_front(i); insert(iter, i); } • What if the arguments of insert function is replaced by (iter, *iter) ?

  8. STL examples • Stack: trace the following program and answer some questions: template<typename T> void f(stack<T> &s, stack<T> &t, int n); int main() { int arr[5] = {2, 1, 7, 4, 3}, i; stack<int> s, t; for (i = 0; i < 5; i++) s.push(arr[i]); f(s, t, 4); outputStack(t); // display content of stack t one element at a time return 0; }

  9. STL examples template<typename T> void f(stack<T> &s, stack<T> &t, const T item) { T svalue; while (!s.empty( )) { svalue = s.top( ); s.pop( ); if (svalue < item) t.push(svalue); } } • What is displayed by the outputStack( ) function?

  10. STL examples • Given the definition of postfix expression (not given here), draw the sequence of stack configuration in the evaluation of the following postfix expression: 2 3 5 * % 6 +

  11. STL examples • Queue: what is the contents of the bins and the vector after pass 2 of the radix sort for the following three digit integer? Integers to be sorted: 365 251 67 175 453 380 905 659 251 49 598 782 967

  12. STL examples • priority queue: use a priority queue object to reorder a vector of integers. What is the order of the vector v = {6, 12, 34, 15, 67, 45, 53, 3, 5} after the execution of function f( )? void f(vector<int &v) { priority_queue<int> pq; int i; for (i = 0; i < v.size( ); i++) pq.push(v[i]); i = 0; while(!pq.empty( )) { v[i] = pq.top( ); pq.pop( ); i++; } }

  13. STL examples • linked list: trace the code in function f( ): template<typename T> void f (node<T> *front) { node<T> *p = front; T value; if (front == NULL) return; while(p->next !=NULL) p = p->next; value = p->nodevalue p->nodeValue = front->nodeValue; front->nodeValue = value } • Assuming the list is front-> 7-> 2 -> 9 -> 5-> NULL, what is the new list?

  14. STL examples • Binary tree: given a binary tree of any node type, what is the order in which nodes are visited in an LRN, LNR, or NLR scan? • A complete tree with 5125 nodes, what is its depth? • Implement a function countNodes( ) which returns the number of nodes in a binary tree as a reference argument: template<typename T> void countNodes(tnode<T> *t, int & count); // pointer t points to root

  15. Other types of problems • Big-O • Recursive algorithms • Dynamic memory allocations • Graphs (if any, extra points problem)

More Related