Download presentation
Presentation is loading. Please wait.
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 * = new for CS Data Structures People
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
6
The Binary (Search) Tree
Organization of TreeNode objects: 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
BST represents hierarchy; allows very efficient searching or inserting; and can be manipulated easily J Root Node → F M B H T Leaves Y
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)
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
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.
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
15
Animated Simulations
16
Thank you Very Much! This should be posted on 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
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.