How to Create a Max Heap using an Array in Java

A Heap/Binary Heap is a data structure that takes the form of Binary Tree. Heaps are commonly used to implement priority queues (check out the PriorityQueue class in Java). Priority queues are great ways to identify the highest (or lowest) priority items in a collection. A Max Heap is a binary tree data structure in

read more

How to Create a Hash Table in Java (Chaining Example)

Knowing how to create a hash table is helpful when using built-in HashTable and HashMap implementations in various languages. Questions about hash tables are commonly asked in programming interviews, and often people are asked to create an implementation from scratch. Below is an example of how to create a hash table in Java using “chaining”

read more

How to Code a Recursive Fibonacci Sequence

A Fibonacci Sequence is a sequence of numbers in which the first and second numbers in the sequence are 0 and 1 respectively, and additional numbers in the sequence are calculated by adding the previous two. The first few numbers in the Fibonacci Sequence look like this: 0, 1, 1, 2, 3, 5, 8, 13,

read more

How to Code an Iterative Fibonacci Sequence

A Fibonacci Sequence is a sequence of numbers in which the first and second numbers in the sequence are 0 and 1 respectively, and additional numbers in the sequence are calculated by adding the previous two. The first few numbers in the Fibonacci Sequence look like this: 0, 1, 1, 2, 3, 5, 8, 13,

read more

How to Reverse a Linked List

A common algorithm question is “How to Reverse a Linked List”. Below the SimpleLinkedList (Java) class contains a simple example to follow. The class SimpleLinkedList contains one field, head, which is used to keep track of the head (first) node of the linked list.

The nested class Node is the class used to create

read more

Recursive Binary Search Example

Binary Search is a classic algorithm used to find an item in an ordered list/array of items. This list/array of items must be ordered for binary search to work. The basic idea of Binary Search is to: Take the midpoint between the smallest and largest elements. Determine if item being searched for is smaller or

read more

Iterative Binary Search Example

Binary Search is a classic algorithm used to find an item in an ordered list/array of items. This list/array of items must be ordered for binary search to work. The basic idea of Binary Search is to: Take the midpoint between the smallest and largest elements. Determine if item being searched for is smaller or

read more

Java Binary Search Tree Implementation

The Binary Search Tree is commonly used data structure in Computer Science. Below is a complete binary search tree implementation, including the standard methods used to find, insert, and delete nodes from the tree. In addition are methods to print tree structure as well as track of the number nodes (so the tree size can

read more