Book Image

Everyday Data Structures

By : William Smith
Book Image

Everyday Data Structures

By: William Smith

Overview of this book

Explore a new world of data structures and their applications easily with this data structures book. Written by software expert William Smith, you?ll learn how to master basic and advanced data structure concepts. ? Fully understand data structures using Java, C and other common languages ? Work through practical examples and learn real-world applications ? Get to grips with data structure problem solving using case studies
Table of Contents (20 chapters)
Everyday Data Structures
Credits
About the Author
About the Reviewer
www.PacktPub.com
Customer Feedback
Preface
Free Chapter
1
Data Types: Foundational Structures

Heap implementations


Like trees, heaps are typically implemented using either linked lists or linked nodes, or an array. Since we examined the linked node approach in Chapter 9, Trees: Nonlinear Structures, in this chapter, we'll examine an array implementation of a heap called a binary heap.

A binary heap is a tree structure where all levels of the tree are filled completely, with the possible exception of the last or deepest level. In the case of the deepest level the nodes are filled from left to right until the level is full. As you can see from the preceding figure, in an array-based implementation each parent node has two child nodes that are located at 2i + 1 and 2i + 2, where i is the index of the parent node and the first node of the collection is found at index 0.

Note

Alternate implementations skip the 0 index of the array to simplify the arithmetic of finding child and parent nodes for a given index. In this design, the child nodes for any given index i are located at 2i and 2i...