# Exam study sheet for CS2711. List of topics

Save this PDF as:

Size: px
Start display at page:

## Transcription

1 Exam study sheet for CS2711 Here is the list of topics you need to know for the final exam. For each data structure listed below, make sure you can do the following: 1. Give an example of this data structure (e.g., draw a binary search tree on 5 nodes). 2. Know the basic properties of data structures (e.g., that a heap has height log n) and be able to prove them (e.g. by induction). 3. Know which basic operations the data structure supports and be able to show them on an example (e.g., insertion into an AVL tree). 4. Know what is the time complexity of its basic operations and how they compare between different structures (e.g., searching in an AVL tree vs. searching in a linked list). 5. For each algorithm, make sure you know its time complexity, can write pseudocode for it and can show its execution on an example. For the analysis of algorithms (chapter 4), you need to know time complexity and induction, and be able to solve problems similar to ones in labs and assignments. Also, have a basic understanding of amortized analysis (for splay trees and doubling array size) and probabilistic analysis (hash tables vs. skip lists). Know the formula for the Master Method and examples for it. List of topics 1. Basic data structures (chapters 3 and 6): Used to implement array list and node list, sequence, iterator ADTs: can insert/remove/update an element accessed either by its rank or after/before a given location, check size, scan through all elements. Linked list: insert takes constant time in front and back, remove constant from the front, O(n) from the back, search/i th element O(n). Implementation: node contains an element and pointer to next, list specified by the first node (can be sentinel). Doubly linked list: insert and remove in constant time both front and back, search/i th element O(n). Implementation: like single linked list, except every node also points to the previous. Array/extendable array: get i th element in constant time; insert (in the middle)/remove i th element O(n). If ordered, search O(log n). Note: doubling the size is a better way to grow an extendable array (amortized analysis). 2. Stacks and queues (chapter 5): Stack: First-In-Last-Out (LIFO). ADT: push, pop, top, size, isempty. Main ones are push (to insert an element) and pop (removes an element). Implementation: linked list or array. Applications: histories, stack of recursive calls, spans, parentheses/tag matching, arithmetic expression evaluation. Queue: First-In-First-Out (FIFO). ADT: queue, dequeue, front, size, isempty. Implementation: linked list or array. Applications: waiting lists, resource access, round-robin scheduler (e.g., process switching). 3. Trees (chapter 7): In a tree every node can have several successors (called children) and a single predecessor (called parent). 1

2 Root is a node with no parent, leaf/external node has no children; a node with at least one child is called internal node. A depth of a node is the length of a path from it to the root; depth of the root is 0. A height of a tree is the max over depths of all nodes. A size of a tree is a total number of nodes. Nodes on the path to the root from a given node are its ancestors, nodes in the subtree rooted at this node (children, their children, etc) are descendants. In a binary tree every node has at most 2 children. In a proper binary tree, every node has either 2 children or is a leaf. In a complete binary tree, all levels have all possible nodes (except possibly the last level, at which the nodes are in order from the left). Note: sometimes a complete binary tree is also used to mean a tree which has all leaves on the last level (so the last level has all the possible nodes). Sometimes this is called a perfect binary tree. Properties: h log(n + 1) 1 (equality for perfect), i e + 1 (equality for proper binary tree), etc. A traversal of a tree lists all its nodes in order, with children usually explored left-to-right. In a preorder traversal, the parent node is explored before children (for example, printing a table of content) and in a post-order traversal the parent is explored after the children (for example, computing the value of an arithmetic expression or size of a directory). In a binary tree, there is also an in-order traversal, where the parent is explored after the left child, but before the right child. This can be used to print arithmetic expressions, etc. Euler tour generalizes the traversals, allowing for all three as special cases. Implementation: the tree is identified by its root. A node consists of the element, pointer to the parent, and either pointer to the sequence containing children (general tree) or two distinct leftchild and right-child pointers. Sometime (for complete binary trees) array representation (see under heaps). Many operations run in time O(height) or O(depth) for a given node; traversals are O(n). Applications: arithmetic expressions, any hierarchical structure/diagram, decision trees, file system, etc. Extended to build heaps, binary search trees, etc. 4. Heaps (chapter 8): Priority queue: Elements can be removed in order of priority. ADT: removemin and min; also size, insert, isempty. Heap: Implements priority queue ADT. A complete binary tree (last row from left possibly unfinished), with a heap property: every node element is no greater than then those of its children. Thus, the root always contains the smallest element. A heap is implemented using arrays. The root is at 1, and for every node i, its children are at cells 2i and 2i + 1. To insert an element into the heap, insert at the last cell of the array, and keep swapping up the chain of ancestors (upheap) until the heap property is maintained. To remove the min element, remove the root, place the element in the last cell into the root, and keep swapping with the smaller of the two children until heap property is maintaned (downheap). Both are O(log n) time. To build a heap in linear time, combine nodes in the second half of the array first in size 1 heaps, then size 3 with the layer above, etc, every time restoring the heap property. Applications: priority queue, heapsort (build a heap, then do n removemin operations: O(n log n) running time). 5. Maps, dictionaries, Hash tables, Skip lists (chapter 9): Map is a collection of elements, where elements could be looked up by a unique key. ADT: get(k), put(k, v), as well as size, isempty, remove(k), keyset(), values(), entryset(). Maps can 2

3 be ordered (by the keys). A dictionary is similar to a map, except the key is not required to be unique, so put(k, v) does not need to return the entry with a previous occurrence of k, and there is a getall(k). A hash table consists of an array, a hash function and a collision resolution strategy (out of separate chaining, or one of the open addressing: linear probing, quadratic probing, double hashing). A typical hash function on integers is h(k) = ak + b mod N, where N is the size of the array. An output of a good hash function looks random ; then less likely to get a collision. May need an additional function converting keys into values appropriate for the hash function; sometimes additional function compressing values of the hash function to fit into the array. Does not usually store keys in order. Performance of the hash table depends on the input values! Worst case: O(n) to insert or find an element. However, the expected performance is constant for insert/find, provided the table is not close to being full (the load factor= n/n 1/2, for example, where n is the number of elements and N the size of the table.) Applications: implement map or dictionary ADT (common for associative arrays). Word count and similar problems. Skip list consists of a number of linked lists layered and connected. The bottom list contains all elements (in order); every list above stores a subset of the elements from the list below, with nodes pointing to their duplicates in the lists above/below (if exist). A probabilistic data structure: the insertion method uses randomness to determine the number of lists (starting from the bottom) into which to insert a given element. Expected number of lists is 2; expected total number of layers O(log n). Search for k proceeds from the top list; traverse the list to the right, when the next element is larger than k and previous was smaller, drop down to the list below following the link from the smaller element and continue moving right; if k is not in the bottom list, it is not in the structure. Expected time for the search is O(log n). Usually fast in practice. Application: implements ordered map or dictionary. 6. Search trees (chapter 10): Binary search tree (BST): preserves the order of the keys. For every node, left subtree contains only keys that are at most the key at the root of the subtree, and the right at least the key at the root of the subtree. To find a node with a given key, follow the path down, going to the left/right subtree depending whether the key is less/greater than the node. ADT: get, put, remove, size, isempty; performance depends on the depth of a node/height of a tree. Insertion: find the place where the element would have been, insert there. Deletion: if leaf, just delete, if one child, move the child in its place. Otherwise find the next node in in-order traversal (it should not have a left child), swap its value into the original node, and delete the second one. Application: implements ordered map or dictionary (in-order traversal outputs keys in increasing order). AVL tree A fairly balanced version of a binary search tree, so performance of get/put/remove is O(log n). AVL property: a balance factor (difference between heights of the two subtrees) of every node is at most 1. Store height of the subtree in each node; when inserting/deleting, may need to do rotations to rebalance a tree (check the book for the types of rotations). Application: more efficient map/dictionary than plain BST. Splay tree A BST where after each get/put/remove operation the key in question is moved to the root using rotations (for deletion/unsuccessful search, move the parent of an element deleted/parent of a node where the key would be). Not necessarily balanced, but amortized performance of m operations is O(m log n). Application: favourites lists, etc, where recent searches have high chance of repeating. 3

5 All-pairs shortest paths: on digraphs, if unweighed, transitive closure. A transitive closure graph has an edge (u, v) if original graph has a path (u, v). Transitive closure can be computed using matrix multiplication. Floyd-Warshall algorithm for all-pairs shortest paths (weighed) is dynamic programming, O(n 3 ): on each iteration look at path between any u, v using only the first k vertices in the graph. Spanning tree: a tree on all vertices using original graph s edges. If graph not connected, spanning forest. Minimum spanning trees: Kriskal s algorithm and Prim-Jarnik s algorithm. Both are greedy; Kruskal s uses union-find, goes in the order of increasing edge weight, Prim- Jarnik uses a priority queue similar to Dijkstra s, but adds vertices by smallest outgoing edge from the cloud, not the shortest path. Both run in O((m + n) log n). 9. Greedy algorithms (chapter 12-13) Sort items then go through them either picking or ignoring each; never reverse a decision. Running time usually O(n log n) where n is the number of elements (depends on data structures used, too). Often does not work or only gives an approximation; when it works, correctness proof by induction on the number of steps (i.e., S i is the solution set after considering i th element in order. ) Base case: show S opt such that S 0 S opt S 0 {1,..., n}. Induction hypothesis: assume S opt such that S i S opt S i {i + 1,..., n}. Induction step: show S opt such that S i+1 S opt S i+1 {i + 2,..., n}. (a) Element i + 1 is not in S i+1. Argue that S opt does not have it either, then S opt = S opt. (b) Element i + 1 is in S i+1. Either S opt has it (possibly in the different place then switch things around to get S opt), or S opt does not have it, then throw some element j out of S opt and put i + 1 instead for S opt; argue that your new solution is at least as good. Examples of greedy algorithms: Fractional knapsack, Kruskal s algorithm for Minimal Spanning Tree, Dijkstra s algorithm, scheduling with deadlines and profits. 10. Dynamic programming (chapter 12-13) Precompute partial solutions starting from the base cases, keep them in a table, compute the table from already precomputed cells (e.g., row by row, but can be different). Arrays can be 1,2, 3-dimensional (possibly more), depends on the problem. Running time a function of the size of the array might be not polynomial (e.g., scheduling with very large deadlines)! Examples: Scheduling, Knapsack, Longest Common Subsequence, Longest Increasing Subsequence, All Pair Shortest Path (Floyd-Warshall). Steps of design: (a) Define an array; that is, state what are the values being put in the cells, then what are the dimensions and where the value of the best solution is stored. E.g.: A(i, t) stores the profit of the best schedule for jobs from 1 to i finishing by time t, where 1 i n, and 0 t maxd i. Final answer value is A(n, maxd i ). (b) Give a recurrence to compute A from the previous { cells in the array, including initialization. A(i 1, j 1) + 1 x i = y j E.g. (longest common subsequence) A(i, j) = max{a(i 1, j), A(i, j 1)} otherwise (c) Give pseudocode to compute the array (usually we omitted it in class). (d) Explain how to recover the actual solution from the array (usually using a recursive P rintopt() procedure to retrace decisions). 11. Backtracking Used when others don t work; usually exponential time, but faster than testing all possibilities. Make a decision tree of possibilities, go through the tree recursively, if some possibilities fail, backtrack. 5

### CSE 326, Data Structures. Sample Final Exam. Problem Max Points Score 1 14 (2x7) 2 18 (3x6) 3 4 4 7 5 9 6 16 7 8 8 4 9 8 10 4 Total 92.

Name: Email ID: CSE 326, Data Structures Section: Sample Final Exam Instructions: The exam is closed book, closed notes. Unless otherwise stated, N denotes the number of elements in the data structure

### 2. (a) Explain the strassen s matrix multiplication. (b) Write deletion algorithm, of Binary search tree. [8+8]

Code No: R05220502 Set No. 1 1. (a) Describe the performance analysis in detail. (b) Show that f 1 (n)+f 2 (n) = 0(max(g 1 (n), g 2 (n)) where f 1 (n) = 0(g 1 (n)) and f 2 (n) = 0(g 2 (n)). [8+8] 2. (a)

### COT5405 Analysis of Algorithms Homework 3 Solutions

COT0 Analysis of Algorithms Homework 3 Solutions. Prove or give a counter example: (a) In the textbook, we have two routines for graph traversal - DFS(G) and BFS(G,s) - where G is a graph and s is any

### Krishna Institute of Engineering & Technology, Ghaziabad Department of Computer Application MCA-213 : DATA STRUCTURES USING C

Tutorial#1 Q 1:- Explain the terms data, elementary item, entity, primary key, domain, attribute and information? Also give examples in support of your answer? Q 2:- What is a Data Type? Differentiate

### A. V. Gerbessiotis CS Spring 2014 PS 3 Mar 24, 2014 No points

A. V. Gerbessiotis CS 610-102 Spring 2014 PS 3 Mar 24, 2014 No points Problem 1. Suppose that we insert n keys into a hash table of size m using open addressing and uniform hashing. Let p(n, m) be the

### 12 Abstract Data Types

12 Abstract Data Types 12.1 Source: Foundations of Computer Science Cengage Learning Objectives After studying this chapter, the student should be able to: Define the concept of an abstract data type (ADT).

### 6 March 2007 1. Array Implementation of Binary Trees

Heaps CSE 0 Winter 00 March 00 1 Array Implementation of Binary Trees Each node v is stored at index i defined as follows: If v is the root, i = 1 The left child of v is in position i The right child of

### Converting a Number from Decimal to Binary

Converting a Number from Decimal to Binary Convert nonnegative integer in decimal format (base 10) into equivalent binary number (base 2) Rightmost bit of x Remainder of x after division by two Recursive

### 1) The postfix expression for the infix expression A+B*(C+D)/F+D*E is ABCD+*F/DE*++

Answer the following 1) The postfix expression for the infix expression A+B*(C+D)/F+D*E is ABCD+*F/DE*++ 2) Which data structure is needed to convert infix notations to postfix notations? Stack 3) The

### DATA STRUCTURES USING C

DATA STRUCTURES USING C QUESTION BANK UNIT I 1. Define data. 2. Define Entity. 3. Define information. 4. Define Array. 5. Define data structure. 6. Give any two applications of data structures. 7. Give

### 2 Exercises and Solutions

2 Exercises and Solutions Most of the exercises below have solutions but you should try first to solve them. Each subsection with solutions is after the corresponding subsection with exercises. 2.1 Sorting

### From Last Time: Remove (Delete) Operation

CSE 32 Lecture : More on Search Trees Today s Topics: Lazy Operations Run Time Analysis of Binary Search Tree Operations Balanced Search Trees AVL Trees and Rotations Covered in Chapter of the text From

### CMSC 451: Graph Properties, DFS, BFS, etc.

CMSC 451: Graph Properties, DFS, BFS, etc. Slides By: Carl Kingsford Department of Computer Science University of Maryland, College Park Based on Chapter 3 of Algorithm Design by Kleinberg & Tardos. Graphs

### Binary Heaps * * * * * * * / / \ / \ / \ / \ / \ * * * * * * * * * * * / / \ / \ / / \ / \ * * * * * * * * * *

Binary Heaps A binary heap is another data structure. It implements a priority queue. Priority Queue has the following operations: isempty add (with priority) remove (highest priority) peek (at highest

### Theorem A graph T is a tree if, and only if, every two distinct vertices of T are joined by a unique path.

Chapter 3 Trees Section 3. Fundamental Properties of Trees Suppose your city is planning to construct a rapid rail system. They want to construct the most economical system possible that will meet the

### Home Page. Data Structures. Title Page. Page 1 of 24. Go Back. Full Screen. Close. Quit

Data Structures Page 1 of 24 A.1. Arrays (Vectors) n-element vector start address + ielementsize 0 +1 +2 +3 +4... +n-1 start address continuous memory block static, if size is known at compile time dynamic,

### Data Structure [Question Bank]

Unit I (Analysis of Algorithms) 1. What are algorithms and how they are useful? 2. Describe the factor on best algorithms depends on? 3. Differentiate: Correct & Incorrect Algorithms? 4. Write short note:

### Sorting revisited. Build the binary search tree: O(n^2) Traverse the binary tree: O(n) Total: O(n^2) + O(n) = O(n^2)

Sorting revisited How did we use a binary search tree to sort an array of elements? Tree Sort Algorithm Given: An array of elements to sort 1. Build a binary search tree out of the elements 2. Traverse

### Sample Questions Csci 1112 A. Bellaachia

Sample Questions Csci 1112 A. Bellaachia Important Series : o S( N) 1 2 N N i N(1 N) / 2 i 1 o Sum of squares: N 2 N( N 1)(2N 1) N i for large N i 1 6 o Sum of exponents: N k 1 k N i for large N and k

### Algorithms and Data Structures

Algorithm Analysis Page 1 BFH-TI: Softwareschule Schweiz Algorithm Analysis Dr. CAS SD01 Algorithm Analysis Page 2 Outline Course and Textbook Overview Analysis of Algorithm Pseudo-Code and Primitive Operations

### PES Institute of Technology-BSC QUESTION BANK

PES Institute of Technology-BSC Faculty: Mrs. R.Bharathi CS35: Data Structures Using C QUESTION BANK UNIT I -BASIC CONCEPTS 1. What is an ADT? Briefly explain the categories that classify the functions

### Binary Heap Algorithms

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

### Symbol Tables. IE 496 Lecture 13

Symbol Tables IE 496 Lecture 13 Reading for This Lecture Horowitz and Sahni, Chapter 2 Symbol Tables and Dictionaries A symbol table is a data structure for storing a list of items, each with a key and

### Binary Heaps. CSE 373 Data Structures

Binary Heaps CSE Data Structures Readings Chapter Section. Binary Heaps BST implementation of a Priority Queue Worst case (degenerate tree) FindMin, DeleteMin and Insert (k) are all O(n) Best case (completely

### Merge Sort. 2004 Goodrich, Tamassia. Merge Sort 1

Merge Sort 7 2 9 4 2 4 7 9 7 2 2 7 9 4 4 9 7 7 2 2 9 9 4 4 Merge Sort 1 Divide-and-Conquer Divide-and conquer is a general algorithm design paradigm: Divide: divide the input data S in two disjoint subsets

### Algorithms and Data Structures

Priority Queues and Heaps Page 1 - Priority Queues and Heaps Dr. Fall 2008 Priority Queues and Heaps Page 2 Outline Priority Queues Heaps Heap-Based Priority Queues Bottom-Up Heap Construction Priority

### GRAPH THEORY LECTURE 4: TREES

GRAPH THEORY LECTURE 4: TREES Abstract. 3.1 presents some standard characterizations and properties of trees. 3.2 presents several different types of trees. 3.7 develops a counting method based on a bijection

### Analysis of Algorithms I: Binary Search Trees

Analysis of Algorithms I: Binary Search Trees Xi Chen Columbia University Hash table: A data structure that maintains a subset of keys from a universe set U = {0, 1,..., p 1} and supports all three dictionary

### AS-2261 M.Sc.(First Semester) Examination-2013 Paper -fourth Subject-Data structure with algorithm

AS-2261 M.Sc.(First Semester) Examination-2013 Paper -fourth Subject-Data structure with algorithm Time: Three Hours] [Maximum Marks: 60 Note Attempts all the questions. All carry equal marks Section A

### Graph. Consider a graph, G in Fig Then the vertex V and edge E can be represented as:

Graph A graph G consist of 1. Set of vertices V (called nodes), (V = {v1, v2, v3, v4...}) and 2. Set of edges E (i.e., E {e1, e2, e3...cm} A graph can be represents as G = (V, E), where V is a finite and

### Definition. E.g. : Attempting to represent a transport link data with a tree structure:

The ADT Graph Recall the ADT binary tree: a tree structure used mainly to represent 1 to 2 relations, i.e. each item has at most two immediate successors. Limitations of tree structures: an item in a tree

### Assignment 3 (concept) Solutions

CS10b Data Structures and Algorithms Assignment 3 (concept) Solutions Due: Friday, February 18th 1. (0%) Consider the following algorithm: Algorithm Power(x, n) Input: A number x and integer n 0 Output:

### UNIVERSITI MALAYSIA SARAWAK KOTA SAMARAHAN SARAWAK PSD2023 ALGORITHM & DATA STRUCTURE

STUDENT IDENTIFICATION NO UNIVERSITI MALAYSIA SARAWAK 94300 KOTA SAMARAHAN SARAWAK FAKULTI SAINS KOMPUTER & TEKNOLOGI MAKLUMAT (Faculty of Computer Science & Information Technology) Diploma in Multimedia

### IE 680 Special Topics in Production Systems: Networks, Routing and Logistics*

IE 680 Special Topics in Production Systems: Networks, Routing and Logistics* Rakesh Nagi Department of Industrial Engineering University at Buffalo (SUNY) *Lecture notes from Network Flows by Ahuja, Magnanti

### The Union-Find Problem Kruskal s algorithm for finding an MST presented us with a problem in data-structure design. As we looked at each edge,

The Union-Find Problem Kruskal s algorithm for finding an MST presented us with a problem in data-structure design. As we looked at each edge, cheapest first, we had to determine whether its two endpoints

### CSCI Trees. Mark Redekopp David Kempe

1 CSCI 104 2-3 Trees Mark Redekopp David Kempe 2 Properties, Insertion and Removal BINARY SEARCH TREES 3 Binary Search Tree Binary search tree = binary tree where all nodes meet the property that: All

### Learning Outcomes. COMP202 Complexity of Algorithms. Binary Search Trees and Other Search Trees

Learning Outcomes COMP202 Complexity of Algorithms Binary Search Trees and Other Search Trees [See relevant sections in chapters 2 and 3 in Goodrich and Tamassia.] At the conclusion of this set of lecture

### Binary Search Trees. A Generic Tree. Binary Trees. Nodes in a binary search tree ( B-S-T) are of the form. P parent. Key. Satellite data L R

Binary Search Trees A Generic Tree Nodes in a binary search tree ( B-S-T) are of the form P parent Key A Satellite data L R B C D E F G H I J The B-S-T has a root node which is the only node whose parent

### Introduction to Algorithms Review information for Prelim 1 CS 4820, Spring 2010 Distributed Wednesday, February 24

Introduction to Algorithms Review information for Prelim 1 CS 4820, Spring 2010 Distributed Wednesday, February 24 The final exam will cover seven topics. 1. greedy algorithms 2. divide-and-conquer algorithms

### To My Parents -Laxmi and Modaiah. To My Family Members. To My Friends. To IIT Bombay. To All Hard Workers

To My Parents -Laxmi and Modaiah To My Family Members To My Friends To IIT Bombay To All Hard Workers Copyright 2010 by CareerMonk.com All rights reserved. Designed by Narasimha Karumanchi Printed in

### International Journal of Software and Web Sciences (IJSWS) www.iasir.net

International Association of Scientific Innovation and Research (IASIR) (An Association Unifying the Sciences, Engineering, and Applied Research) ISSN (Print): 2279-0063 ISSN (Online): 2279-0071 International

### CSE 5311 Homework 2 Solution

CSE 5311 Homework 2 Solution Problem 6.2-6 Show that the worst-case running time of MAX-HEAPIFY on a heap of size n is Ω(lg n). (Hint: For a heap with n nodes, give node values that cause MAX- HEAPIFY

### Algorithms and Data Structures

Algorithms and Data Structures CMPSC 465 LECTURES 20-21 Priority Queues and Binary Heaps Adam Smith S. Raskhodnikova and A. Smith. Based on slides by C. Leiserson and E. Demaine. 1 Trees Rooted Tree: collection

### Any two nodes which are connected by an edge in a graph are called adjacent node.

. iscuss following. Graph graph G consist of a non empty set V called the set of nodes (points, vertices) of the graph, a set which is the set of edges and a mapping from the set of edges to a set of pairs

### 1 2-3 Trees: The Basics

CS10: Data Structures and Object-Oriented Design (Fall 2013) November 1, 2013: 2-3 Trees: Inserting and Deleting Scribes: CS 10 Teaching Team Lecture Summary In this class, we investigated 2-3 Trees in

### Binary Search Trees CMPSC 122

Binary Search Trees CMPSC 122 Note: This notes packet has significant overlap with the first set of trees notes I do in CMPSC 360, but goes into much greater depth on turning BSTs into pseudocode than

### root node level: internal node edge leaf node CS@VT Data Structures & Algorithms 2000-2009 McQuain

inary Trees 1 A binary tree is either empty, or it consists of a node called the root together with two binary trees called the left subtree and the right subtree of the root, which are disjoint from each

### Final Exam Solutions

Introduction to Algorithms May 19, 2011 Massachusetts Institute of Technology 6.006 Spring 2011 Professors Erik Demaine, Piotr Indyk, and Manolis Kellis Final Exam Solutions Problem 1. Final Exam Solutions

### Balanced Binary Search Tree

AVL Trees / Slide 1 Balanced Binary Search Tree Worst case height of binary search tree: N-1 Insertion, deletion can be O(N) in the worst case We want a tree with small height Height of a binary tree with

### Outline BST Operations Worst case Average case Balancing AVL Red-black B-trees. Binary Search Trees. Lecturer: Georgy Gimel farb

Binary Search Trees Lecturer: Georgy Gimel farb COMPSCI 220 Algorithms and Data Structures 1 / 27 1 Properties of Binary Search Trees 2 Basic BST operations The worst-case time complexity of BST operations

### Cpt S 223. School of EECS, WSU

Priority Queues (Heaps) 1 Motivation Queues are a standard mechanism for ordering tasks on a first-come, first-served basis However, some tasks may be more important or timely than others (higher priority)

### Two General Methods to Reduce Delay and Change of Enumeration Algorithms

ISSN 1346-5597 NII Technical Report Two General Methods to Reduce Delay and Change of Enumeration Algorithms Takeaki Uno NII-2003-004E Apr.2003 Two General Methods to Reduce Delay and Change of Enumeration

### GRAPH THEORY and APPLICATIONS. Trees

GRAPH THEORY and APPLICATIONS Trees Properties Tree: a connected graph with no cycle (acyclic) Forest: a graph with no cycle Paths are trees. Star: A tree consisting of one vertex adjacent to all the others.

### Questions 1 through 25 are worth 2 points each. Choose one best answer for each.

Questions 1 through 25 are worth 2 points each. Choose one best answer for each. 1. For the singly linked list implementation of the queue, where are the enqueues and dequeues performed? c a. Enqueue in

### Balanced search trees

Lecture 8 Balanced search trees 8.1 Overview In this lecture we discuss search trees as a method for storing data in a way that supports fast insert, lookup, and delete operations. (Data structures handling

### A Functional Graph Library

A Functional Graph Library Based on Inductive Graphs and Functional Graph Algorithms by Martin Erwig Presentation by Christian Doczkal March 22 nd, 2006 Structure Motivation Inductive graph definition

### 1. The memory address of the first element of an array is called A. floor address B. foundation addressc. first address D.

1. The memory address of the first element of an array is called A. floor address B. foundation addressc. first address D. base address 2. The memory address of fifth element of an array can be calculated

### Algorithms and data structures

Algorithms and data structures This course will examine various data structures for storing and accessing information together with relationships between the items being stored, and algorithms for efficiently

### Writing programs to solve problem consists of a large. how to represent aspects of the problem for solution

Algorithm Efficiency & Sorting Algorithm efficiency Big-O notation Searching algorithms Sorting algorithms 1 Overview 2 If a given ADT (i.e. stack or queue) is attractive as part of a solution How will

### Lecture 6: Binary Search Trees CSCI 700 - Algorithms I. Andrew Rosenberg

Lecture 6: Binary Search Trees CSCI 700 - Algorithms I Andrew Rosenberg Last Time Linear Time Sorting Counting Sort Radix Sort Bucket Sort Today Binary Search Trees Data Structures Data structure is a

### CSC 143. Two important problems. Searching and Sorting. Review: Linear Search. Example. Review: Binary Search. How Efficient Is Linear Search?

CSC 43 Searching and Sorting [Chapter 9, pp. 402-432] Two important problems Search: finding something in a set of data Sorting: putting a set of data in order Both very common, very useful operations

### Sorting algorithms. Mergesort and Quicksort. Merge Sort. Partitioning Choice 1. Partitioning Choice 3. Partitioning Choice 2 2/5/2015

Sorting algorithms Mergesort and Quicksort Insertion, selection and bubble sort have quadratic worst case performance The faster comparison based algorithm? O(nlogn) Mergesort and Quicksort Merge Sort

### Trees. Tree Definitions: Let T = (V, E, r) be a tree. The size of a tree denotes the number of nodes of the tree.

Trees After lists (including stacks and queues) and hash tables, trees represent one of the most widely used data structures. On one hand trees can be used to represent objects that are recursive in nature

### Java Software Structures

INTERNATIONAL EDITION Java Software Structures Designing and Using Data Structures FOURTH EDITION John Lewis Joseph Chase This page is intentionally left blank. Java Software Structures,International Edition

### Matrix Product. Matrix-Multiply (A, B) Cost of multiplying these matrices is p q r.

Dynamic Programming A powerful paradigm for algorithm design. Often leads to elegant and efficient algorithms when greedy or diide-and-conquer don t work. DP also breaks a problem into subproblems, but

### The Selection Problem

The Selection Problem The selection problem: given an integer k and a list x 1,..., x n of n elements find the k-th smallest element in the list Example: the 3rd smallest element of the following list

### Homework 15 Solutions

PROBLEM ONE (Trees) Homework 15 Solutions 1. Recall the definition of a tree: a tree is a connected, undirected graph which has no cycles. Which of the following definitions are equivalent to this definition

### Chapter There are non-isomorphic rooted trees with four vertices. Ans: 4.

Use the following to answer questions 1-26: In the questions below fill in the blanks. Chapter 10 1. If T is a tree with 999 vertices, then T has edges. 998. 2. There are non-isomorphic trees with four

### Cpt S 223. School of EECS, WSU

The Shortest Path Problem 1 Shortest-Path Algorithms Find the shortest path from point A to point B Shortest in time, distance, cost, Numerous applications Map navigation Flight itineraries Circuit wiring

### 5. A full binary tree with n leaves contains [A] n nodes. [B] log n 2 nodes. [C] 2n 1 nodes. [D] n 2 nodes.

1. The advantage of.. is that they solve the problem if sequential storage representation. But disadvantage in that is they are sequential lists. [A] Lists [B] Linked Lists [A] Trees [A] Queues 2. The

### Data Structures and Algorithm Analysis (CSC317) Intro/Review of Data Structures Focus on dynamic sets

Data Structures and Algorithm Analysis (CSC317) Intro/Review of Data Structures Focus on dynamic sets We ve been talking a lot about efficiency in computing and run time. But thus far mostly ignoring data

### Data Structures and Algorithms Written Examination

Data Structures and Algorithms Written Examination 22 February 2013 FIRST NAME STUDENT NUMBER LAST NAME SIGNATURE Instructions for students: Write First Name, Last Name, Student Number and Signature where

### Graph Algorithms. Ananth Grama, Anshul Gupta, George Karypis, and Vipin Kumar

Graph Algorithms Ananth Grama, Anshul Gupta, George Karypis, and Vipin Kumar To accompany the text Introduction to Parallel Computing, Addison Wesley, 3. Topic Overview Definitions and Representation Minimum

### CS711008Z Algorithm Design and Analysis

CS711008Z Algorithm Design and Analysis Lecture 7 Binary heap, binomial heap, and Fibonacci heap 1 Dongbo Bu Institute of Computing Technology Chinese Academy of Sciences, Beijing, China 1 The slides were

### Dynamic programming. Doctoral course Optimization on graphs - Lecture 4.1. Giovanni Righini. January 17 th, 2013

Dynamic programming Doctoral course Optimization on graphs - Lecture.1 Giovanni Righini January 1 th, 201 Implicit enumeration Combinatorial optimization problems are in general NP-hard and we usually

### Binary Search Trees > = Binary Search Trees 1. 2004 Goodrich, Tamassia

Binary Search Trees < 6 2 > = 1 4 8 9 Binary Search Trees 1 Binary Search Trees A binary search tree is a binary tree storing keyvalue entries at its internal nodes and satisfying the following property:

### ECE 250 Data Structures and Algorithms MIDTERM EXAMINATION 2008-10-23/5:15-6:45 REC-200, EVI-350, RCH-106, HH-139

ECE 250 Data Structures and Algorithms MIDTERM EXAMINATION 2008-10-23/5:15-6:45 REC-200, EVI-350, RCH-106, HH-139 Instructions: No aides. Turn off all electronic media and store them under your desk. If

### 2.3 Scheduling jobs on identical parallel machines

2.3 Scheduling jobs on identical parallel machines There are jobs to be processed, and there are identical machines (running in parallel) to which each job may be assigned Each job = 1,,, must be processed

### Multi-Way Search Trees (B Trees)

Multi-Way Search Trees (B Trees) Multiway Search Trees An m-way search tree is a tree in which, for some integer m called the order of the tree, each node has at most m children. If n

### Trees & Binary Search Trees

CMSC 132: Object-Oriented Programming II Trees & Binary Search Trees Department of Computer Science University of Maryland, College Park Trees Trees are hierarchical data structures One-to-many relationship

### Informatique Fondamentale IMA S8

Informatique Fondamentale IMA S8 Cours 4 : graphs, problems and algorithms on graphs, (notions of) NP completeness Laure Gonnord http://laure.gonnord.org/pro/teaching/ Laure.Gonnord@polytech-lille.fr Université

### Algorithms. Theresa Migler-VonDollen CMPS 5P

Algorithms Theresa Migler-VonDollen CMPS 5P 1 / 32 Algorithms Write a Python function that accepts a list of numbers and a number, x. If x is in the list, the function returns the position in the list

### Data Structures. Level 6 C30151. www.fetac.ie. Module Descriptor

The Further Education and Training Awards Council (FETAC) was set up as a statutory body on 11 June 2001 by the Minister for Education and Science. Under the Qualifications (Education & Training) Act,

### - Easy to insert & delete in O(1) time - Don t need to estimate total memory needed. - Hard to search in less than O(n) time

Skip Lists CMSC 420 Linked Lists Benefits & Drawbacks Benefits: - Easy to insert & delete in O(1) time - Don t need to estimate total memory needed Drawbacks: - Hard to search in less than O(n) time (binary

### CompSci-61B, Data Structures Final Exam

Your Name: CompSci-61B, Data Structures Final Exam Your 8-digit Student ID: Your CS61B Class Account Login: This is a final test for mastery of the material covered in our labs, lectures, and readings.

### Heaps & Priority Queues in the C++ STL 2-3 Trees

Heaps & Priority Queues in the C++ STL 2-3 Trees CS 3 Data Structures and Algorithms Lecture Slides Friday, April 7, 2009 Glenn G. Chappell Department of Computer Science University of Alaska Fairbanks

### Lecture Notes on Spanning Trees

Lecture Notes on Spanning Trees 15-122: Principles of Imperative Computation Frank Pfenning Lecture 26 April 26, 2011 1 Introduction In this lecture we introduce graphs. Graphs provide a uniform model

### Textbook: Data Structures and Algorithm Analysis in C++ (3rd edition), by M. A. Weiss. Addison-Wesley, ISBN-10: X & ISBN-13:

SYLLABUS: Data Structures, Algorithms, and Generic Programming COP-4530/CGS-5425 Fall 2006 Mon./Wed. 3:35-4:50pm @ 301 LOVE BLDG Thu. 11:00am-12:15pm (sec. 01) and 12:30-1:45pm (sec. 02) @ 202 Carothers

### The Knapsack Problem. Decisions and State. Dynamic Programming Solution Introduction to Algorithms Recitation 19 November 23, 2011

The Knapsack Problem You find yourself in a vault chock full of valuable items. However, you only brought a knapsack of capacity S pounds, which means the knapsack will break down if you try to carry more

### Ordered Lists and Binary Trees

Data Structures and Algorithms Ordered Lists and Binary Trees Chris Brooks Department of Computer Science University of San Francisco Department of Computer Science University of San Francisco p.1/62 6-0:

### Mergesort and Quicksort

Mergesort Mergesort and Quicksort Basic plan: Divide array into two halves. Recursively sort each half. Merge two halves to make sorted whole. mergesort mergesort analysis quicksort quicksort analysis

### Lecture 1: Course overview, circuits, and formulas

Lecture 1: Course overview, circuits, and formulas Topics in Complexity Theory and Pseudorandomness (Spring 2013) Rutgers University Swastik Kopparty Scribes: John Kim, Ben Lund 1 Course Information Swastik

### 1. Sorting (assuming sorting into ascending order) a) BUBBLE SORT

DECISION 1 Revision Notes 1. Sorting (assuming sorting into ascending order) a) BUBBLE SORT Make sure you show comparisons clearly and label each pass First Pass 8 4 3 6 1 4 8 3 6 1 4 3 8 6 1 4 3 6 8 1

### Announcements. CSE332: Data Abstractions. Lecture 9: B Trees. Today. Our goal. M-ary Search Tree. M-ary Search Tree. Ruth Anderson Winter 2011

Announcements CSE2: Data Abstractions Project 2 posted! Partner selection due by 11pm Tues 1/25 at the latest. Homework due Friday Jan 28 st at the BEGINNING of lecture Lecture 9: B Trees Ruth Anderson

### Quiz 1 Solutions. (a) T F The height of any binary search tree with n nodes is O(log n). Explain:

Introduction to Algorithms March 9, 2011 Massachusetts Institute of Technology 6.006 Spring 2011 Professors Erik Demaine, Piotr Indyk, and Manolis Kellis Quiz 1 Solutions Problem 1. Quiz 1 Solutions True

### Memoization/Dynamic Programming. The String reconstruction problem. CS125 Lecture 5 Fall 2016

CS125 Lecture 5 Fall 2016 Memoization/Dynamic Programming Today s lecture discusses memoization, which is a method for speeding up algorithms based on recursion, by using additional memory to remember

### CS268: Geometric Algorithms Handout #5 Design and Analysis Original Handout #15 Stanford University Tuesday, 25 February 1992

CS268: Geometric Algorithms Handout #5 Design and Analysis Original Handout #15 Stanford University Tuesday, 25 February 1992 Original Lecture #6: 28 January 1991 Topics: Triangulating Simple Polygons

### Tables so far. set() get() delete() BST Average O(lg n) O(lg n) O(lg n) Worst O(n) O(n) O(n) RB Tree Average O(lg n) O(lg n) O(lg n)

Hash Tables Tables so far set() get() delete() BST Average O(lg n) O(lg n) O(lg n) Worst O(n) O(n) O(n) RB Tree Average O(lg n) O(lg n) O(lg n) Worst O(lg n) O(lg n) O(lg n) Table naïve array implementation