Exam study sheet for CS2711. List of topics

Size: px
Start display at page:

Download "Exam study sheet for CS2711. List of topics"

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

4 7. Sorting/divide-and-conquer (chapter 11): Divide input into portions, solve each recursively. Example: Mergesort, Quicksort. Recurrences solved by the Master Method. Mergesort: split input in half, sort each recursively, then merge. O(n log n) Quicksort: select a (random) pivot, partition into greater-than, equal and less-than pivot portions, solve each recursively. O(n 2 ) worst time, O(n log n) average, randomized. Can be done in-place. If items to sort arbitrary, O(n log n) is the lower bound: no better algorithm possible. If items are restricted (i.e., come from a small set), can do linear time: bucket sort with one bucket per type of item. More general, radix sort (where elements are tuples of items coming from a small set). Uses bucket sort as a subroutine, requires it to be a stable sort (i.e., order of items of the same time does not change with sorting on a different radix). Radix sort can be used to sort short integers, playlists, x, y, z coordinates, etc. Other sorts: selection sort and insertion sort. Time O(n 2 ). Put elements in the array (sorted in insertion sort case, unsorted in selection), selection sort does most work on removing elements, insertion on inserting. Another O(n log n) sort is HeapSort: put elements on a heap, remove one by one. Selection problem: pick k th element. Algorithm similar to QuickSort, but only recurse on a partition which contains the element. Randomized running time O(n), can be deterministic O(n). Sets/union-find: Can store a collection of elements. Union-find: can check if two elements are in the same set and merge sets. Simple implementation O(log n), can be made amortized O(log n). 8. Graphs (chapter 13): Graphs: nodes (vertices) and links (edges) connecting them. undirected; can be weights/costs on edges or vertices. Can be directed (digraph) or Representation: adjacency list (for each vertex, list of adjacent/outgoing edges), or adjacency matrix (C(i, j) is either 1 for edge from i to j, or weight of the edge, and 0 or otherwise). Adjacency lists better if there are few edges, matrices if lots of edges and need matrix operations (i.e., transitive closure). Path: sequence of vertices where edge between two subsequent ones. Cycle: path where first and last vertices the same. Simple path/cycle: no vertex repeats. Connected: path between any two vertices. Strongly connected (digraph): path between any two vertices, weakly connected: path between any two vertices in underlying undirected graph. Graph traversals: Depth First Search (DFS) go to the child first. Breadth First Search (BFS) go to the neighbour first, uses queue. Run time O(n + m). BFS solves single-source shortest path on unweighted graphs, DFS strongly connected components, both can detect cycles. Faster implementation with adjacency lists. Both give spanning trees, label edges. Topological sort: only applies to directed acyclic graphs (DAGs). List vertices in such order that if there is a path from u to v, then u is before v. Uses DFS, O(n+m). On DAGs, problems like longest-path solvable in polynomial time. Single-source shortest paths: BFS (on unweighted graphs), Dijkstra s algorthm (on digraphs with positive weights, O(n log n)), Bellman-Ford on any graphs/digraphs, O(nm). Dijkstra s algorithm is greedy, requires positive weights on edges and uses a priority queue as an auxulary data structure; start with only the start vertex, on each step take off the queue the closest vertex to the cloud and relax its edges. Also use adjacency list implementation. 4

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.

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

More information

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

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)

More information

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

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

More information

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

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

More information

Converting a Number from Decimal to Binary

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

More information

6 March 2007 1. Array Implementation of Binary Trees

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

More information

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

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

More information

From Last Time: Remove (Delete) Operation

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

More information

DATA STRUCTURES USING C

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

More information

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

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,

More information

Sample Questions Csci 1112 A. Bellaachia

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

More information

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. 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

More information

PES Institute of Technology-BSC QUESTION BANK

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

More information

GRAPH THEORY LECTURE 4: TREES

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

More information

Binary Heap Algorithms

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

More information

Binary Heaps. CSE 373 Data Structures

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

More information

Data Structure [Question Bank]

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:

More information

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. 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

More information

Analysis of Algorithms I: Binary Search Trees

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

More information

Binary Search Trees CMPSC 122

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

More information

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 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

More information

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

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

More information

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

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

More information

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

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

More information

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. 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

More information

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 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

More information

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, 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

More information

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

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

More information

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. 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

More information

Cpt S 223. School of EECS, WSU

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

More information

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

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

More information

Algorithms and Data Structures

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

More information

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

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

More information

Ordered Lists and Binary Trees

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:

More information

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.

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

More information

Cpt S 223. School of EECS, WSU

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)

More information

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 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

More information

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

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

More information

Java Software Structures

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

More information

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 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

More information

Data Structures and Algorithms Written Examination

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

More information

- 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

- 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

More information

Binary Search Trees. Data in each node. Larger than the data in its left child Smaller than the data in its right child

Binary Search Trees. Data in each node. Larger than the data in its left child Smaller than the data in its right child Binary Search Trees Data in each node Larger than the data in its left child Smaller than the data in its right child FIGURE 11-6 Arbitrary binary tree FIGURE 11-7 Binary search tree Data Structures Using

More information

Algorithms and data structures

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

More information

CS711008Z Algorithm Design and Analysis

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

More information

Data Structures. Chapter 8

Data Structures. Chapter 8 Chapter 8 Data Structures Computer has to process lots and lots of data. To systematically process those data efficiently, those data are organized as a whole, appropriate for the application, called a

More information

Lecture 1: Course overview, circuits, and formulas

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

More information

How To Create A Tree From A Tree In Runtime (For A Tree)

How To Create A Tree From A Tree In Runtime (For A Tree) 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:

More information

Dynamic Programming. Lecture 11. 11.1 Overview. 11.2 Introduction

Dynamic Programming. Lecture 11. 11.1 Overview. 11.2 Introduction Lecture 11 Dynamic Programming 11.1 Overview Dynamic Programming is a powerful technique that allows one to solve many different types of problems in time O(n 2 ) or O(n 3 ) for which a naive approach

More information

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

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,

More information

Algorithms and Data Structures

Algorithms and Data Structures Algorithms and Data Structures Part 2: Data Structures PD Dr. rer. nat. habil. Ralf-Peter Mundani Computation in Engineering (CiE) Summer Term 2016 Overview general linked lists stacks queues trees 2 2

More information

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

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

More information

TREE BASIC TERMINOLOGIES

TREE BASIC TERMINOLOGIES TREE Trees are very flexible, versatile and powerful non-liner data structure that can be used to represent data items possessing hierarchical relationship between the grand father and his children and

More information

CompSci-61B, Data Structures Final Exam

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.

More information

Data Structures. Jaehyun Park. CS 97SI Stanford University. June 29, 2015

Data Structures. Jaehyun Park. CS 97SI Stanford University. June 29, 2015 Data Structures Jaehyun Park CS 97SI Stanford University June 29, 2015 Typical Quarter at Stanford void quarter() { while(true) { // no break :( task x = GetNextTask(tasks); process(x); // new tasks may

More information

CPSC 211 Data Structures & Implementations (c) Texas A&M University [ 221] edge. parent

CPSC 211 Data Structures & Implementations (c) Texas A&M University [ 221] edge. parent CPSC 211 Data Structures & Implementations (c) Texas A&M University [ 221] Trees Important terminology: edge root node parent Some uses of trees: child leaf model arithmetic expressions and other expressions

More information

Introduction to Algorithms March 10, 2004 Massachusetts Institute of Technology Professors Erik Demaine and Shafi Goldwasser Quiz 1.

Introduction to Algorithms March 10, 2004 Massachusetts Institute of Technology Professors Erik Demaine and Shafi Goldwasser Quiz 1. Introduction to Algorithms March 10, 2004 Massachusetts Institute of Technology 6.046J/18.410J Professors Erik Demaine and Shafi Goldwasser Quiz 1 Quiz 1 Do not open this quiz booklet until you are directed

More information

Mathematics for Algorithm and System Analysis

Mathematics for Algorithm and System Analysis Mathematics for Algorithm and System Analysis for students of computer and computational science Edward A. Bender S. Gill Williamson c Edward A. Bender & S. Gill Williamson 2005. All rights reserved. Preface

More information

Chapter 14 The Binary Search Tree

Chapter 14 The Binary Search Tree Chapter 14 The Binary Search Tree In Chapter 5 we discussed the binary search algorithm, which depends on a sorted vector. Although the binary search, being in O(lg(n)), is very efficient, inserting a

More information

Data Structures and Algorithms

Data Structures and Algorithms Data Structures and Algorithms CS245-2016S-06 Binary Search Trees David Galles Department of Computer Science University of San Francisco 06-0: Ordered List ADT Operations: Insert an element in the list

More information

CS104: Data Structures and Object-Oriented Design (Fall 2013) October 24, 2013: Priority Queues Scribes: CS 104 Teaching Team

CS104: Data Structures and Object-Oriented Design (Fall 2013) October 24, 2013: Priority Queues Scribes: CS 104 Teaching Team CS104: Data Structures and Object-Oriented Design (Fall 2013) October 24, 2013: Priority Queues Scribes: CS 104 Teaching Team Lecture Summary In this lecture, we learned about the ADT Priority Queue. A

More information

Analysis of Algorithms, I

Analysis of Algorithms, I Analysis of Algorithms, I CSOR W4231.002 Eleni Drinea Computer Science Department Columbia University Thursday, February 26, 2015 Outline 1 Recap 2 Representing graphs 3 Breadth-first search (BFS) 4 Applications

More information

Data Structures Fibonacci Heaps, Amortized Analysis

Data Structures Fibonacci Heaps, Amortized Analysis Chapter 4 Data Structures Fibonacci Heaps, Amortized Analysis Algorithm Theory WS 2012/13 Fabian Kuhn Fibonacci Heaps Lacy merge variant of binomial heaps: Do not merge trees as long as possible Structure:

More information

10CS35: Data Structures Using C

10CS35: Data Structures Using C CS35: Data Structures Using C QUESTION BANK REVIEW OF STRUCTURES AND POINTERS, INTRODUCTION TO SPECIAL FEATURES OF C OBJECTIVE: Learn : Usage of structures, unions - a conventional tool for handling a

More information

Near Optimal Solutions

Near Optimal Solutions Near Optimal Solutions Many important optimization problems are lacking efficient solutions. NP-Complete problems unlikely to have polynomial time solutions. Good heuristics important for such problems.

More information

Euclidean Minimum Spanning Trees Based on Well Separated Pair Decompositions Chaojun Li. Advised by: Dave Mount. May 22, 2014

Euclidean Minimum Spanning Trees Based on Well Separated Pair Decompositions Chaojun Li. Advised by: Dave Mount. May 22, 2014 Euclidean Minimum Spanning Trees Based on Well Separated Pair Decompositions Chaojun Li Advised by: Dave Mount May 22, 2014 1 INTRODUCTION In this report we consider the implementation of an efficient

More information

A binary search tree is a binary tree with a special property called the BST-property, which is given as follows:

A binary search tree is a binary tree with a special property called the BST-property, which is given as follows: Chapter 12: Binary Search Trees A binary search tree is a binary tree with a special property called the BST-property, which is given as follows: For all nodes x and y, if y belongs to the left subtree

More information

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)

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

More information

Binary Trees and Huffman Encoding Binary Search Trees

Binary Trees and Huffman Encoding Binary Search Trees Binary Trees and Huffman Encoding Binary Search Trees Computer Science E119 Harvard Extension School Fall 2012 David G. Sullivan, Ph.D. Motivation: Maintaining a Sorted Collection of Data A data dictionary

More information

The following themes form the major topics of this chapter: The terms and concepts related to trees (Section 5.2).

The following themes form the major topics of this chapter: The terms and concepts related to trees (Section 5.2). CHAPTER 5 The Tree Data Model There are many situations in which information has a hierarchical or nested structure like that found in family trees or organization charts. The abstraction that models hierarchical

More information

MAX = 5 Current = 0 'This will declare an array with 5 elements. Inserting a Value onto the Stack (Push) -----------------------------------------

MAX = 5 Current = 0 'This will declare an array with 5 elements. Inserting a Value onto the Stack (Push) ----------------------------------------- =============================================================================================================================== DATA STRUCTURE PSEUDO-CODE EXAMPLES (c) Mubashir N. Mir - www.mubashirnabi.com

More information

Problem Set 7 Solutions

Problem Set 7 Solutions 8 8 Introduction to Algorithms May 7, 2004 Massachusetts Institute of Technology 6.046J/18.410J Professors Erik Demaine and Shafi Goldwasser Handout 25 Problem Set 7 Solutions This problem set is due in

More information

A binary search tree or BST is a binary tree that is either empty or in which the data element of each node has a key, and:

A binary search tree or BST is a binary tree that is either empty or in which the data element of each node has a key, and: Binary Search Trees 1 The general binary tree shown in the previous chapter is not terribly useful in practice. The chief use of binary trees is for providing rapid access to data (indexing, if you will)

More information

Previous Lectures. B-Trees. External storage. Two types of memory. B-trees. Main principles

Previous Lectures. B-Trees. External storage. Two types of memory. B-trees. Main principles B-Trees Algorithms and data structures for external memory as opposed to the main memory B-Trees Previous Lectures Height balanced binary search trees: AVL trees, red-black trees. Multiway search trees:

More information

CS473 - Algorithms I

CS473 - Algorithms I CS473 - Algorithms I Lecture 9 Sorting in Linear Time View in slide-show mode 1 How Fast Can We Sort? The algorithms we have seen so far: Based on comparison of elements We only care about the relative

More information

Chapter 13: Query Processing. Basic Steps in Query Processing

Chapter 13: Query Processing. Basic Steps in Query Processing Chapter 13: Query Processing! Overview! Measures of Query Cost! Selection Operation! Sorting! Join Operation! Other Operations! Evaluation of Expressions 13.1 Basic Steps in Query Processing 1. Parsing

More information

Big O and Limits Abstract Data Types Data Structure Grand Tour. http://gcc.gnu.org/onlinedocs/libstdc++/images/pbds_different_underlying_dss_1.

Big O and Limits Abstract Data Types Data Structure Grand Tour. http://gcc.gnu.org/onlinedocs/libstdc++/images/pbds_different_underlying_dss_1. Big O and Limits Abstract Data Types Data Structure Grand Tour http://gcc.gnu.org/onlinedocs/libstdc++/images/pbds_different_underlying_dss_1.png Consider the limit lim n f ( n) g ( n ) What does it

More information

Social Media Mining. Graph Essentials

Social Media Mining. Graph Essentials Graph Essentials Graph Basics Measures Graph and Essentials Metrics 2 2 Nodes and Edges A network is a graph nodes, actors, or vertices (plural of vertex) Connections, edges or ties Edge Node Measures

More information

1/1 7/4 2/2 12/7 10/30 12/25

1/1 7/4 2/2 12/7 10/30 12/25 Binary Heaps A binary heap is dened to be a binary tree with a key in each node such that: 1. All leaves are on, at most, two adjacent levels. 2. All leaves on the lowest level occur to the left, and all

More information

Approximation Algorithms

Approximation Algorithms Approximation Algorithms or: How I Learned to Stop Worrying and Deal with NP-Completeness Ong Jit Sheng, Jonathan (A0073924B) March, 2012 Overview Key Results (I) General techniques: Greedy algorithms

More information

B-Trees. Algorithms and data structures for external memory as opposed to the main memory B-Trees. B -trees

B-Trees. Algorithms and data structures for external memory as opposed to the main memory B-Trees. B -trees B-Trees Algorithms and data structures for external memory as opposed to the main memory B-Trees Previous Lectures Height balanced binary search trees: AVL trees, red-black trees. Multiway search trees:

More information

Data Structure and Algorithm I Midterm Examination 120 points Time: 9:10am-12:10pm (180 minutes), Friday, November 12, 2010

Data Structure and Algorithm I Midterm Examination 120 points Time: 9:10am-12:10pm (180 minutes), Friday, November 12, 2010 Data Structure and Algorithm I Midterm Examination 120 points Time: 9:10am-12:10pm (180 minutes), Friday, November 12, 2010 Problem 1. In each of the following question, please specify if the statement

More information

Warshall s Algorithm: Transitive Closure

Warshall s Algorithm: Transitive Closure CS 0 Theory of Algorithms / CS 68 Algorithms in Bioinformaticsi Dynamic Programming Part II. Warshall s Algorithm: Transitive Closure Computes the transitive closure of a relation (Alternatively: all paths

More information

Persistent Binary Search Trees

Persistent Binary Search Trees Persistent Binary Search Trees Datastructures, UvA. May 30, 2008 0440949, Andreas van Cranenburgh Abstract A persistent binary tree allows access to all previous versions of the tree. This paper presents

More information

Analysis of a Search Algorithm

Analysis of a Search Algorithm CSE 326 Lecture 4: Lists and Stacks 1. Agfgd 2. Dgsdsfd 3. Hdffdsf 4. Sdfgsfdg 5. Tefsdgass We will review: Analysis: Searching a sorted array (from last time) List ADT: Insert, Delete, Find, First, Kth,

More information

A Comparison of Dictionary Implementations

A Comparison of Dictionary Implementations A Comparison of Dictionary Implementations Mark P Neyer April 10, 2009 1 Introduction A common problem in computer science is the representation of a mapping between two sets. A mapping f : A B is a function

More information

Sorting Algorithms. Nelson Padua-Perez Bill Pugh. Department of Computer Science University of Maryland, College Park

Sorting Algorithms. Nelson Padua-Perez Bill Pugh. Department of Computer Science University of Maryland, College Park Sorting Algorithms Nelson Padua-Perez Bill Pugh Department of Computer Science University of Maryland, College Park Overview Comparison sort Bubble sort Selection sort Tree sort Heap sort Quick sort Merge

More information

International Journal of Advanced Research in Computer Science and Software Engineering

International Journal of Advanced Research in Computer Science and Software Engineering Volume 3, Issue 7, July 23 ISSN: 2277 28X International Journal of Advanced Research in Computer Science and Software Engineering Research Paper Available online at: www.ijarcsse.com Greedy Algorithm:

More information

Sequential Data Structures

Sequential Data Structures Sequential Data Structures In this lecture we introduce the basic data structures for storing sequences of objects. These data structures are based on arrays and linked lists, which you met in first year

More information

Fast Sequential Summation Algorithms Using Augmented Data Structures

Fast Sequential Summation Algorithms Using Augmented Data Structures Fast Sequential Summation Algorithms Using Augmented Data Structures Vadim Stadnik vadim.stadnik@gmail.com Abstract This paper provides an introduction to the design of augmented data structures that offer

More information

Computer Algorithms. NP-Complete Problems. CISC 4080 Yanjun Li

Computer Algorithms. NP-Complete Problems. CISC 4080 Yanjun Li Computer Algorithms NP-Complete Problems NP-completeness The quest for efficient algorithms is about finding clever ways to bypass the process of exhaustive search, using clues from the input in order

More information

Algorithm Homework and Test Problems

Algorithm Homework and Test Problems Algorithm Homework and Test Problems Steven S. Skiena Department of Computer Science State University of New York Stony Brook, NY 11794-4400 skiena@cs.sunysb.edu January 29, 2006 All of the midterm and

More information

Motivation Suppose we have a database of people We want to gure out who is related to whom Initially, we only have a list of people, and information a

Motivation Suppose we have a database of people We want to gure out who is related to whom Initially, we only have a list of people, and information a CSE 220: Handout 29 Disjoint Sets 1 Motivation Suppose we have a database of people We want to gure out who is related to whom Initially, we only have a list of people, and information about relations

More information

CS211 Spring 2005 Final Exam May 17, 2005. Solutions. Instructions

CS211 Spring 2005 Final Exam May 17, 2005. Solutions. Instructions CS11 Spring 005 Final Exam May 17, 005 Solutions Instructions Write your name and Cornell netid above. There are 15 questions on 1 numbered pages. Check now that you have all the pages. Write your answers

More information

Review of Hashing: Integer Keys

Review of Hashing: Integer Keys CSE 326 Lecture 13: Much ado about Hashing Today s munchies to munch on: Review of Hashing Collision Resolution by: Separate Chaining Open Addressing $ Linear/Quadratic Probing $ Double Hashing Rehashing

More information

Class Overview. CSE 326: Data Structures. Goals. Goals. Data Structures. Goals. Introduction

Class Overview. CSE 326: Data Structures. Goals. Goals. Data Structures. Goals. Introduction Class Overview CSE 326: Data Structures Introduction Introduction to many of the basic data structures used in computer software Understand the data structures Analyze the algorithms that use them Know

More information

5.1 Bipartite Matching

5.1 Bipartite Matching CS787: Advanced Algorithms Lecture 5: Applications of Network Flow In the last lecture, we looked at the problem of finding the maximum flow in a graph, and how it can be efficiently solved using the Ford-Fulkerson

More information

A binary heap is a complete binary tree, where each node has a higher priority than its children. This is called heap-order property

A binary heap is a complete binary tree, where each node has a higher priority than its children. This is called heap-order property CmSc 250 Intro to Algorithms Chapter 6. Transform and Conquer Binary Heaps 1. Definition A binary heap is a complete binary tree, where each node has a higher priority than its children. This is called

More information

Abstract Data Type. EECS 281: Data Structures and Algorithms. The Foundation: Data Structures and Abstract Data Types

Abstract Data Type. EECS 281: Data Structures and Algorithms. The Foundation: Data Structures and Abstract Data Types EECS 281: Data Structures and Algorithms The Foundation: Data Structures and Abstract Data Types Computer science is the science of abstraction. Abstract Data Type Abstraction of a data structure on that

More information