CSCI-1200 Data Structures Test 3 Practice Problem Solutions

Size: px
Start display at page:

Download "CSCI-1200 Data Structures Test 3 Practice Problem Solutions"

Transcription

1 1 Short Answer [ /21] CSCI-1200 Data Structures Test 3 Practice Problem Solutions 1.1 TreeNode Parent Pointers [ /5] In our initial version of the ds set class, the TreeNode object had 3 member variables: the value, and pointers to the left and right sub-trees. Why did we later add a parent pointer to each TreeNode object? Write 2-3 concise and well-written sentences. We added the parent pointers to the TreeNode class so that we could implement the iterator increment and decrement operators. Finding the next or previous node in a binary search tree can require climbing up or down in the tree hierarchy, and parent pointers are a nice way to do this. (Although they do require extra maintenance work in insert & erase.) 1.2 Hash Function for Phone Numbers [ /5] In Lecture 19 we discussed a simple application for hash tables: Caller ID reverse telephone lookup to find the person s name matching the query 10-digit phone number. Why is the following function a poor choice for the hash function to map these numbers to locations in a hash table with 1000 bins? Write 2-3 concise and well written sentences. Note: The type u int64 t is a 64-bit unsigned integer. int hash_function(u_int64_t phone_number) { return phone_number / ; This function extracts the area code from the 10 digit number and stores all phone numbers with the same area code in the same bin. For a collection of phone numbers for people living in one area of the country, the data will not be uniformly distributed throughout the hash table and due to the cost of resolving these collisions we will not achieve optimal expected hash table performance. 1.3 Red-Black Trees [ /6] Fill in the following tree with the integers 1-7 to make a binary search tree. Also, color each node red or black so that the tree also fulfills the requirements of a Red-Black tree. 3 black 1 black 6 red 2 red 5 black 7 black 4 red 1

2 1.4 Improving the Performance of Inverse Word Search [ /5] In Homework 6 you tackled the problem of Inverse Word Search, creating a grid of letters that contained all required words on the input list. How might the ordering of the words on the list affect the running time of the solver? Describe a simple method to re-order the input words to achieve faster performance. Explain why your new order is better than a random order. Write 3-4 concise and well written sentences. In general it makes sense to place the longest words first, since they will fit in the fewest places and heavily constrain the layout of the other words. Once a long word is placed the smaller words can be placed around it. If a word does not fit in the current intermediate board we can abandon further search of that partial solution. Thus, the list should be sorted by word length, with the longest words first. A random order may have the longest word last, and the program could waste a lot of time investigating intermediate solutions that are impossible if the biggest word does not fit. 2 Sorting with a Set [ /15] 2.1 Implementation [ /12] Write a fragment of C++ code to read in n integers from cin and then output those numbers to cout in sorted order (smallest first). Your code should use the STL set container class. You may not use arrays, vectors, lists, or maps. You may assume there are no duplicates in the input data. std::set<int> data; int num; // read in the data, store in a set for (int i = 0; i < n; i++) { std::cin >> num; data.insert(num); // output directly from the set (will be sorted!) for (std::set<int>::iterator itr = data.begin(); itr!= data.end(); itr++) { std::cout << *itr << " "; std::cout << std::endl; 2.2 Order Notation [ /3] What is the order notation of your solution? O(n log n) 3 Width of Binary Tree [ /36] In this problem you will write 2 versions of a function to calculate the width of a binary tree; that is, the maximum number of elements that appear on any level of the tree, where a level is all elements that are the same distance from the root node. In the example below the widest level is level 3 which has 6 elements, so both versions of the function should return the value 6 for this example. 2

3 a level 0: 1 element b c level 1: 2 elements d e f level2: 3 elements g h i j k l level 3: 6 elements m n o p level 4: 4 elements q r s t u level 5: 5 elements The first version of the function should be implemented using iteration, and following a breadth-first traversal; that is, visiting all elements of a particular level of the tree before progressing to visit elements on the next level of the tree. The second version of the function should be implemented using recursion, and a depth-first traversal. Both versions need to visit every element of the tree, and will thus require O(n) time to execute (where n is the number of elements in the tree). The implementation of your functions should be efficient and not require more than O(n) time. 3.1 Order Notation for Memory Usage [ /6] For both versions of the function consider the order notation of the memory usage of the implementation. Assume the input tree has n elements, the height of the tree is h, the width of the tree (what these functions are calculating) is w, and the number of leaf elements is m. What is the maximum memory usage at any point during execution of the program? (After you complete the implementation on the next pages, revise your answers below as necessary.) The breadth-first (iterative) solution requires O(w) because the current vector will need to store the Node* s for each level, and the maximum vector length throughout execution is equal to the width. The depth-first (recursive) solution requires O(h) both to store the stack (at maximum recursion depth we will have h stack frames) and also to store the vector of counters for the number of elements found at each level. Now on to the implementation. Each version is passed a single argument, a pointer to the root node of the tree. Note: This problem does not involve STL maps, STL sets, or the ds_set class. class Node { public: Node(char c) { value=c; left=null; right=null; char value; Node* left; Node* right; ; 3.2 Implement tree width breadth first using Iteration [ /15] int tree_width_breadth_first(node *t) { int max_width = 0; // a place to store the elements on the current and next levels std::vector<node*> current, next; if (t!= NULL) current.push_back(t); while (current.size() > 0) { 3

4 if (current.size() > max_width) max_width = current.size(); // loop through the current level and construct the list of elements on the next level for (int i = 0; i < current.size(); i++) { if (current[i]->left!= NULL) next.push_back(current[i]->left); if (current[i]->right!= NULL) next.push_back(current[i]->right); // advance to next level current = next; next.clear(); return max_width; 3.3 Implement tree width depth first using Recursion [ /15] // the recursive function void tree_width_depth_first_helper(node *t, std::vector<int> &level_widths, int level) { if (t == NULL) return; // make sure the vector contains a slot for this level while (level_widths.size() <= level) level_widths.push_back(0); // increment the count for this level level_widths[level]++; // recurse on the right and left branches tree_width_depth_first_helper(t->left,level_widths,level+1); tree_width_depth_first_helper(t->right,level_widths,level+1); // the "driver function" int tree_width_depth_first(node *t) { // a vector to store the number of elements discovered at each level std::vector<int> level_widths; // calculate the level widths using recursive helper function tree_width_depth_first_helper(t,level_widths,0); // loop through and return the maximum width int max = 0; for (int i = 0; i < level_widths.size(); i++) { if (level_widths[i] > max) max = level_widths[i]; return max; 4 Mutual Best Friends [ /25] In this problem we will store and access data for best friend relationships between people. Each person (represented by an STL string) is allowed to have one best friend. You will be asked to scan through this data and output all pairs of people for whom this best friend relationship is mutual; that is, Person A s best friend is Person B, and Person B s best friend is Person A. We use a typedef to specify the type of the data structure that stores this information. Here is an example of how the data structure is constructed and initialized: typedef ***PART_1*** best_friends_type; best_friends_type best_friends; best_friends["alice"] = "henry"; best_friends["bob"] = "ed"; 4

5 best_friends["dan"] = "alice"; best_friends["ginny"] = "carol"; best_friends["ed"] = "bob"; best_friends["carol"] = "ginny"; best_friends["frank"] = "carol"; 4.1 The best friends Data Type [ /3] What is the type for the best friends data structure? Fill in the blank marked ***PART 1***. typedef std::map<std::string,std::string> best friends type 4.2 Visualizing the Data Structure [ /6] Draw a picture to represent the best friends data structure that has been constructed by the commands above. As much as possible use the conventions from lecture and lab for drawing these pictures. Please be neat when drawing the picture so we can give you full credit. alice bob carol dan ed frank ginny henry ed ginny alice bob carol carol 4.3 Output Mutual Best Friends [ /13] Now write the fragment of code to output the mutual best friends in the best friends data structure. Here is the expected output for the example presented above: mutual best friends: bob & ed carol & ginny // iterate through all people in the data structure for (best_friends_type::iterator itr = best_friends.begin(); itr!= best_friends.end(); itr++) { const std::string &f1 = itr->first; const std::string &f2 = itr->second; // to avoid duplicate output, only consider friendships where A < B alphabetically if (f1 > f2) continue; // see if the friendship is mutual best_friends_type::iterator itr2 = best_friends.find(f2); if (itr2!= best_friends.end() && itr2->second == f1) { cout << " " << f1 << " & " << f2 << endl; 4.4 Order Notation [ /3] Assuming the best friends data structure stores data for n people, what is the order notation of your code for the previous part? O(n log n) 5

6 5 Short Answer [ /18] 5.1 Red-Black Trees [ /4] Which of the following statements about Red-Black trees are true? Write the letters for all true statements in the box below. A) The number of red nodes in each level of the tree is fixed in a Red-Black tree. B) Red-Black trees ensure that the least frequently accessed elements are near the bottom of the tree. C) Red-Black trees can be used to ensure that the O(log n) expected running time of tree operations is achieved. D) Red-Black trees are theoretically powerful, but rarely used in practice. E) Red-Black trees are non-trivial to implement because a series of rotations and re-colorings are often necessary to maintain the tree properties. Statements C & E are true. 5.2 Operator Overloading [ /4] There are 3 different ways we can overload an operator in C++: as a non-member function, as a member function, and as a friend function. Which way cannot be used for the input & output stream operators (>> and <<)? Why not? Write 2-3 concise and well-written sentences. The stream operators cannot be written as member functions of a custom class. These binary operators require that a stream object be on the left argument, thus when re-written as a function call, the stream object will be the first argument. When written as a member function, the left argument is the object whose member function is called. 5.3 TreeNode Parent Pointers [ /5] In our initial version of the cs2set class, the TreeNode object had 3 member variables: the value, and pointers to the left and right sub-trees. Why did we later add a parent pointer to each TreeNode object? Write 2-3 concise and well-written sentences. We added the parent pointers to the TreeNode class so that we could implement the iterator increment and decrement operators. Finding the next or previous node in a binary search tree can require climbing up or down in the tree hierarchy, and parent pointers are a nice way to do this. (Although they do require extra maintenance work in insert & erase.) 5.4 STL Vectors vs. Sets [ /5] Both vectors and sets can be used to efficiently sort a collection of numbers (or strings, etc.) What is the expected running time to use these data structures for sorting? Describe a specific application where one data structure may be more advantageous than the other. Write 2-3 concise and well written sentences explaining these differences. 6

7 Both vectors and sets can be used to sort a collection of numbers in O(n log n) time. When using a vector, all the elements are inserted, then the STL sort algorithm is called. Because vectors are packed sequentially, there is little extra memory overhead to store the elements. On the other hand, the elements can be added one at a time into a set, and they will be incrementally sorted, which is useful for many applications. 6 Counting the NULL Left and Right Children [ /15] Write a recursive function named count_left_right_null that takes in a pointer to a TreeNode templated over type T and returns a pair of two integers that represent the total number of NULL left and right child pointers in the tree, in that order. For example, when called on the root of the tree shown on the right, the function returns the pair (5,4) because there are 5 NULL left pointers (the nodes with values a, f, k, m, and z) and 4 NULL right pointers (the nodes with values a, f, m, and z). a c g s z template <class T> class TreeNode { public: T value; TreeNode<T>* left; TreeNode<T>* right; ; f k m template <class T> pair<int,int> count_left_right_null(treenode<t> *p) { if (p == NULL) return make_pair(0,0); pair<int,int> left,right; if (p->left == NULL) left = make_pair(1,0); else left = count_left_right_null(p->left); if (p->right == NULL) right = make_pair(0,1); else right = count_left_right_null(p->right); return make_pair(left.first+right.first,left.second+right.second); 7 Binary Tree Traversal Order [ /28] In this problem we will investigate different traversal orders in which to visit and print the nodes in a tree. For each subproblem below a particular ordering is demonstrated for the tree on the right. You will first identify the common name for this traversal order (choose from the list below). Then you will write a function of the type specified (recursive or iterative) that takes in the root pointer to the tree, a TreeNode templated over type T, and visits and prints (to std::cout) the nodes of the tree in that order. The traversal orderings below are one of: 7

8 A) leaf order B) pre-order C) post-order D) breadth first E) in-order F) random order 7.1 c a s g z f k m [ /12] Common Name: D) breadth first a c s Iterative function: template <class T> void breadth_first(treenode<t> *p) { if (p == NULL) return; list<treenode<t>*> todo; todo.push_back(p); while (!todo.empty()) { TreeNode<T> *tmp = todo.front(); todo.pop_front(); if (tmp->left!= NULL) todo.push_back(tmp->left); if (tmp->right!= NULL) todo.push_back(tmp->right); cout << tmp->value << " "; f g k m z 7.2 a c f g k m s z [ /8] Common Name: E) in-order Recursive Function: template <class T> void in_order(treenode<t> *p) { if (p == NULL) return; in_order(p->left); cout << p->value << " "; in_order(p->right); 7.3 a f m k g z s c [ /8] Common Name: C) post-order Your choice: Iterative or Recursive Function: (using recursion) template <class T> void post_order(treenode<t> *p) { if (p == NULL) return; post_order(p->left); post_order(p->right); cout << p->value << " "; 8

9 8 Family Maps [ /35] In this problem we store information about families with children. In particular we will store the years in which the siblings were born and the family s last name. We want to efficiently access information about the family based on the birth years and the overall difference in these years. In fact, we want to store the families sorted by the number of years between the first born and last born child. We will use a map to define this data structure. Your first task is to deduce the specific type of the map that is used from the examples below. You will complete the following typedef: typedef ***PART_1*** map_type; And here is how we add data into the structure: map_type family_data; vector<int> smith_kids; smith_kids.push_back(1990); smith_kids.push_back(1993); smith_kids.push_back(1995); family_data.insert(make_pair(smith_kids,string("smith"))); vector<int> jones_kids; jones_kids.push_back(1989); jones_kids.push_back(1995); family_data.insert(make_pair(jones_kids,string("jones"))); vector<int> davis_kids; davis_kids.push_back(1992); family_data.insert(make_pair(davis_kids,string("davis"))); vector<int> williams_kids; williams_kids.push_back(1991); williams_kids.push_back(1992); family_data.insert(make_pair(williams_kids,string("williams"))); vector<int> miller_kids; miller_kids.push_back(1991); miller_kids.push_back(1996); family_data.insert(make_pair(miller_kids,string("miller"))); You may assume that the birth years for the children within a family will always be given in chronological order as shown above. As always, we need to make sure that the operator< ordering function for the key used in our map has been appropriately defined so that our data is sorted within the map as desired. We want the entries in our data structure to be ordered first by the difference between the birth year of the first and last born children. In the above example, the Smith family will appear after the Williams family because the Smith family spans 5 years and the Williams family spans 1 year. Families with a single child have a span of 0 years and will be listed first. When two families have the same year span, the tie is broken by looking at the birth years of the children, and the family with the earliest birth year will be listed first (looking at the second born children to break further ties, etc.). For example, the Smith family and Miller families both span 5 years, but the Smith family will be listed first because 1990 < You may assume no two families have the same number of children born in the same set of years. 9

10 8.1 The Map Type [ /4] What is the specific typedef for the map? Fill in the blank marked ***PART 1***. typedef map<vector<int>, string> map type; Note: When fully implemented with functors (see implementation of my vector sort in part 4.3), this will be: typedef map<vector<int>,string, my vector sort> map type; 8.2 Visualizing the Data Structure [ /10] Draw a picture to represent the family data data structure that has been constructed by the commands above. As much as possible use the conventions from lecture and lab for drawing these pictures. Please be neat when drawing the picture so we can give you full credit. Optional: You may also write a few concise sentences to explain your picture. A map (table) between vector<int>s and strings. The rows of the table are sorted as described earlier. The vectors have exactly as many spots as necessary to store the birth year for each child in the family. vector<int> string davis williams smith miller jones 8.3 Ordering the Map Keys [ /10] Now implement the function that will be used to order the keys. You should implement this by overloading the operator< function for the key type. Note: Technically this code must be wrapped up in a C++ functor for this example, but we haven t covered functors yet, so just write it as operator<. bool operator< (const vector<int> &a, const vector<int> &b) { int a_diff = a.back() - a.front(); int b_diff = b.back() - b.front(); if (a_diff < b_diff) return true; if (a_diff > b_diff) return false; unsigned int i = 0; while (i < a.size() && i < b.size()) { if (a[i] < b[i]) return true; if (a[i] > b[i]) return false; i++; return a.size() < b.size(); 10

11 And here s what the code looks like wrapped in a C++ function object, a functor, where the function call operator is overloaded with the ordering functionality: class my_vector_sort { public: bool operator()(const vector<int> &a, const vector<int> &b) { int a_diff = a.back() - a.front(); int b_diff = b.back() - b.front(); if (a_diff < b_diff) return true; if (a_diff > b_diff) return false; unsigned int i = 0; while (i < a.size() && i < b.size()) { if (a[i] < b[i]) return true; if (a[i] > b[i]) return false; i++; return a.size() < b.size(); ; 8.4 Searching for a Particular Family [ /8] Now assume many more families have been added to the data structure. Write a fragment of code that will efficiently search the data structure for a family with three children that were born in 1992, 1993, and If such a family exists in the database, the code should output a short message to cout with the family s last name, otherwise it should output a message stating that no such family exists. vector<int> query; query.push_back(1992); query.push_back(1993); query.push_back(1994); map_type::iterator tmp = family_data.find(query); if (tmp!= family_data.end()) { cout << "The family name is " << tmp->second << endl; else { cout << "No such family" << endl; 8.5 Order Notation [ /3] If there are f families stored in the map, and each family has at most c children, what is the running time for your code above? The running time of is O( log f c ). 11

CSCI-1200 Data Structures Fall 2018 Lecture 19 Trees, Part III

CSCI-1200 Data Structures Fall 2018 Lecture 19 Trees, Part III CSCI-1200 Data Structures Fall 2018 Lecture 19 Trees, Part III Review from Lecture 17 & 18 Overview of the ds set implementation begin, find, destroy_tree, insert In-order, pre-order, and post-order traversal;

More information

CSCI-1200 Data Structures Spring 2015 Lecture 20 Trees, Part III

CSCI-1200 Data Structures Spring 2015 Lecture 20 Trees, Part III CSCI-1200 Data Structures Spring 2015 Lecture 20 Trees, Part III Review from Lecture 18 & 19 Overview of the ds set implementation begin, find, destroy_tree, insert In-order, pre-order, and post-order

More information

CSCI-1200 Data Structures Fall 2014 Lecture 18 Trees, Part III

CSCI-1200 Data Structures Fall 2014 Lecture 18 Trees, Part III Review from Lecture 17 CSCI-1200 Data Structures Fall 2014 Lecture 18 Trees, Part III Overview of the ds set implementation begin, find, destroy_tree, insert In-order, pre-order, and post-order traversal;

More information

CSCI-1200 Data Structures Spring 2018 Lecture 18 Trees, Part III

CSCI-1200 Data Structures Spring 2018 Lecture 18 Trees, Part III CSCI-1200 Data Structures Spring 2018 Lecture 18 Trees, Part III Review from Lecture 16 & 17 Overview of the ds set implementation begin, find, destroy_tree, insert In-order, pre-order, and post-order

More information

CSCI-1200 Data Structures Fall 2018 Lecture 21 Hash Tables, part 1

CSCI-1200 Data Structures Fall 2018 Lecture 21 Hash Tables, part 1 Review from Lecture 20 CSCI-1200 Data Structures Fall 2018 Lecture 21 Hash Tables, part 1 Finishing binary search trees & the ds set class Operators as non-member functions, as member functions, and as

More information

CSCI-1200 Data Structures Fall 2017 Lecture 18 Trees, Part II

CSCI-1200 Data Structures Fall 2017 Lecture 18 Trees, Part II CSCI-1200 Data Structures Fall 2017 Lecture 18 Trees, Part II Review from Lecture 17 and Lab 9 Binary Trees, Binary Search Trees, & Balanced Trees STL set container class (like STL map, but without the

More information

CSCI-1200 Data Structures Spring 2015 Lecture 18 Trees, Part I

CSCI-1200 Data Structures Spring 2015 Lecture 18 Trees, Part I CSCI-1200 Data Structures Spring 2015 Lecture 18 Trees, Part I Review from Lectures 17 Maps containing more complicated values. Example: index mapping words to the text line numbers on which they appear.

More information

CSCI-1200 Data Structures Fall 2017 Lecture 17 Trees, Part I

CSCI-1200 Data Structures Fall 2017 Lecture 17 Trees, Part I Review from Lecture 16 CSCI-1200 Data Structures Fall 2017 Lecture 17 Trees, Part I Maps containing more complicated values. Example: index mapping words to the text line numbers on which they appear.

More information

CSCI-1200 Data Structures Spring 2018 Lecture 16 Trees, Part I

CSCI-1200 Data Structures Spring 2018 Lecture 16 Trees, Part I CSCI-1200 Data Structures Spring 2018 Lecture 16 Trees, Part I Review from Lecture 15 Maps containing more complicated values. Example: index mapping words to the text line numbers on which they appear.

More information

CSCI-1200 Data Structures Test 3 Practice Problems

CSCI-1200 Data Structures Test 3 Practice Problems CSCI-1200 Data Structures Test 3 Practice Problems Note: This packet contains practice problems from three previous exams. Your exam will contain approximately one third as many problems. 1 Upside-Down

More information

CSCI-1200 Data Structures Fall 2017 Test 3 Solutions

CSCI-1200 Data Structures Fall 2017 Test 3 Solutions CSCI-1200 Data Structures Fall 2017 Test 3 Solutions 1 Dorm Assignment Maps [ / 45 ] Louis B. Reasoner has started a new job in the RPI housing office and is tasked with re-writing their dorm assignment

More information

Final Exam. Name: Student ID: Section: Signature:

Final Exam. Name: Student ID: Section: Signature: Final Exam PIC 10B, Spring 2016 Name: Student ID: Section: Discussion 3A (2:00 2:50 with Kelly) Discussion 3B (3:00 3:50 with Andre) I attest that the work presented in this exam is my own. I have not

More information

CSCI-1200 Data Structures Fall 2015 Lecture 24 Hash Tables

CSCI-1200 Data Structures Fall 2015 Lecture 24 Hash Tables CSCI-1200 Data Structures Fall 2015 Lecture 24 Hash Tables Review from Lecture 22 & 23 STL Queues & Stacks Definition of a Prioriry Queue / Binary Heap percolate_up and percolate_down A Heap as a Vector,

More information

Final Exam Solutions PIC 10B, Spring 2016

Final Exam Solutions PIC 10B, Spring 2016 Final Exam Solutions PIC 10B, Spring 2016 Problem 1. (10 pts) Consider the Fraction class, whose partial declaration was given by 1 class Fraction { 2 public : 3 Fraction ( int num, int den ); 4... 5 int

More information

CSCI-1200 Data Structures Spring 2014 Lecture 19 Hash Tables

CSCI-1200 Data Structures Spring 2014 Lecture 19 Hash Tables CSCI-1200 Data Structures Spring 2014 Lecture 19 Hash Tables Announcements: Test 3 Information Test 3 will be held Monday, April 14th from 6-7:50pm in DCC 308 (Sections 1-5 & 7-9) and DCC 337 (Sections

More information

CSCI-1200 Data Structures Fall 2018 Lecture 22 Hash Tables, part 2 & Priority Queues, part 1

CSCI-1200 Data Structures Fall 2018 Lecture 22 Hash Tables, part 2 & Priority Queues, part 1 Review from Lecture 21 CSCI-1200 Data Structures Fall 2018 Lecture 22 Hash Tables, part 2 & Priority Queues, part 1 the single most important data structure known to mankind Hash Tables, Hash Functions,

More information

Lecture 2. Binary Trees & Implementations. Yusuf Pisan

Lecture 2. Binary Trees & Implementations. Yusuf Pisan CSS 343 Data Structures, Algorithms, and Discrete Math II Lecture 2 Binary Trees & Implementations Yusuf Pisan Overview 1. Huffman Coding and Arithmetic Expressions 2. 342 Topics a. Pointers & References

More information

Chapter 20: Binary Trees

Chapter 20: Binary Trees Chapter 20: Binary Trees 20.1 Definition and Application of Binary Trees Definition and Application of Binary Trees Binary tree: a nonlinear linked list in which each node may point to 0, 1, or two other

More information

CSCI-1200 Data Structures Fall 2017 Test 1 Solutions

CSCI-1200 Data Structures Fall 2017 Test 1 Solutions CSCI-1200 Data Structures Fall 2017 Test 1 Solutions 1 Searching for Symbols in ASCII Art [ /24] In this problem we will search a large ASCII Art canvas for matches to a target pattern. For example, given

More information

CSCI-1200 Data Structures Spring 2018 Lecture 7 Order Notation & Basic Recursion

CSCI-1200 Data Structures Spring 2018 Lecture 7 Order Notation & Basic Recursion CSCI-1200 Data Structures Spring 2018 Lecture 7 Order Notation & Basic Recursion Review from Lectures 5 & 6 Arrays and pointers, Pointer arithmetic and dereferencing, Types of memory ( automatic, static,

More information

CSCI-1200 Data Structures Test 3 Practice Problems

CSCI-1200 Data Structures Test 3 Practice Problems CSCI-1200 Data Structures Test 3 Practice Problems Note: This packet contains selected practice problems from Test 3 from three previous years. Your test will contain approximately one third as many problems

More information

CSCI-1200 Data Structures Fall 2017 Lecture 5 Pointers, Arrays, & Pointer Arithmetic

CSCI-1200 Data Structures Fall 2017 Lecture 5 Pointers, Arrays, & Pointer Arithmetic CSCI-1200 Data Structures Fall 2017 Lecture 5 Pointers, Arrays, & Pointer Arithmetic Review from Letctures 3 & 4 C++ class syntax, designing classes, classes vs. structs; Passing comparison functions to

More information

CSCI-1200 Data Structures Fall 2018 Lecture 5 Pointers, Arrays, & Pointer Arithmetic

CSCI-1200 Data Structures Fall 2018 Lecture 5 Pointers, Arrays, & Pointer Arithmetic CSCI-1200 Data Structures Fall 2018 Lecture 5 Pointers, Arrays, & Pointer Arithmetic Announcements: Test 1 Information Test 1 will be held Thursday, Sept 20th, 2018 from 6-7:50pm Students will be randomly

More information

Computer Science II Lecture 2 Strings, Vectors and Recursion

Computer Science II Lecture 2 Strings, Vectors and Recursion 1 Overview of Lecture 2 Computer Science II Lecture 2 Strings, Vectors and Recursion The following topics will be covered quickly strings vectors as smart arrays Basic recursion Mostly, these are assumed

More information

Figure 1. A breadth-first traversal.

Figure 1. A breadth-first traversal. 4.3 Tree Traversals Stepping, or iterating, through the entries of a linearly ordered list has only two obvious orders: from front to back or from back to front. There is no obvious traversal of a general

More information

CSCI-1200 Data Structures Spring 2016 Lecture 22 Priority Queues, part II (& Functors)

CSCI-1200 Data Structures Spring 2016 Lecture 22 Priority Queues, part II (& Functors) CSCI-1200 Data Structures Spring 2016 Lecture 22 Priority Queues, part II (& Functors) Review from Lecture 21 What s a Priority Queue? Definition of a Binary Heap: A binary tree where: The value at each

More information

Trees. Chapter 6. strings. 3 Both position and Enumerator are similar in concept to C++ iterators, although the details are quite different.

Trees. Chapter 6. strings. 3 Both position and Enumerator are similar in concept to C++ iterators, although the details are quite different. Chapter 6 Trees In a hash table, the items are not stored in any particular order in the table. This is fine for implementing Sets and Maps, since for those abstract data types, the only thing that matters

More information

CSCI-1200 Data Structures Spring 2018 Lecture 14 Associative Containers (Maps), Part 1 (and Problem Solving Too)

CSCI-1200 Data Structures Spring 2018 Lecture 14 Associative Containers (Maps), Part 1 (and Problem Solving Too) CSCI-1200 Data Structures Spring 2018 Lecture 14 Associative Containers (Maps), Part 1 (and Problem Solving Too) HW6 NOTE: Do not use the STL map or STL pair for HW6. (It s okay to use them for the contest.)

More information

LECTURE 11 TREE TRAVERSALS

LECTURE 11 TREE TRAVERSALS DATA STRUCTURES AND ALGORITHMS LECTURE 11 TREE TRAVERSALS IMRAN IHSAN ASSISTANT PROFESSOR AIR UNIVERSITY, ISLAMABAD BACKGROUND All the objects stored in an array or linked list can be accessed sequentially

More information

CS102 Binary Search Trees

CS102 Binary Search Trees CS102 Binary Search Trees Prof Tejada 1 To speed up insertion, removal and search, modify the idea of a Binary Tree to create a Binary Search Tree (BST) Binary Search Trees Binary Search Trees have one

More information

CSCI-1200 Data Structures Spring 2016 Lecture 7 Iterators, STL Lists & Order Notation

CSCI-1200 Data Structures Spring 2016 Lecture 7 Iterators, STL Lists & Order Notation Today CSCI-1200 Data Structures Spring 2016 Lecture 7 Iterators, STL Lists & Order Notation Another vector operation: pop back Erasing items from vectors is inefficient! Iterators and iterator operations

More information

Uses for Trees About Trees Binary Trees. Trees. Seth Long. January 31, 2010

Uses for Trees About Trees Binary Trees. Trees. Seth Long. January 31, 2010 Uses for About Binary January 31, 2010 Uses for About Binary Uses for Uses for About Basic Idea Implementing Binary Example: Expression Binary Search Uses for Uses for About Binary Uses for Storage Binary

More information

CSE 250 Final Exam. Fall 2013 Time: 3 hours. Dec 11, No electronic devices of any kind. You can open your textbook and notes

CSE 250 Final Exam. Fall 2013 Time: 3 hours. Dec 11, No electronic devices of any kind. You can open your textbook and notes CSE 250 Final Exam Fall 2013 Time: 3 hours. Dec 11, 2013 Total points: 100 14 pages Please use the space provided for each question, and the back of the page if you need to. Please do not use any extra

More information

Solution to CSE 250 Final Exam

Solution to CSE 250 Final Exam Solution to CSE 250 Final Exam Fall 2013 Time: 3 hours. December 13, 2013 Total points: 100 14 pages Please use the space provided for each question, and the back of the page if you need to. Please do

More information

Data Structures CSci 1200 Test 1 Questions

Data Structures CSci 1200 Test 1 Questions Overview Data Structures CSci 1200 Test 1 Questions Test 1 will be held Monday, February 14, 2011, 12:00-1:30pm, Darrin 308. No make-ups will be given except for emergency situations, and even then a written

More information

CSCI-1200 Data Structures Spring 2017 Lecture 5 Pointers, Arrays, Pointer Arithmetic

CSCI-1200 Data Structures Spring 2017 Lecture 5 Pointers, Arrays, Pointer Arithmetic CSCI-1200 Data Structures Spring 2017 Lecture 5 Pointers, Arrays, Pointer Arithmetic Announcements Submitty iclicker registration is still open. Even if you already registered on the iclicker website,

More information

CSCI-1200 Data Structures Fall 2017 Lecture 9 Iterators & STL Lists

CSCI-1200 Data Structures Fall 2017 Lecture 9 Iterators & STL Lists Review from Lecture 8 CSCI-1200 Data Structures Fall 2017 Lecture 9 Iterators & STL Lists Designing our own container classes Dynamically allocated memory in classes Copy constructors, assignment operators,

More information

! Tree: set of nodes and directed edges. ! Parent: source node of directed edge. ! Child: terminal node of directed edge

! Tree: set of nodes and directed edges. ! Parent: source node of directed edge. ! Child: terminal node of directed edge Trees & Heaps Week 12 Gaddis: 20 Weiss: 21.1-3 CS 5301 Fall 2018 Jill Seaman!1 Tree: non-recursive definition! Tree: set of nodes and directed edges - root: one node is distinguished as the root - Every

More information

- 1 - Handout #22S May 24, 2013 Practice Second Midterm Exam Solutions. CS106B Spring 2013

- 1 - Handout #22S May 24, 2013 Practice Second Midterm Exam Solutions. CS106B Spring 2013 CS106B Spring 2013 Handout #22S May 24, 2013 Practice Second Midterm Exam Solutions Based on handouts by Eric Roberts and Jerry Cain Problem One: Reversing a Queue One way to reverse the queue is to keep

More information

CSE100. Advanced Data Structures. Lecture 4. (Based on Paul Kube course materials)

CSE100. Advanced Data Structures. Lecture 4. (Based on Paul Kube course materials) CSE100 Advanced Data Structures Lecture 4 (Based on Paul Kube course materials) Lecture 4 Binary search trees Toward a binary search tree implementation using C++ templates Reading: Weiss Ch 4, sections

More information

COSC 2007 Data Structures II Final Exam. Part 1: multiple choice (1 mark each, total 30 marks, circle the correct answer)

COSC 2007 Data Structures II Final Exam. Part 1: multiple choice (1 mark each, total 30 marks, circle the correct answer) COSC 2007 Data Structures II Final Exam Thursday, April 13 th, 2006 This is a closed book and closed notes exam. There are total 3 parts. Please answer the questions in the provided space and use back

More information

CS 104 (Spring 2014) Final Exam 05/09/2014

CS 104 (Spring 2014) Final Exam 05/09/2014 CS 104 (Spring 2014) Final Exam 05/09/2014 G o o d L u c k Your Name, USC username, and Student ID: This exam has 8 pages and 8 questions. If yours does not, please contact us immediately. Please read

More information

CSCI-1200 Data Structures Fall 2018 Lecture 23 Priority Queues II

CSCI-1200 Data Structures Fall 2018 Lecture 23 Priority Queues II Review from Lecture 22 CSCI-1200 Data Structures Fall 2018 Lecture 23 Priority Queues II Using STL s for_each, Function Objects, a.k.a., Functors STL s unordered_set (and unordered_map) Hash functions

More information

CSCI-1200 Data Structures Fall 2017 Lecture 7 Order Notation & Basic Recursion

CSCI-1200 Data Structures Fall 2017 Lecture 7 Order Notation & Basic Recursion CSCI-1200 Data Structures Fall 2017 Lecture 7 Order Notation & Basic Recursion Announcements: Test 1 Information Test 1 will be held Monday, Sept 25th, 2017 from 6-7:50pm Students will be randomly assigned

More information

SETS AND MAPS. Chapter 9

SETS AND MAPS. Chapter 9 SETS AND MAPS Chapter 9 The set Functions Required methods: testing set membership (find) testing for an empty set (empty) determining set size (size) creating an iterator over the set (begin, end) adding

More information

Data Structures CSci 1200 Test 2 Questions

Data Structures CSci 1200 Test 2 Questions Overview Data Structures CSci 1200 Test 2 Questions Test 2 will be held Thursday, March 10, 2010, 12:00-1:30pm, Darrin 308. No make-ups will be given except for emergency situations, and even then a written

More information

CSCI Trees. Mark Redekopp David Kempe

CSCI Trees. Mark Redekopp David Kempe CSCI 104 2-3 Trees Mark Redekopp David Kempe Trees & Maps/Sets C++ STL "maps" and "sets" use binary search trees internally to store their keys (and values) that can grow or contract as needed This allows

More information

SELF-BALANCING SEARCH TREES. Chapter 11

SELF-BALANCING SEARCH TREES. Chapter 11 SELF-BALANCING SEARCH TREES Chapter 11 Tree Balance and Rotation Section 11.1 Algorithm for Rotation BTNode root = left right = data = 10 BTNode = left right = data = 20 BTNode NULL = left right = NULL

More information

Module 4: Index Structures Lecture 13: Index structure. The Lecture Contains: Index structure. Binary search tree (BST) B-tree. B+-tree.

Module 4: Index Structures Lecture 13: Index structure. The Lecture Contains: Index structure. Binary search tree (BST) B-tree. B+-tree. The Lecture Contains: Index structure Binary search tree (BST) B-tree B+-tree Order file:///c /Documents%20and%20Settings/iitkrana1/My%20Documents/Google%20Talk%20Received%20Files/ist_data/lecture13/13_1.htm[6/14/2012

More information

CSCI-1200 Data Structures Fall 2014 Lecture 8 Iterators

CSCI-1200 Data Structures Fall 2014 Lecture 8 Iterators Review from Lecture 7 CSCI-1200 Data Structures Fall 2014 Lecture 8 Iterators Designing our own container classes Dynamically allocated memory in classes Copy constructors, assignment operators, and destructors

More information

Binary Search Trees. Contents. Steven J. Zeil. July 11, Definition: Binary Search Trees The Binary Search Tree ADT...

Binary Search Trees. Contents. Steven J. Zeil. July 11, Definition: Binary Search Trees The Binary Search Tree ADT... Steven J. Zeil July 11, 2013 Contents 1 Definition: Binary Search Trees 2 1.1 The Binary Search Tree ADT.................................................... 3 2 Implementing Binary Search Trees 7 2.1 Searching

More information

Trees. CptS 223 Advanced Data Structures. Larry Holder School of Electrical Engineering and Computer Science Washington State University

Trees. CptS 223 Advanced Data Structures. Larry Holder School of Electrical Engineering and Computer Science Washington State University Trees CptS 223 Advanced Data Structures Larry Holder School of Electrical Engineering and Computer Science Washington State University 1 Overview Tree data structure Binary search trees Support O(log 2

More information

CS301 - Data Structures Glossary By

CS301 - Data Structures Glossary By CS301 - Data Structures Glossary By Abstract Data Type : A set of data values and associated operations that are precisely specified independent of any particular implementation. Also known as ADT Algorithm

More information

Computer Science II CSci 1200 Test 1 Overview and Practice

Computer Science II CSci 1200 Test 1 Overview and Practice Computer Science II CSci 1200 Test 1 Overview and Practice Overview Test 1 will be held Tuesday, February 13, 2007, 2:00-3:30pm, West Hall Auditorium. No make-ups will be given except for emergency situations,

More information

PIC10B/1 Winter 2014 Final Exam Study Guide

PIC10B/1 Winter 2014 Final Exam Study Guide PIC10B/1 Winter 2014 Final Exam Study Guide Suggested Study Order: 1. Lecture Notes (Lectures 1-24 inclusive) 2. Examples/Homework 3. Textbook The final exam will test 1. Your ability to read a program

More information

CSE 332 Autumn 2013: Midterm Exam (closed book, closed notes, no calculators)

CSE 332 Autumn 2013: Midterm Exam (closed book, closed notes, no calculators) Name: Email address: Quiz Section: CSE 332 Autumn 2013: Midterm Exam (closed book, closed notes, no calculators) Instructions: Read the directions for each question carefully before answering. We will

More information

CSCI-401 Examlet #5. Name: Class: Date: True/False Indicate whether the sentence or statement is true or false.

CSCI-401 Examlet #5. Name: Class: Date: True/False Indicate whether the sentence or statement is true or false. Name: Class: Date: CSCI-401 Examlet #5 True/False Indicate whether the sentence or statement is true or false. 1. The root node of the standard binary tree can be drawn anywhere in the tree diagram. 2.

More information

CSCI-1200 Data Structures Fall 2010 Lecture 8 Iterators

CSCI-1200 Data Structures Fall 2010 Lecture 8 Iterators CSCI-1200 Data Structures Fall 2010 Lecture 8 Iterators Review from Lecture 7 Designing our own container classes Dynamically allocated memory in classes Copy constructors, assignment operators, and destructors

More information

Basic program The following is a basic program in C++; Basic C++ Source Code Compiler Object Code Linker (with libraries) Executable

Basic program The following is a basic program in C++; Basic C++ Source Code Compiler Object Code Linker (with libraries) Executable Basic C++ Overview C++ is a version of the older C programming language. This is a language that is used for a wide variety of applications and which has a mature base of compilers and libraries. C++ is

More information

CSCI-1200 Data Structures Fall 2009 Lecture 20 Hash Tables, Part II

CSCI-1200 Data Structures Fall 2009 Lecture 20 Hash Tables, Part II Review from Lecture 19 CSCI-1200 Data Structures Fall 2009 Lecture 20 Hash Tables, Part II Operators as non-member functions, as member functions, and as friend functions. A hash table is a table implementation

More information

Trees. A tree is a directed graph with the property

Trees. A tree is a directed graph with the property 2: Trees Trees A tree is a directed graph with the property There is one node (the root) from which all other nodes can be reached by exactly one path. Seen lots of examples. Parse Trees Decision Trees

More information

Binary Trees. Examples:

Binary Trees. Examples: Binary Trees A tree is a data structure that is made of nodes and pointers, much like a linked list. The difference between them lies in how they are organized: In a linked list each node is connected

More information

TREES Lecture 10 CS2110 Spring2014

TREES Lecture 10 CS2110 Spring2014 TREES Lecture 10 CS2110 Spring2014 Readings and Homework 2 Textbook, Chapter 23, 24 Homework: A thought problem (draw pictures!) Suppose you use trees to represent student schedules. For each student there

More information

Trees, Part 1: Unbalanced Trees

Trees, Part 1: Unbalanced Trees Trees, Part 1: Unbalanced Trees The first part of this chapter takes a look at trees in general and unbalanced binary trees. The second part looks at various schemes to balance trees and/or make them more

More information

Tree: non-recursive definition. Trees, Binary Search Trees, and Heaps. Tree: recursive definition. Tree: example.

Tree: non-recursive definition. Trees, Binary Search Trees, and Heaps. Tree: recursive definition. Tree: example. Trees, Binary Search Trees, and Heaps CS 5301 Fall 2013 Jill Seaman Tree: non-recursive definition Tree: set of nodes and directed edges - root: one node is distinguished as the root - Every node (except

More information

COMP : Trees. COMP20012 Trees 219

COMP : Trees. COMP20012 Trees 219 COMP20012 3: Trees COMP20012 Trees 219 Trees Seen lots of examples. Parse Trees Decision Trees Search Trees Family Trees Hierarchical Structures Management Directories COMP20012 Trees 220 Trees have natural

More information

CSCI-1200 Data Structures Fall 2013 Lecture 9 Iterators & Lists

CSCI-1200 Data Structures Fall 2013 Lecture 9 Iterators & Lists Review from Lecture 8 CSCI-1200 Data Structures Fall 2013 Lecture 9 Iterators & Lists Explored a program to maintain a class enrollment list and an associated waiting list. Unfortunately, erasing items

More information

CMSC 341 Lecture 10 Binary Search Trees

CMSC 341 Lecture 10 Binary Search Trees CMSC 341 Lecture 10 Binary Search Trees John Park Based on slides from previous iterations of this course Review: Tree Traversals 2 Traversal Preorder, Inorder, Postorder H X M A K B E N Y L G W UMBC CMSC

More information

Computer Science Foundation Exam

Computer Science Foundation Exam Computer Science Foundation Exam December 13, 2013 Section I A COMPUTER SCIENCE NO books, notes, or calculators may be used, and you must work entirely on your own. SOLUTION Question # Max Pts Category

More information

Why Do We Need Trees?

Why Do We Need Trees? CSE 373 Lecture 6: Trees Today s agenda: Trees: Definition and terminology Traversing trees Binary search trees Inserting into and deleting from trees Covered in Chapter 4 of the text Why Do We Need Trees?

More information

Trees. (Trees) Data Structures and Programming Spring / 28

Trees. (Trees) Data Structures and Programming Spring / 28 Trees (Trees) Data Structures and Programming Spring 2018 1 / 28 Trees A tree is a collection of nodes, which can be empty (recursive definition) If not empty, a tree consists of a distinguished node r

More information

3137 Data Structures and Algorithms in C++

3137 Data Structures and Algorithms in C++ 3137 Data Structures and Algorithms in C++ Lecture 3 July 12 2006 Shlomo Hershkop 1 Announcements Homework 2 out tonight Please make sure you complete hw1 asap if you have issues, please contact me will

More information

void insert( Type const & ) void push_front( Type const & )

void insert( Type const & ) void push_front( Type const & ) 6.1 Binary Search Trees A binary search tree is a data structure that can be used for storing sorted data. We will begin by discussing an Abstract Sorted List or Sorted List ADT and then proceed to describe

More information

Outline. Preliminaries. Binary Trees Binary Search Trees. What is Tree? Implementation of Trees using C++ Tree traversals and applications

Outline. Preliminaries. Binary Trees Binary Search Trees. What is Tree? Implementation of Trees using C++ Tree traversals and applications Trees 1 Outline Preliminaries What is Tree? Implementation of Trees using C++ Tree traversals and applications Binary Trees Binary Search Trees Structure and operations Analysis 2 What is a Tree? A tree

More information

FINALTERM EXAMINATION Fall 2009 CS301- Data Structures Question No: 1 ( Marks: 1 ) - Please choose one The data of the problem is of 2GB and the hard

FINALTERM EXAMINATION Fall 2009 CS301- Data Structures Question No: 1 ( Marks: 1 ) - Please choose one The data of the problem is of 2GB and the hard FINALTERM EXAMINATION Fall 2009 CS301- Data Structures Question No: 1 The data of the problem is of 2GB and the hard disk is of 1GB capacity, to solve this problem we should Use better data structures

More information

CSCI-1200 Data Structures Fall 2017 Lecture 23 Functors & Hash Tables, part II

CSCI-1200 Data Structures Fall 2017 Lecture 23 Functors & Hash Tables, part II CSCI-1200 Data Structures Fall 2017 Lecture 23 Functors & Hash Tables, part II Review from Lecture 22 A Heap as a Vector Building a Heap Heap Sort the single most important data structure known to mankind

More information

Binary Trees. Height 1

Binary Trees. Height 1 Binary Trees Definitions A tree is a finite set of one or more nodes that shows parent-child relationship such that There is a special node called root Remaining nodes are portioned into subsets T1,T2,T3.

More information

MARKING KEY The University of British Columbia MARKING KEY Computer Science 260 Midterm #2 Examination 12:30 noon, Thursday, March 15, 2012

MARKING KEY The University of British Columbia MARKING KEY Computer Science 260 Midterm #2 Examination 12:30 noon, Thursday, March 15, 2012 MARKING KEY The University of British Columbia MARKING KEY Computer Science 260 Midterm #2 Examination 12:30 noon, Thursday, March 15, 2012 Instructor: K. S. Booth Time: 70 minutes (one hour ten minutes)

More information

CSCI-1200 Computer Science II Fall 2006 Lecture 23 C++ Inheritance and Polymorphism

CSCI-1200 Computer Science II Fall 2006 Lecture 23 C++ Inheritance and Polymorphism CSCI-1200 Computer Science II Fall 2006 Lecture 23 C++ Inheritance and Polymorphism Review from Lecture 22 Added parent pointers to the TreeNode to implement increment and decrement operations on tree

More information

CSE100 Practice Final Exam Section C Fall 2015: Dec 10 th, Problem Topic Points Possible Points Earned Grader

CSE100 Practice Final Exam Section C Fall 2015: Dec 10 th, Problem Topic Points Possible Points Earned Grader CSE100 Practice Final Exam Section C Fall 2015: Dec 10 th, 2015 Problem Topic Points Possible Points Earned Grader 1 The Basics 40 2 Application and Comparison 20 3 Run Time Analysis 20 4 C++ and Programming

More information

C++ Basics. Data Processing Course, I. Hrivnacova, IPN Orsay

C++ Basics. Data Processing Course, I. Hrivnacova, IPN Orsay C++ Basics Data Processing Course, I. Hrivnacova, IPN Orsay The First Program Comments Function main() Input and Output Namespaces Variables Fundamental Types Operators Control constructs 1 C++ Programming

More information

Review of the Lectures 21-26, 30-32

Review of the Lectures 21-26, 30-32 Review of the Lectures 21-26, 30-32 1 The Final Exam Monday 11 December, BSB 337, from 8AM to 10AM 2 Examples of Questions recursion and memoization enumeration trees, binary search trees, Huffman codes

More information

MID TERM MEGA FILE SOLVED BY VU HELPER Which one of the following statement is NOT correct.

MID TERM MEGA FILE SOLVED BY VU HELPER Which one of the following statement is NOT correct. MID TERM MEGA FILE SOLVED BY VU HELPER Which one of the following statement is NOT correct. In linked list the elements are necessarily to be contiguous In linked list the elements may locate at far positions

More information

Part I: Short Answer (12 questions, 65 points total)

Part I: Short Answer (12 questions, 65 points total) CSE 143 Sp01 Final Exam Sample Solution page 1 of 14 Part I: Short Answer (12 questions, 65 points total) Answer all of the following questions. READ EACH QUESTION CAREFULLY. Answer each question in the

More information

CS 231 Data Structures and Algorithms Fall Recursion and Binary Trees Lecture 21 October 24, Prof. Zadia Codabux

CS 231 Data Structures and Algorithms Fall Recursion and Binary Trees Lecture 21 October 24, Prof. Zadia Codabux CS 231 Data Structures and Algorithms Fall 2018 Recursion and Binary Trees Lecture 21 October 24, 2018 Prof. Zadia Codabux 1 Agenda ArrayQueue.java Recursion Binary Tree Terminologies Traversal 2 Administrative

More information

CS302 Data Structures using C++

CS302 Data Structures using C++ CS302 Data Structures using C++ Study Guide for the Final Exam Fall 2018 Revision 1.1 This document serves to help you prepare towards the final exam for the Fall 2018 semester. 1. What topics are to be

More information

Hash Tables. CS 311 Data Structures and Algorithms Lecture Slides. Wednesday, April 22, Glenn G. Chappell

Hash Tables. CS 311 Data Structures and Algorithms Lecture Slides. Wednesday, April 22, Glenn G. Chappell Hash Tables CS 311 Data Structures and Algorithms Lecture Slides Wednesday, April 22, 2009 Glenn G. Chappell Department of Computer Science University of Alaska Fairbanks CHAPPELLG@member.ams.org 2005

More information

Tutorial AVL TREES. arra[5] = {1,2,3,4,5} arrb[8] = {20,30,80,40,10,60,50,70} FIGURE 1 Equivalent Binary Search and AVL Trees. arra = {1, 2, 3, 4, 5}

Tutorial AVL TREES. arra[5] = {1,2,3,4,5} arrb[8] = {20,30,80,40,10,60,50,70} FIGURE 1 Equivalent Binary Search and AVL Trees. arra = {1, 2, 3, 4, 5} 1 Tutorial AVL TREES Binary search trees are designed for efficient access to data. In some cases, however, a binary search tree is degenerate or "almost degenerate" with most of the n elements descending

More information

8. Write an example for expression tree. [A/M 10] (A+B)*((C-D)/(E^F))

8. Write an example for expression tree. [A/M 10] (A+B)*((C-D)/(E^F)) DHANALAKSHMI COLLEGE OF ENGINEERING DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING EC6301 OBJECT ORIENTED PROGRAMMING AND DATA STRUCTURES UNIT IV NONLINEAR DATA STRUCTURES Part A 1. Define Tree [N/D 08]

More information

CSE 143. Complexity Analysis. Program Efficiency. Constant Time Statements. Big Oh notation. Analyzing Loops. Constant Time Statements (2) CSE 143 1

CSE 143. Complexity Analysis. Program Efficiency. Constant Time Statements. Big Oh notation. Analyzing Loops. Constant Time Statements (2) CSE 143 1 CSE 1 Complexity Analysis Program Efficiency [Sections 12.1-12., 12., 12.9] Count number of instructions executed by program on inputs of a given size Express run time as a function of the input size Assume

More information

4. Trees. 4.1 Preliminaries. 4.2 Binary trees. 4.3 Binary search trees. 4.4 AVL trees. 4.5 Splay trees. 4.6 B-trees. 4. Trees

4. Trees. 4.1 Preliminaries. 4.2 Binary trees. 4.3 Binary search trees. 4.4 AVL trees. 4.5 Splay trees. 4.6 B-trees. 4. Trees 4. Trees 4.1 Preliminaries 4.2 Binary trees 4.3 Binary search trees 4.4 AVL trees 4.5 Splay trees 4.6 B-trees Malek Mouhoub, CS340 Fall 2002 1 4.1 Preliminaries A Root B C D E F G Height=3 Leaves H I J

More information

Trees : Part 1. Section 4.1. Theory and Terminology. A Tree? A Tree? Theory and Terminology. Theory and Terminology

Trees : Part 1. Section 4.1. Theory and Terminology. A Tree? A Tree? Theory and Terminology. Theory and Terminology Trees : Part Section. () (2) Preorder, Postorder and Levelorder Traversals Definition: A tree is a connected graph with no cycles Consequences: Between any two vertices, there is exactly one unique path

More information

CSE 332 Winter 2015: Midterm Exam (closed book, closed notes, no calculators)

CSE 332 Winter 2015: Midterm Exam (closed book, closed notes, no calculators) _ UWNetID: Lecture Section: A CSE 332 Winter 2015: Midterm Exam (closed book, closed notes, no calculators) Instructions: Read the directions for each question carefully before answering. We will give

More information

CSCI-1200 Data Structures Spring 2018 Lecture 10 Vector Iterators & Linked Lists

CSCI-1200 Data Structures Spring 2018 Lecture 10 Vector Iterators & Linked Lists CSCI-1200 Data Structures Spring 2018 Lecture 10 Vector Iterators & Linked Lists Review from Lecture 9 Explored a program to maintain a class enrollment list and an associated waiting list. Unfortunately,

More information

Chapter 12: Indexing and Hashing. Basic Concepts

Chapter 12: Indexing and Hashing. Basic Concepts Chapter 12: Indexing and Hashing! Basic Concepts! Ordered Indices! B+-Tree Index Files! B-Tree Index Files! Static Hashing! Dynamic Hashing! Comparison of Ordered Indexing and Hashing! Index Definition

More information

CSCE 2014 Final Exam Spring Version A

CSCE 2014 Final Exam Spring Version A CSCE 2014 Final Exam Spring 2017 Version A Student Name: Student UAID: Instructions: This is a two-hour exam. Students are allowed one 8.5 by 11 page of study notes. Calculators, cell phones and computers

More information

Student number: Datenstrukturen & Algorithmen page 1

Student number: Datenstrukturen & Algorithmen page 1 Student number: Datenstrukturen & Algorithmen page 1 Problem 1. / 16 P Instructions: 1) In this problem, you have to provide solutions only. You can write them right on this sheet. 2) You may use the notation,

More information

CS106X Handout 35 Winter 2018 March 12 th, 2018 CS106X Midterm Examination

CS106X Handout 35 Winter 2018 March 12 th, 2018 CS106X Midterm Examination CS106X Handout 35 Winter 2018 March 12 th, 2018 CS106X Midterm Examination This is an open-book, open-note, closed-electronic-device exam. You needn t write #includes, and you may (and you re even encouraged

More information

BBM 201 Data structures

BBM 201 Data structures BBM 201 Data structures Lecture 11: Trees 2018-2019 Fall Content Terminology The Binary Tree The Binary Search Tree Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, 2013

More information

CSCI 104 Binary Trees / Priority Queues / Heaps. Mark Redekopp Michael Crowley

CSCI 104 Binary Trees / Priority Queues / Heaps. Mark Redekopp Michael Crowley CSCI 04 Binary Trees / Priority Queues / Heaps Mark Redekopp Michael Crowley Trees Definition: A connected, acyclic (no cycles) graph with: A root node, r, that has 0 or more subtrees Exactly one path

More information