-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBasics.java
More file actions
32 lines (27 loc) · 899 Bytes
/
Basics.java
File metadata and controls
32 lines (27 loc) · 899 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package Heaps;
import java.util.List;
/*
* Full Binary Tree : 0 / 2 child for all nodes.
* Complete Binary Tree : All levels must be filled except the last.
Last Level must be filled from left to right.
*
* HEAP : Heap is a data structure which is a Complete Binary Tree, represented in terms of Array and visualized in terms if Tree.
* MAX HEAP : For every node parent must be greater than the children.
* MIN HEAP : For every node parent must be smaller than the children.
*
* Left Child : (2 * i) + 1
* Right Child : (2 * i) + 2
* Parent : (i - 1) / 2
* */
public class Basics {
/*
* Utility function to swap the two array elements.
* */
public static void swap(List<Integer> heap, int l, int r) {
int temp = heap.get(l);
heap.set(l, heap.get(r));
heap.set(r, temp);
}
public static void main(String[] args) {
}
}