Review – Part 1 CSE 2011 Winter 2011 112 September 2015.

Slides:



Advertisements
Similar presentations
Lecture 22, Revision 1 Lecture notes Java code – CodeFromLectures folder* Example class sheets – 4 of these plus solutions Extra examples (quicksort) Lab.
Advertisements

Exam Review 3 Chapters 10 – 13, 15 CSC212 Section FG CS Dept, CCNY.
COL 106 Shweta Agrawal and Amit Kumar
EECS 4101/5101 Prof. Andy Mirzaian. Lists Move-to-Front Search Trees Binary Search Trees Multi-Way Search Trees B-trees Splay Trees Trees Red-Black.
Heaps1 Part-D2 Heaps Heaps2 Recall Priority Queue ADT (§ 7.1.3) A priority queue stores a collection of entries Each entry is a pair (key, value)
Binary Trees, Binary Search Trees CMPS 2133 Spring 2008.
Priority Queues And the amazing binary heap Chapter 20 in DS&PS Chapter 6 in DS&AA.
CSE 332 Review Slides Tyler Robison Summer
More sorting algorithms: Heap sort & Radix sort. Heap Data Structure and Heap Sort (Chapter 7.6)
Lists A list is a finite, ordered sequence of data items. Two Implementations –Arrays –Linked Lists.
BST Data Structure A BST node contains: A BST contains
Graphs & Exam Review 3 Chapter 10 – 13 CS211 CS Dept, MHC.
Course Review COMP171 Spring Hashing / Slide 2 Elementary Data Structures * Linked lists n Types: singular, doubly, circular n Operations: insert,
Unit 11a 1 Unit 11: Data Structures & Complexity H We discuss in this unit Graphs and trees Binary search trees Hashing functions Recursive sorting: quicksort,
COMP 171 Data Structures and Algorithms Tutorial 10 Hash Tables.
Priority Queues1 Part-D1 Priority Queues. Priority Queues2 Priority Queue ADT (§ 7.1.3) A priority queue stores a collection of entries Each entry is.
Comp 249 Programming Methodology Chapter 15 Linked Data Structure - Part B Dr. Aiman Hanna Department of Computer Science & Software Engineering Concordia.
Chapter Tow Search Trees BY HUSSEIN SALIM QASIM WESAM HRBI FADHEEL CS 6310 ADVANCE DATA STRUCTURE AND ALGORITHM DR. ELISE DE DONCKER 1.
1 Hash Tables  a hash table is an array of size Tsize  has index positions 0.. Tsize-1  two types of hash tables  open hash table  array element type.
Final Exam Review CS 3610/5610N Dr. Jundong Liu.
IKI 10100: Data Structures & Algorithms Ruli Manurung (acknowledgments to Denny & Ade Azurat) 1 Fasilkom UI Ruli Manurung (Fasilkom UI)IKI10100: Lecture8.
CS 3610 Midterm Review.
Final Review Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2010.
Midterm Review CSE 2011 Winter October 2015.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 223 – Advanced Data Structures Course Review Midterm.
1 Road Map Associative Container Impl. Unordered ACs Hashing Collision Resolution Collision Resolution Open Addressing Open Addressing Separate Chaining.
Final Review Dr. Yingwu Zhu. Goals Use appropriate data structures to solve real- world problems –E.g., use stack to implement non-recursive BST traversal,
Binary Trees, Binary Search Trees RIZWAN REHMAN CENTRE FOR COMPUTER STUDIES DIBRUGARH UNIVERSITY.
Chapter 21 Binary Heap.
Review for Final Andy Wang Data Structures, Algorithms, and Generic Programming.
1 Applications of BFS and DFS CSE 2011 Winter May 2016.
CS Data Structures II Review & Final Exam. 2 Topics Review Final Exam.
1 Binary Trees (7.3) CSE 2011 Winter November 2015.
CS223 Advanced Data Structures and Algorithms 1 Review for Midterm Neil Tang 03/06/2008.
Final Exam Review CS Total Points – 60 Points Writing Programs – 50 Points Tracing Algorithms, determining results, and drawing pictures – 50.
Chapter 2: Basic Data Structures. Spring 2003CS 3152 Basic Data Structures Stacks Queues Vectors, Linked Lists Trees (Including Balanced Trees) Priority.
CH 8. HEAPS AND PRIORITY QUEUES ACKNOWLEDGEMENT: THESE SLIDES ARE ADAPTED FROM SLIDES PROVIDED WITH DATA STRUCTURES AND ALGORITHMS IN C++, GOODRICH, TAMASSIA.
Review for Final Exam – cs411/511 Definitions (5 questions, 2 points each) Algorithm Analysis (3 questions, 3 points each) General Questions (3 questions,
Hashtables. An Abstract data type that supports the following operations: –Insert –Find –Remove Search trees can be used for the same operations but require.
Week 10 - Friday.  What did we talk about last time?  Graph representations  Adjacency matrix  Adjacency lists  Depth first search.
8 January Heap Sort CSE 2011 Winter Heap Sort Consider a priority queue with n items implemented by means of a heap  the space used is.
CS 146: Data Structures and Algorithms June 30 Class Meeting Department of Computer Science San Jose State University Summer 2015 Instructor: Ron Mak
FALL 2005CENG 213 Data Structures1 Priority Queues (Heaps) Reference: Chapter 7.
CISC220 Fall 2009 James Atlas Dec 07: Final Exam Review.
Week 15 – Wednesday.  What did we talk about last time?  Review up to Exam 1.
1 Joe Meehean. A A B B D D I I C C E E X X A A B B D D I I C C E E X X  Terminology each circle is a node pointers are edges topmost node is the root.
 Saturday, April 20, 8:30-11:00am in B9201  Similar in style to written midterm exam  May include (a little) coding on paper  About 1.5 times as long.
Final Exam Review CS Total Points – 20 Points Writing Programs – 65 Points Tracing Algorithms, determining results, and drawing pictures – 50.
1 the BSTree class  BSTreeNode has same structure as binary tree nodes  elements stored in a BSTree are a key- value pair  must be a class (or a struct)
DATA STRUCURES II CSC QUIZ 1. What is Data Structure ? 2. Mention the classifications of data structure giving example of each. 3. Briefly explain.
COMP 103 Course Review. 2 Menu  A final word on hash collisions in Open Addressing / Probing  Course Summary  What we have covered  What you should.
1 Priority Queues (Heaps). 2 Priority Queues Many applications require that we process records with keys in order, but not necessarily in full sorted.
Final Exam Review COP4530.
Final Exam Review CS 3358.
Trees Chapter 15.
Heaps (8.3) CSE 2011 Winter May 2018.
Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2008
Hashing CSE 2011 Winter July 2018.
Exam Hints.
Week 11 - Friday CS221.
Cse 373 April 26th – Exam Review.
November 1st – Exam Review
Review for Midterm Neil Tang 03/04/2010
Map interface Empty() - return true if the map is empty; else return false Size() - return the number of elements in the map Find(key) - if there is an.
CSE 326: Data Structures: Midterm Review
Final Exam Review COP4530.
Heap Sort CSE 2011 Winter January 2019.
Final Review Dr. Yingwu Zhu.
EE 312 Final Exam Review.
EECE.3220 Data Structures Instructor: Dr. Michael Geiger Spring 2019
Presentation transcript:

Review – Part 1 CSE 2011 Winter September 2015

Algorithm Analysis Given an algorithm, compute its running time in terms of O, , and  (if any).  Usually the big-Oh running time is enough. Given f(n) = 5n + 10, show that f(n) is O(n).  Find c and n 0 Compare the grow rates of 2 functions. Order the grow rates of several functions.  Use slide 14.  Use L’Hôpital’s rule. 2

Running Times of Loops Nested for loops: If the exact number of iterations of each loop is known, multiply the numbers of iterations of the loops. If the exact number of iterations of some loop is not known, “open” the loops and count the total number of iterations. 3

Running Time of Recursive Methods Could be just a hidden “for" or “while” loop.  See “Tail Recursion” slide.  “Unravel” the hidden loop to count the number of iterations. Logarithmic  Examples: binary search, exponentiation, GCD Solving a recurrence  Example: merge sort, quick sort 4

Recursion Know how to write recursive functions/methods: Recursive call  Adjusting recursive parameter(s) for each call Base case(s) 1.Use the definition (factorial, tree depth, height) 2.Cut the problem size by half (binary search), or by k elements at a time (sum, reversing arrays). 3.Divide and conquer (merge sort, quick sort) 5

Sorting Algorithms Insertion sort Merge sort Quick sort Lower bound of sorting algorithms  O(NlogN) When to use which sorting algorithm? Linear-time sorting (bucket sort) 6

Running Time of Tree Methods Most tree methods are recursive. Visualize the recursion trace. Count the number of nodes that were visited (processed) k. Compute the running time for processing each node O(m). If O(m v ) ≠ O(m u ), sum up the running times of the k nodes. Otherwise total running time = k  O(m) 7

Arrays and Linked Lists Arrays A = B Cloning arrays Extendable arrays Strategies for extending arrays:  doubling the size  increment by k cells Linked lists Singly linked Doubly linked Implementation Running times for insertion and deletion at the two ends. 8

Running Times of Array and Linked List Operations Operation Array unsorted Array sorted DL list unsorted DL list sorted insertO( ) deleteO( ) searchO( ) 9

Stacks, Queues and Deques Operations Array implementation Linked list implementation Running times for each implementation Assignment 3 (deques) 10

Trees Definitions, terminologies Traversal algorithms and applications  Preorder  Postorder Computing depth and height of a tree or node. 11

Binary Trees Linked structure implementation Array implementation Traversal algorithms  Preorder  Postorder  Inorder Properties: relationships between n, i, e, h. Definitions:  complete binary tree  full binary tree 12

13 Linked Structure of Binary Trees A node is represented by an object storing  Element  Parent node  Left child node  Right child node B D A CE   BADCE 

14 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 2i The right child of v is in position 2i + 1 The parent of v is in position ???

15 Space Analysis of Array Implementation n: number of nodes of binary tree T p M : index of the rightmost leaf of the corresponding full binary tree (or size of the full tree) N: size of the array needed for storing T; N = p M + 1 Best-case scenario: balanced, full binary tree p M = n Worst case scenario: unbalanced tree Height h = n – 1 Size of the corresponding full tree: p M = 2 h+1 – 1= 2 n – 1 N = 2 n Space usage: O(2 n )

16 Arrays versus Linked Structure Linked lists Slower operations due to pointer manipulations Use less space if the tree is unbalanced Rotation (restructuring) code is simple Arrays Faster operations Use less space if the tree is balanced (no pointers) Rotation (restructuring) code is complex

Review – Part 2 CSE September 2015

Binary Search Trees and AVL Trees BST Properties Searching Insertion  Distinct keys  Duplicate keys Deletion (3 cases) Running times AVL trees Properties Searching Insertion: as BST plus  restructuring (once) Deletion: as BST plus  restructuring (maybe more than once) Running times 18

19 BSTs versus AVL Trees OperationBSTsAVL Trees search insert delete findMin findMax

20 Implementations of Priority Queues Unsorted linked list  insertion O( )  deleteMin O( ) Sorted linked list  insertion O( )  deleteMin O( ) AVL trees  insertion O( )  deleteMin O( ) Unsorted array  insertion O( )  deleteMin O( ) Sorted array  insertion O( )  deleteMin O( ) Heaps  insertion O( )  deleteMin O( )

Heaps Properties Array implementation Insert  upheap percolation Delete  downheap percolation Running time Other operations:  decreaseKey(i, k)  increaseKey(i, k)  delete(i) 21

Heap Sort Using a temp heap T for (i = 0; i++; i < n) T.insert(A[i]); for (i = 0; i++; i < n) A[i] = T.deleteMin(); Running time = ? In-place sorting run buildHeap on A; repeat deleteMax; copyMax; until the heap is empty; Running time = ?

23 buildHeap Bottom-up heap construction runs in O(n) time. Bottom-up heap construction is faster than n successive insertions, which take O(nlogn).  speeds up the first phase of heap-sort.

Hashing Table size (a prime number) Hash functions  For integer keys division (modular) MAD  For strings: polynomial accumulation z = 33, 37, 39, 41 Collision handling Separate chaining Probing (open addressing)  Linear probing  Quadratic probing  Double hashing Probing: 3 types of cells (null, in use, available) 24

25 Comparing Collision Handling Schemes Separate chaining: – simple implementation – faster than open addressing in general – using more memory Open addressing: – using less memory – slower than chaining in general – more complex removals Linear probing: items are clustered into contiguous runs (primary clustering). Quadratic probing: secondary clustering. Double hashing: distributes keys more uniformly than linear probing does.

Graphs Definitions (terminology) Properties (with respect to V and E) Data structures  Adjacency matrix  Adjacency lists Running time of graph methods Graph traversal algorithms:  BFS  DFS 26

27 Properties of Undirected Graphs Notation V number of vertices E number of edges deg(v) degree of vertex v Property 1  v deg(v)  2E Proof: each edge is counted twice Property 2 In an undirected graph with no loops E  V (V  1)  2 Proof: each vertex has degree at most (V  1) What is the bound for a directed graph? Example  V  4  E  6  deg(v)  3

28 Applications of DFS and BFS CB A E D L0L0 L1L1 F L2L2 CB A E D F DFSBFS ApplicationsDFSBFS Spanning tree/forest, connected components, paths, cycles  Shortest paths  Biconnected components 

Final Exam Date: Sunday, 17 April Time: 10:00-13:00 (180 minutes) Materials  Lectures notes from the beginning up to and including the lecture on March 31.  Corresponding sections in the textbook.  Assignments 1 to 5. 29

Exam Rules This is a closed-book exam. No books, notes or calculators are allowed. You will be given blank paper for scrap work. Bring a photo ID, pens, and pencils. You may use pencils with darkness of at least HB; 2B is preferred. No questions are allowed during the exam. You may leave the classroom if you hand in your exam booklet 10 minutes or more before the exam ends. 30

Exam Rules (2) Programming problems will be marked based on both correctness and efficiency. You may use either Java or Java-like pseudo-code, but if an interface or class is given, you must use the methods and data structure(s) of the interface/class. 31

Office Hours before Exam (tentative) Wednesday, 6 April, 11:00-12:00 Thursday, 14 April, 14:00-15:00 32