comp2521 19t0
play

COMP2521 19T0 Week 7, Tuesday: A Question of Balance Jashank Jeremy - PowerPoint PPT Presentation

COMP2521 19T0 lec12 cs2521@ jashankj@ Sorting Balanced Trees COMP2521 19T0 Week 7, Tuesday: A Question of Balance Jashank Jeremy jashank.jeremy@unsw.edu.au radix sort balanced trees COMP2521 19T0 lec12 cs2521@ jashankj@ Sorting


  1. COMP2521 19T0 lec12 cs2521@ jashankj@ Sorting Balanced Trees COMP2521 19T0 Week 7, Tuesday: A Question of Balance Jashank Jeremy jashank.jeremy@unsw.edu.au radix sort balanced trees

  2. COMP2521 19T0 lec12 cs2521@ jashankj@ Sorting Non-Comparison Radix Balanced Trees Sorting

  3. COMP2521 19T0 lec12 Sorting individually on each part of the key at a time: Keys are values in some base- R number system. Radix sorts let us deal with this case. Can we decompose our keys? Radix Sorting Trees Balanced Radix Non-Comparison Sorting jashankj@ cs2521@ digit-by-digit, character-by-character, rune-by-rune, etc. e.g. , binary, R = 2 ; decimal, R = 10 ; ascii, R = 128 or R = 256 ; Unicode, R = 2 16

  4. COMP2521 3129 with R 3129 2301 2122 1019 31 29 21 22 23 01 10 19 2 122 3 129 2 301 1 019 2122 2301 19T0 lec12 1019 key.1 , key.2 , …, key. w recurse into each piece, using succesive keys — partitioning input into R pieces according to key.0 ; from left to right ; Consider characters, digits, bits, runes, etc. , Radix Sorting, Most-Significant-Digit First Trees Balanced Radix Non-Comparison Sorting jashankj@ cs2521@ , roughly a quicksort.

  5. COMP2521 3129 with R 3129 2301 2122 1019 31 29 21 22 23 01 10 19 2 122 3 129 2 301 1 019 2122 2301 19T0 lec12 1019 key.1 , key.2 , …, key. w recurse into each piece, using succesive keys — partitioning input into R pieces according to key.0 ; from left to right ; Consider characters, digits, bits, runes, etc. , Radix Sorting, Most-Significant-Digit First Trees Balanced Radix Non-Comparison Sorting jashankj@ cs2521@ , roughly a quicksort.

  6. COMP2521 3129 with R 3129 2301 2122 1019 31 29 21 22 23 01 10 19 2 122 3 129 2 301 1 019 2122 2301 19T0 lec12 1019 key.1 , key.2 , …, key. w recurse into each piece, using succesive keys — partitioning input into R pieces according to key.0 ; from left to right ; Consider characters, digits, bits, runes, etc. , Radix Sorting, Most-Significant-Digit First Trees Balanced Radix Non-Comparison Sorting jashankj@ cs2521@ , roughly a quicksort.

  7. COMP2521 3129 with R 3129 2301 2122 1019 31 29 21 22 23 01 10 19 2 122 3 129 2 301 1 019 2122 2301 19T0 lec12 1019 key.1 , key.2 , …, key. w recurse into each piece, using succesive keys — partitioning input into R pieces according to key.0 ; from left to right ; Consider characters, digits, bits, runes, etc. , Radix Sorting, Most-Significant-Digit First Trees Balanced Radix Non-Comparison Sorting jashankj@ cs2521@ , roughly a quicksort.

  8. COMP2521 3129 3129 2301 2122 1019 31 29 21 22 23 01 10 19 2 122 3 129 2 301 1 019 2122 2301 19T0 lec12 1019 key.1 , key.2 , …, key. w recurse into each piece, using succesive keys — partitioning input into R pieces according to key.0 ; from left to right ; Consider characters, digits, bits, runes, etc. , Radix Sorting, Most-Significant-Digit First Trees Balanced Radix Non-Comparison Sorting jashankj@ cs2521@ with R = 2 , roughly a quicksort.

  9. COMP2521 3 1 29 23 0 1 21 2 2 10 1 9 31 2 9 2 3 01 1 0 19 2 1 22 1 019 312 9 2 122 3 129 2 301 1019 2122 2301 3129 212 2 230 1 19T0 lec12 Radix Sorting, Least-Significant-Digit First cs2521@ jashankj@ Sorting Non-Comparison Radix Balanced Trees Consider characters, digits, bits, runes, etc. , 101 9 use a stable sort using the d th digit as key, using ( e.g. ,) key-indexed counting sort. 1019 2301 3129 2122 this will not work if the sort is not stable! from right to left ;

  10. COMP2521 3 1 29 23 0 1 21 2 2 10 1 9 31 2 9 2 3 01 1 0 19 2 1 22 1 019 312 9 2 122 3 129 2 301 1019 2122 2301 3129 212 2 230 1 19T0 lec12 Radix Sorting, Least-Significant-Digit First cs2521@ jashankj@ Sorting Non-Comparison Radix Balanced Trees Consider characters, digits, bits, runes, etc. , 101 9 use a stable sort using the d th digit as key, using ( e.g. ,) key-indexed counting sort. 1019 2301 3129 2122 this will not work if the sort is not stable! from right to left ;

  11. COMP2521 3 1 29 23 0 1 21 2 2 10 1 9 31 2 9 2 3 01 1 0 19 2 1 22 1 019 312 9 2 122 3 129 2 301 1019 2122 2301 3129 212 2 230 1 19T0 lec12 Radix Sorting, Least-Significant-Digit First cs2521@ jashankj@ Sorting Non-Comparison Radix Balanced Trees Consider characters, digits, bits, runes, etc. , 101 9 use a stable sort using the d th digit as key, using ( e.g. ,) key-indexed counting sort. 1019 2301 3129 2122 this will not work if the sort is not stable! from right to left ;

  12. COMP2521 3 1 29 23 0 1 21 2 2 10 1 9 31 2 9 2 3 01 1 0 19 2 1 22 1 019 312 9 2 122 3 129 2 301 1019 2122 2301 3129 212 2 230 1 19T0 lec12 Radix Sorting, Least-Significant-Digit First cs2521@ jashankj@ Sorting Non-Comparison Radix Balanced Trees Consider characters, digits, bits, runes, etc. , 101 9 use a stable sort using the d th digit as key, using ( e.g. ,) key-indexed counting sort. 1019 2301 3129 2122 this will not work if the sort is not stable! from right to left ;

  13. COMP2521 3 1 29 23 0 1 21 2 2 10 1 9 31 2 9 2 3 01 1 0 19 2 1 22 1 019 312 9 2 122 3 129 2 301 1019 2122 2301 3129 212 2 230 1 19T0 lec12 Radix Sorting, Least-Significant-Digit First cs2521@ jashankj@ Sorting Non-Comparison Radix Balanced Trees Consider characters, digits, bits, runes, etc. , 101 9 use a stable sort using the d th digit as key, using ( e.g. ,) key-indexed counting sort. 1019 2301 3129 2122 this will not work if the sort is not stable! from right to left ;

  14. COMP2521 3 1 29 23 0 1 21 2 2 10 1 9 31 2 9 2 3 01 1 0 19 2 1 22 1 019 312 9 2 122 3 129 2 301 1019 2122 2301 3129 212 2 230 1 19T0 lec12 Radix Sorting, Least-Significant-Digit First cs2521@ jashankj@ Sorting Non-Comparison Radix Balanced Trees Consider characters, digits, bits, runes, etc. , 101 9 use a stable sort using the d th digit as key, using ( e.g. ,) key-indexed counting sort. 1019 2301 3129 2122 this will not work if the sort is not stable! from right to left ;

  15. COMP2521 3 1 29 23 0 1 21 2 2 10 1 9 31 2 9 2 3 01 1 0 19 2 1 22 1 019 312 9 2 122 3 129 2 301 1019 2122 2301 3129 212 2 230 1 19T0 lec12 Radix Sorting, Least-Significant-Digit First cs2521@ jashankj@ Sorting Non-Comparison Radix Balanced Trees Consider characters, digits, bits, runes, etc. , 101 9 use a stable sort using the d th digit as key, using ( e.g. ,) key-indexed counting sort. 1019 2301 3129 2122 this will not work if the sort is not stable! from right to left ;

  16. COMP2521 19T0 lec12 May be stable! Usable on variable length data. ( D is the recursion depth.) msd May be stable! Usable on variable length data. lsd the algorithm makes w passes over n keys where w is the ‘width’ of data; Can complete before examining all of all keys. Analysis; Summary Radix Sort Trees Balanced Radix Non-Comparison Sorting jashankj@ cs2521@ Complexity: O ( w ( n + R )) ≈ O ( n ) , Not in-place: O ( n + R ) extra space required. Not in-place: O ( n + DR ) extra space required.

  17. COMP2521 Primitives Splay Complex Approaches Random Trees Root Insert Global Simple Approaches Partition Rotation Properties 19T0 lec12 Search Trees Trees, BTrees Searching Recap Trees Balanced Sorting jashankj@ cs2521@ Balanced Trees

  18. COMP2521 19T0 lec12 Common variations: output item(s) containing that key input a key value Recap: The Search Problem Splay Complex Approaches Random Trees Root Insert Global Simple Approaches Partition Rotation Primitives Properties Search Trees Trees, BTrees Searching Recap Trees Balanced Sorting jashankj@ cs2521@ We assume: keys are unique, each item has one key. • keys are unique; key value matches 0 or 1 items • multiple keys in search, items containing any key • multiple keys in search/item, items containing all keys

  19. COMP2521 19T0 lec12 Trees can be viewed as a set of nested structures: Each node contains a value. Trees are branched data structures, Recap: Trees; Binary Trees Splay Complex Approaches Random Trees Root Insert Global Simple Approaches Partition Rotation Primitives Properties Search Trees Trees, BTrees Searching Recap Trees Balanced Sorting jashankj@ cs2521@ consisting of nodes and edges, with no cycles. Each node has edges to ≤ k other nodes. For now, k = 2 — binary trees each node has k (possibly empty) subtrees.

  20. is degenerate if its height is is balanced if its height is COMP2521 19T0 lec12 by order of insertion: Structure tends to be determined at least log n . A binary tree of n nodes . at most n A binary tree of n nodes values in the right subtree For all nodes in the tree: Recap: Binary Search Trees Splay Complex Approaches Random Trees Root Insert Trees, BTrees cs2521@ jashankj@ Sorting Balanced Trees Recap Searching Search Trees Global Properties Primitives Rotation Partition Simple Approaches vs the values in the left subtree are less than the node value the are greater than the node value

  21. COMP2521 Simple Approaches by order of insertion: Structure tends to be determined A binary tree of n nodes A binary tree of n nodes values in the right subtree For all nodes in the tree: Recap: Binary Search Trees Splay Complex Approaches 19T0 lec12 Root Insert Global Random Trees Partition Rotation cs2521@ jashankj@ Sorting Balanced Trees Recap Searching Trees, BTrees Search Trees Properties Primitives vs is degenerate if its height is at most n − 1 . the values in the left subtree are less than the node value the is balanced if its height is at least ⌊ log 2 n ⌋ . are greater than the node value

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend