1 / 16

Data Structures – An Introduction

Data Structures – An Introduction. Comp Sci Club 12 June 2014. After CS III AP…. First of all – Congratulations on finishing CS III There is much more to Comp Sci (A lot more than I thought when I took the AP Exam!). Overview (for Today’s Meeting). Data Structures – some background

saad
Download Presentation

Data Structures – An Introduction

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Data Structures –An Introduction Comp Sci Club 12 June 2014

  2. After CS III AP… • First of all – Congratulations on finishing CS III • There is much more to Comp Sci • (A lot more than I thought when I took the AP Exam!)

  3. Overview (for Today’s Meeting) • Data Structures – some background • Binary Trees – BSTs, methods(), uses, etc. • *Types of Binary Trees • *Heaps, *HeapSort • Conclusion

  4. Data Structures • Simple, efficient ways of organizing data • (Goes far Beyond the ‘Array’ and ‘ArrayList’ concepts taught in CS III!)

  5. Data Structures • Abstract Data Type – more generalized forms of these structures (e.g. Queue, Stack, LinkedList, etc.) • Data Structure – how programmers/software developers implement these data types (ArrayQueue, LinkedStack/ArrayStack, Singly/DoublyLinkedList) • However… • There are some concepts which are more ambiguous, and can be considered part-“data type” and part-“data structure” • And, we will see a few of these in this presentation  http://cs.lmu.edu/~ray/notes/dtds/

  6. The Binary (Search) Tree • Organization ofTreeNodeobjects: each ‘level’ of this structure has up to 2N Nodes. • Each Node has a reference to value; left, and right • Several different kinds of binary trees; a very common one is the Binary Search Tree • All Nodes left of root have VALUES less than the root; All Nodes right of root have VALUES greater than the root. • This principle applies to every Node, in fact.

  7. The Binary (Search) Tree • http://www.cs.cmu.edu/~adamchik/15-121/lectures/Trees/trees.html • BST represents hierarchy; allows very efficient searching or inserting; and can be manipulated easily Root Node → J F B H M T Y Leaves

  8. Binary Trees – Specific Types* • Full Binary Tree – every node has zero or two ‘children’ • Perfect Binary Tree – all leaf nodes lie on same level • Complete Binary Tree – every level is filled completely, except perhaps the last level (more detail later) http://en.wikipedia.org/wiki/Binary_tree http://www.cs.cmu.edu/~adamchik/15-121/lectures/Trees/trees.html http://www.scribd.com/doc/17116770/Types-of-Binary-Tree

  9. Infinite Binary Trees – A Digression • Stern-Brocot Tree – Mathematical model for the set of all positive rational numbers (known since the 1850s!) • Wikipedia: the cardinalities of these numbers (the nodes themselves = א0; ways of permuting them = c) • There are numerous interesting facts about this model – see cut-the-knort.org and other sites for more info http://en.wikipedia.org/wiki/Binary_tree http://www.cut-the-knot.org/blue/Stern.shtml

  10. Heaps

  11. A Heap* Disambiguation: I am not talking about THE Heap, which is considered the source for all dynamic data (i.e., how data is stored in an Object rather than a primitive type.) ….What do I mean then?

  12. A Heap* • Special Binary Tree – a complete binary tree • Bottom row (‘level’) fills from the left • Allows simple implementations (Array duality) • Max-heap property – root node is greater than all others; min-heap property – root node is less than all others • Technically, the heap can be seen as a data structure for a PriorityQueue • Queue, you may recall, is a built-in Java interface, modeling ‘FIFO’ • PriorityQueue – more specific type that assigns a priority to each task/value, removing the highest Priority first

  13. Heaps* • Percolation Up/Down Method of adding/deleting a Node to/from a Heap. Involves swapping the last/final Node with the Root Node, then comparing the new ‘last’ with its parent Nodes to find where it should be. • https://www.cs.auckland.ac.nz/~jmor159/PLDS210/heaps.html • http://www.cs.cmu.edu/~adamchik/15-121/lectures/Binary%20Heaps/heaps.html

  14. HeapSort! • Relatively efficient kind of sort • O (n log (n)) [for a worst case, this is not too bad] • Collects all elements into heap, sorts them inside the Heap, then remove each while updating the structure • In-place algorithm – uses small, constant memory • Somewhat complicated process • Make a heap out of the given info // Can be max or min! • Remove the root Node; replace it with the final Node in the heap • Perform comparisons (from left to right) to “rebalance” or reconfigure the heap again (method siftUp() or siftDown()) • Repeat steps 2-3 until there are no Nodes remaining • http://stackoverflow.com/questions/8938375/an-intuitive-understanding-of-heapsort • http://en.wikipedia.org/wiki/Heapsort • https://www.cs.auckland.ac.nz/~jmor159/PLDS210/heapsort.html

  15. Animated Simulations • http://www.ee.ryerson.ca/~courses/coe428/sorting/heapsort.html • http://en.wikipedia.org/wiki/Heapsort#mediaviewer/File:Heapsort-example.gif

  16. Thank you Very Much! • This should be posted on http://mthcompsci.wordpress.com/within a week • Many thanks to all of you for a great year of CS Club • I exhort you to continue next year • (March competition!) • (Recruiting more people?) • Good luck on Final Exams; have a great summer 

More Related