CSC 213 – Large Scale Programming. Final Exam  Thurs., May 10 from 8:00 – 10:00 in OM 200  Plan on exam taking full 2 hours  If major problem, come.

Slides:



Advertisements
Similar presentations
Introduction to Algorithms Quicksort
Advertisements

Garfield AP Computer Science
The Dictionary ADT Definition A dictionary is an ordered or unordered list of key-element pairs, where keys are used to locate elements in the list. Example:
AVL Trees1 Part-F2 AVL Trees v z. AVL Trees2 AVL Tree Definition (§ 9.2) AVL trees are balanced. An AVL Tree is a binary search tree such that.
Chapter 4: Trees Part II - AVL Tree
CSC 213 – Large Scale Programming. Today’s Goals  Review discussion of merge sort and quick sort  How do they work & why divide-and-conquer?  Are they.
CSC 213 – Large Scale Programming or. Today’s Goals  Begin by discussing basic approach of quick sort  Divide-and-conquer used, but how does this help?
B+-Trees (PART 1) What is a B+ tree? Why B+ trees? Searching a B+ tree
Problem of the Day  You are trapped alone in a dark room with:  Candle;  Wood stove; and  Gas lamp (with full tank).  You only have one match; what.
Data Structures Data Structures Topic #13. Today’s Agenda Sorting Algorithms: Recursive –mergesort –quicksort As we learn about each sorting algorithm,
Sorting Chapter Sorting Consider list x 1, x 2, x 3, … x n We seek to arrange the elements of the list in order –Ascending or descending Some O(n.
CSC 213 – Large Scale Programming Lecture 27: Graph ADT.
CSC 213 ORD DFW SFO LAX Lecture 20: Graphs.
© 2004 Goodrich, Tamassia Graphs1 ORD DFW SFO LAX
Course Review COMP171 Spring Hashing / Slide 2 Elementary Data Structures * Linked lists n Types: singular, doubly, circular n Operations: insert,
TTIT33 Algorithms and Optimization – Dalg Lecture 2 HT TTIT33 Algorithms and optimization Lecture 2 Algorithms Sorting [GT] 3.1.2, 11 [LD] ,
General Trees and Variants CPSC 335. General Trees and transformation to binary trees B-tree variants: B*, B+, prefix B+ 2-4, Horizontal-vertical, Red-black.
Balanced Trees. Binary Search tree with a balance condition Why? For every node in the tree, the height of its left and right subtrees must differ by.
CSC 213 – Large Scale Programming. Today’s Goals  Review first two implementation for Graph ADT  What fields & data used in edge-list based approach.
Important Problem Types and Fundamental Data Structures
Tree-Structured Indexes. Range Searches ``Find all students with gpa > 3.0’’ –If data is in sorted file, do binary search to find first such student,
CSC 213 – Large Scale Programming. Today’s Goals  Review a new search tree algorithm is needed  What real-world problems occur with old tree?  Why.
1 Data Structures and Algorithms Sorting. 2  Sorting is the process of arranging a list of items into a particular order  There must be some value on.
Graphs – ADTs and Implementations ORD DFW SFO LAX
CHAPTER 09 Compiled by: Dr. Mohammad Omar Alhawarat Sorting & Searching.
CSC 213 Lecture 12: Quick Sort & Radix/Bucket Sort.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 19: Searching and Sorting Algorithms.
Merge Sort. What Is Sorting? To arrange a collection of items in some specified order. Numerical order Lexicographical order Input: sequence of numbers.
CSC 213 – Large Scale Programming. Today’s Goal  Review Map & Dictionary implementations  What do they do well? When would they be used?  Why do they.
1 CSC 421: Algorithm Design Analysis Spring 2014 Transform & conquer  transform-and-conquer approach  presorting  balanced search trees, heaps  Horner's.
CSC 213 – Large Scale Programming. Today’s Goals  Briefly review graphs and vital graph terms  Begin discussion of how to implement Graph  Vertex &
CSC 213 – Large Scale Programming Lecture 17: Binary Search Trees.
© 2006 Pearson Addison-Wesley. All rights reserved13 B-1 Chapter 13 (continued) Advanced Implementation of Tables.
Sorting Fun1 Chapter 4: Sorting     29  9.
Sorting. Pseudocode of Insertion Sort Insertion Sort To sort array A[0..n-1], sort A[0..n-2] recursively and then insert A[n-1] in its proper place among.
Graphs CSE 2011 Winter June Graphs A graph is a pair (V, E), where  V is a set of nodes, called vertices  E is a collection of pairs.
CSC 212 – Data Structures Lecture 37: Course Review.
B + -Trees. Motivation An AVL tree with N nodes is an excellent data structure for searching, indexing, etc. The Big-Oh analysis shows that most operations.
2-3 Tree. Slide 2 Outline  Balanced Search Trees 2-3 Trees Trees.
School of Engineering and Computer Science Victoria University of Wellington Copyright: Xiaoying Gao, Peter Andreae, VUW B Trees and B+ Trees COMP 261.
File Organization and Processing Week Tree Tree.
Fall 2006 CSC311: Data Structures 1 Chapter 10: Search Trees Objectives: Binary Search Trees: Search, update, and implementation AVL Trees: Properties.
CS 206 Introduction to Computer Science II 04 / 22 / 2009 Instructor: Michael Eckmann.
Lecture 11COMPSCI.220.FS.T Balancing an AVLTree Two mirror-symmetric pairs of cases to rebalance the tree if after the insertion of a new key to.
Chapter 18: Searching and Sorting Algorithms. Objectives In this chapter, you will: Learn the various search algorithms Implement sequential and binary.
+ David Kauchak cs312 Review. + Midterm Will be posted online this afternoon You will have 2 hours to take it watch your time! if you get stuck on a problem,
3.1. Binary Search Trees   . Ordered Dictionaries Keys are assumed to come from a total order. Old operations: insert, delete, find, …
Week 10 - Friday.  What did we talk about last time?  Graph representations  Adjacency matrix  Adjacency lists  Depth first search.
1 C++ Classes and Data Structures Jeffrey S. Childs Chapter 15 Other Data Structures Jeffrey S. Childs Clarion University of PA © 2008, Prentice Hall.
COSC 2007 Data Structures II
CSC 213 – Large Scale Programming. Graphs  Mathematically, graph is pair (V, E) where  V is collection of nodes, called vertices  Two nodes can be.
Week 15 – Wednesday.  What did we talk about last time?  Review up to Exam 1.
Week 9 - Monday.  What did we talk about last time?  Practiced with red-black trees  AVL trees  Balanced add.
Chapter 4, Part II Sorting Algorithms. 2 Heap Details A heap is a tree structure where for each subtree the value stored at the root is larger than all.
Today’s Material Sorting: Definitions Basic Sorting Algorithms
1 CSC 421: Algorithm Design Analysis Spring 2013 Transform & conquer  transform-and-conquer approach  presorting  balanced search trees, heaps  Horner's.
Chapter 11. Chapter Summary  Introduction to trees (11.1)  Application of trees (11.2)  Tree traversal (11.3)  Spanning trees (11.4)
CSE 250 – Data Structures. Today’s Goals  First review the easy, simple sorting algorithms  Compare while inserting value into place in the vector 
Advanced Sorting 7 2  9 4   2   4   7
Chapter 11 Sorting Acknowledgement: These slides are adapted from slides provided with Data Structures and Algorithms in C++, Goodrich, Tamassia and Mount.
COMP261 Lecture 23 B Trees.
Multiway Search Trees Data may not fit into main memory
B+-Trees.
Cse 373 April 26th – Exam Review.
Teach A level Computing: Algorithms and Data Structures
original list {67, 33,49, 21, 25, 94} pass { } {67 94}
Wednesday, April 18, 2018 Announcements… For Today…
B+ Trees What are B+ Trees used for What is a B Tree What is a B+ Tree
Richard Anderson Spring 2016
CS203 Lecture 15.
Presentation transcript:

CSC 213 – Large Scale Programming

Final Exam  Thurs., May 10 from 8:00 – 10:00 in OM 200  Plan on exam taking full 2 hours  If major problem, come talk to me ASAP  Exam covers material from entire semester  Open-book & open-note so bring what you’ve got  My handouts, solutions, & computers are not allowed  Cannot collaborate with a neighbor on the exam  Problems will be in a similar style to 2 midterms  Lab mastery: 12:30 – 1:30 on Wed., May 11 in OM119

Lazy

Contemplative

Always Using Imagination

Most Important Trait

Critical Property of Test

Loop Testing: Simple Loops  Loop executed at most n times, try inputs that:  Skip loop entirely  Make 1 pass through the loop  Make 2 passes through the loop  Make m passes through the loop, where ( m < n )  If possible,  If possible, n -1, n, & ( n +1) passes through the loop

Indexed File Format  Split information into two (or more) files  Data file uses fixed-size records to store data  Index files contain search terms & location record starts  Fixed-size records usually used in data file  Each record will use exactly that much space  Extra space wasted if the value is smaller  But limits data size, cannot get more space  Makes it far easier  Makes it far easier to reuse space & rebuild index

Entry ADT  Needs 2 pieces: what we have & what we want  First part is the key: data used in search  Item we want is value; the second part of an Entry  Implementations must define 2 methods  key() & value() return appropriate item NOT  Usually includes setValue() but NOT setKey()

What is a M AP ?  At simplest level, Map is collection of Entry s  key-value pairs serve as the basic data in a Map  size() & isEmpty() work at level of Entry  Searchable data stored using Map s  put() adds an Entry so key is mapped to the value  get() retrieves value associated with key from Map  remove() deletes entire Entry  At most one value per key using a Map

Dictionary ADT very  D ICTIONARY ADT very similar to M AP  Hold searchable data in each of these ADTs  Both data structures are collections of Entry s  Convert key to value using either concept  D ICTIONARY can have multiple values to one key  1 value for key is still legal option  Also many Entry s with same key but different value

Using Hash Properly

Binary Search Trees  Implements a BinaryTree for searching  Map or Dictionary will be ADT exposed  Data organized to make usage efficient (maybe)  Strict ordering maintained in tree  Nodes to the left are smaller  Larger keys in right child of node  Equal values not specified  No problem, just be consistent

BST Performance  Search, insert, & remove take O(h) time  h is height of tree  Height’s best case is complete tree at O(log n)  O(n) height for linked list is BST’s worst case

AVL Tree Definition  Fancy type of BST  O(log n) time provided  For this, needs more info

AVL Tree Definition Node heights are shown in blue

Concept Behind SplayTree  Splay trees do NOT maintain balance  Recently used nodes clustered near top of BST  Most recently accessed nodes take O(1) time  Other nodes may need O ( n ) time to access but provides no guarantees  Usually very efficient, but provides no guarantees

Red-Black Tree black  Root Property: Root node painted black black  External Property: Leaves are painted black black  Internal Property: Red nodes’ children are black black  Depth Property: Leaves have identical black depth black  Number of black ancestors for the node

Map & Dictionary ADT ImplementationSearchingAddingRemoving Ordered List O(log n)O(n)O(n)O(n)O(n) Unordered List O(n)O(n)O(n)/O(1)O(n)/O(1)O(n)O(n) Hash O(n)O(n)O(n)O(n)O(n)O(n) if lucky/good O(1)O(1)O(1)O(1)O(1)O(1) BST O(n)O(n)O(n)O(n)O(n)O(n) AVL / balanced O(log n) Splay (expected) O(log n) Splay (worst-case) O(n)O(n)O(n)O(n)O(n)O(n)

Using Set s  Amorphous, Iterable collection of elements  Elements unordered in concept, but only once per Set  Easiest approach relies on ordered Sequence  Faster possible, but much more complex & limits use  This still fast: hardest operations need O ( n ) time P OSITION s Set list comp

Set Operations  Set defines 3 operations involving other Set s  union(s) adds elements in s to this  Elements in s removed from this by subtract(s)  intersect(s) preserve elements in s also in this  Comparing Set s’ elements needed for each  Operations differ only in how to act after comparison  When already ordered, process much easier

Merge Sort Execution Tree  Show steps used to sort all of the data     77  72  22    99  94  44     88  83  33    66  61  11  1

Quick Sort  Divide: Partition by pivot  L has values <= p  G uses values >= p  Recur: Sort L and G  Conquer: Merge L, p, G p p L G p

Quick Sort v. Merge Sort Quick SortMerge Sort  Divide data around pivot  Want pivot to be near middle  All comparisons occur here  Conquer with recursion  Does not need extra space  Merge usually done already  Data already sorted!  Divide data in blindly half  Always gets even split  No comparisons performed!  Conquer with recursion  Needs * to use other arrays  Merge combines solutions  Compares from (sorted) halves

Bucket & Radix Sort  Sort data written as tuple of enumerable data  Consumption of wine overall, in liters  Annual per capita consumption of liters  Sort one place in tuple using bucket sort  Uses 1 bucket per value that could be enumerated  When there are ties, preserve relative ordering  Repeat stable sorts to perform radix sort  Must preserve relative ordering, like bucket sort  From least to most important sort each tuple place

Radix-Sort In Action  List of 4-bit integers sorted using R ADIX - SORT

Lower Bound on Sorting  Smallest number of comparisons is tree’s height  Decision tree sorting n elements has n! leaves  At least log( n !) height needed for this many leaves  As we saw, this simplifies to at most O(n log n) height  O(n log n) time needed to compare data!  Practical lower bound, but cheating can do better  Need enumerable tuples  Need enumerable tuples - cannot always cheat  “If you believe radix hypothesis” it takes O(n) time

Graph Applications  Electronic circuits  Transportation networks  Databases  Packing suitcases  Finding terrorists  Scheduling college’s exams  Assigning classes to rooms  Garbage collection  Coloring countries on a map  Playing minesweeper

edges Edge List Structure  Simplest Graph  Space efficient  No change to use with directed or undirected  Fields  Sequence of vertices  Sequence of edges vw ac b a z d b c d vertices v w z u u

edges vertices Adjacency-List Implementation  Vertex has Sequence of Edge s  Edges still refer to Vertex  Ideas in Edge-List serve as base  Extends Vertex  Add Position reference to speed removal uw uv w ab u v w a b

edges vertices Adjacency Matrix Structure u v w 012 u v w a b ba

012 0  1  2  edges vertices Adjacency Matrix Structure  Undirected edges stored in both array locations  Directed edges only in array from source to target u v w 012 u v w a b ba

n vertices & m edges no self-loops Edge- List Adjacency- List Adjacency- Matrix Space n  m n2n2 incidentEdges (v) mdeg(v)n + deg(v) areAdjacent (v,w) mmin(deg(v), deg(w))1 insertVertex (o) 11n2n2 insertEdge (v,w,o) 111 removeVertex (v) mdeg(v)n2n2 removeEdge (e) 111 Asymptotic Performance

Graphs Solve Many Problems…  Understand how it works & what it does:  DFS finds connected components in tree form  Connected vertices using minimal hops using BFS  Dijsktra’s minimizes weight to each vertex  Weight of edge total minimized with Prim-Jarnik  Topological sort schedules vertices (when possible)  Can compute reachablility with Floyd-Warshall  Given problem, which algorithm would solve it?

Cost of Accessing Memory  How long memory access takes is also important  Will make a major difference in time program takes  Easy memory aid to remember how this works:

Multi-Way Search Tree  Nodes contain multiple elements  Tree grows up  Tree grows up with leaves always at same level  Each internal node:  At least 2 children  Has 1 fewer Entry s than children  Entry s sorted from smallest to largest

Hints for Studying  Will NOT require memorizing:  ADT’s methods  Node implementations  Big-Oh time proofs  (Anything else you think of)

Hints for Studying

Studying For the Exam 1. What does the ADT/implementation do? Where in the real-world is this found? 2. How is the ADT, search tree, or sort used? What would we apply it to solve a problem? How is it used and why? 3. What is necessary for implementation? Given implementation, why do we do it like that? What tradeoffs does this implementation make?

“Subtle” Hint