Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lära Heap Data Structure | Trees Part I
Data Structure & Algorithms PART I
course content

Kursinnehåll

Data Structure & Algorithms PART I

Data Structure & Algorithms PART I

1. Introduction to ADS
2. Data Structures Part I
3. Trees Part I
4. Trees Part II

book
Heap Data Structure

Heap is a binary tree. The binary tree doesn’t look like the traditional Homo sapiens family: children have only 1 parent, and this 1 parent may have only two children maximum. There are 2 types of heaps:

  • Max-heap: when each parent's value is more significant than its children's value;

  • Min-heap: when each parent's value is lower than its children’s value.

Let’s learn some basic heap operations:

  • Heapify;

  • Insert;

  • Deletion.

Heapify

Heapify is a process of creating a heap data structure from a binary tree.

Once the tree is composed, it is needed to create precisely the heap(max-/min-heap).

To do that, we need to replace nodes due to the rules of the max-/min-heap.

In the next chapter, we will practice heaping.

Insertion It is straightforward to insert an element into the heap. We need to:

  • Insert it as a leave (the end branches);

  • Perform heapifying.

Deletion

To delete the node from the heap, you need to:

  • Swap the element you want to delete with the last element;

  • Delete the last element;

  • Perform heapifying.

question mark

Choose options with the heap Data Structure.

Select the correct answer

Var allt tydligt?

Hur kan vi förbättra det?

Tack för dina kommentarer!

Avsnitt 3. Kapitel 4

Fråga AI

expand
ChatGPT

Fråga vad du vill eller prova någon av de föreslagna frågorna för att starta vårt samtal

course content

Kursinnehåll

Data Structure & Algorithms PART I

Data Structure & Algorithms PART I

1. Introduction to ADS
2. Data Structures Part I
3. Trees Part I
4. Trees Part II

book
Heap Data Structure

Heap is a binary tree. The binary tree doesn’t look like the traditional Homo sapiens family: children have only 1 parent, and this 1 parent may have only two children maximum. There are 2 types of heaps:

  • Max-heap: when each parent's value is more significant than its children's value;

  • Min-heap: when each parent's value is lower than its children’s value.

Let’s learn some basic heap operations:

  • Heapify;

  • Insert;

  • Deletion.

Heapify

Heapify is a process of creating a heap data structure from a binary tree.

Once the tree is composed, it is needed to create precisely the heap(max-/min-heap).

To do that, we need to replace nodes due to the rules of the max-/min-heap.

In the next chapter, we will practice heaping.

Insertion It is straightforward to insert an element into the heap. We need to:

  • Insert it as a leave (the end branches);

  • Perform heapifying.

Deletion

To delete the node from the heap, you need to:

  • Swap the element you want to delete with the last element;

  • Delete the last element;

  • Perform heapifying.

question mark

Choose options with the heap Data Structure.

Select the correct answer

Var allt tydligt?

Hur kan vi förbättra det?

Tack för dina kommentarer!

Avsnitt 3. Kapitel 4
Vi beklagar att något gick fel. Vad hände?
some-alt