DSA

0.0(0)
studied byStudied by 4 people
full-widthCall with Kai
GameKnowt Play
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/38

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

39 Terms

1
New cards

Binary Tree

  • allows data to be organized hierarchically, making it valuable in scenarios where data relationship exists.

  • it can have up to two (2) child nodes per parent.

2
New cards

Root node

Topmost mode of this tree

3
New cards

two (2)

Every parent node may have only __ children (left/right child)

4
New cards

Data Element

Functions as a storage for the data value that the node needs to store

5
New cards

Pointer to the Left Child

holds the address to the Left child node.

6
New cards

Pointer to the Right Child

holds the address to the Right child node.

7
New cards

Tree Traversal

  • process of visiting every node in a tree exactly once in a particular order to access or process data.

8
New cards

Breadth-First Traversal

  • also known as Level Order Traversal

  • visits the nodes level by level from the root downwards, moving horizontally across each level before descending to the next.

9
New cards

Depth-First Traversal

the traversal proceeds by exploring as deeply as possible along each branch before backtracking.

10
New cards

Inorder Traversal

  • LVR

  • This method is particularly useful in binary search trees because it retrieves values in a naturally sorted order.

11
New cards

Preorder Traversal

  • VLR

  • Commonly applied in tasks such as creating a duplicate of the tree or evaluating prefix expressions.

12
New cards

Postorder Traversal

  • LRV

  • useful when a task requires processing child nodes before their parent node (safely deleting a tree/evaluating postfix expression).

13
New cards

Binary Search Tree (BST)

  • used for retrieving, sorting, and searching data.

  • Ordered Binary Tree

14
New cards

Hierarchical Data Representation

  • represents file systems (directories contain subdirectories & files in a tree-like format).

  • DOM in HTML/XML docs use tree structures to illustrate nested relationships clearly.

15
New cards

Efficient Searching and Sorting

  • BST, AVL, and Red-Black Trees provide fast access, insertion, and deletion operations.

  • Ensures that these operations remain efficient (esp w/ frequent data updates).

16
New cards

Databases and File Storage Systems

  • Relies heavily on tree structures (B- Trees & B+ Trees)

  • used to manage large volumes of data and support efficient indexing & range queries (MySQL & Oracle)

  • Tries (prefix trees)  are used for fast retrieval in applications such as autocomplete systems, dictionary lookups, & IP routing in networks.

17
New cards

AI & Game Development

  • trees play a central role.

  • decision trees are commonly used for classification problems in machine learning.

  • minimax trees guide decision-making in competitive games like chess (optimized using alpha-beta pruning).

  • Behavior trees widely used in modern video games to control NPC behavior in a structured and modular way.

18
New cards

Compiler Design

  • rely on Abstract Syntax Trees (AST) to represent the syntactic structure of programming languages (parse and analyze code efficiently).

  • Parse trees also help visualize the grammatical structures of code inputs.

19
New cards

Cryptography and Security

  • Merkle Trees (blockchain technologies like BTC and ETH), facilitates fast and secure verification of transaction.

  • Authentication systems also use the tree structures to organize & verify credentials efficiently.

20
New cards

Networking

  • trees are essential for building routing tables and performing fast IP lookups using trie structures.

  • Minimum Spanning Tree (MST), employed through Kruskal’s or Prim’s algo, are used to optimize network designs by minimizing connection costs.

21
New cards

Heap Data Structure

  • binary tree in which every node is larger than the values associated with either child.

  • largest/smallest value is always at the top (root) of the tree.

22
New cards

Max-Heap

  • the parent node is always greater than/equal to its children.

  • largest value is always at the root of the tree.

23
New cards

Heapsort

(Max-Heap)

  • comparison-based sorting algo that uses a binary heap to repeatedly extract the max/min element and place it at the end of array.

  • it uses a max-heap to sort an array in ascending order by repeatedly extracting the max and placing it at the end.

24
New cards

Priority Queues (Max-Heap)

  • element with the highest priority is accessed first, such as real-time operating systems (RTOS) and emergency resource allocation systems.

  • put the “(Min-Heap) or (Max-Heap)” at the end of your answer

25
New cards

Top-K tracking

  • process of efficiently maintaining the K largest or K smallest elements from a continuous stream or large dataset, without sorting the entire input.

  • size of K is used to find the K smallest elements (max-heap). New elements are compared to the root (largest); if smaller value, it is replaced,

  • applied in product-ranking systems (bottom K-scores) & real-time performance analytics (slowest transactions).

26
New cards

Min-Heap

  • the parent node is always less than/equal to its children.

  • smallest value is always at the root of the tree.

27
New cards

Dijkstra’s Algorithm

  • uses min-heap to extract the next closest vertex (smallest tentative distance).

  • applied in GPS routing, network routing protocols & game AI pathfinding.

28
New cards

Priority Queues (Min-Heap)

  • this are the backbone of priority queues (task with lowest cost are processed first).

  • applied in CPU scheduling (shortest-job-first), task sched in OS, and printer job management.

  • put the “(Min-Heap) or (Max-Heap)” at the end of your answer.

29
New cards

Event-Driven Simulation

  • stores and retries the next event based on the timestamp.

  • min-heap ensures earlier event is always at the top.

  • applied in network simulations, manufacturing process simulations, logistics & supply chain modeling.

30
New cards

Insert (Push)

adds a new element to the heap by adding it at the bottom

31
New cards

Extract Root (Pop)

removes and returns the root element with the last element

32
New cards

Peek (Get Root)

returns the root without removing it.

33
New cards

Replace

removes the root and inserts a new element in a single operation.

34
New cards

Heapify

  • process of converting an arbitrary array (no specific structure/order) to a valid heap.

  • heap property (parent >= or <= children) is maintained from a given node down to its descendants.

35
New cards

Up-Heapify (Bubble-Up)

  • used after inserting a new element to restore the heap property by moving the element up the tree.

<ul><li><p>used after inserting a new element to restore the heap property by moving the element up the tree.</p></li></ul><p></p>
36
New cards

Down-Heapify (Bubble-Down)

  • used after deleting the root element to restore the heap property by moving the new root element down the tree.

<ul><li><p>used after deleting the root element to restore the heap property by moving the new root element down the tree.</p></li></ul><p></p>
37
New cards

Priority Queues

  • abstract data type that operates like a regular queue, except that each element priority level, and elements are dequeued based on their priority, not just their arrival order.

  • elements with higher priority are processed first.

38
New cards

Implementing Insert

When a new value is inserted into a priority queue, add the value so that the heap still has its properties.

To achieve:

  • Add the new value at the end of the array; that corresponds to adding it as a new rightmost leaf in the tree (or complete binary, all leaves were at the same depth) ensures that the heap has its shape property.

  • Compare the new value in its parents to check. If the parent is smaller, swap the values until the order property holds/reaches the root.

39
New cards

removeMax

This operation will always remove & return the root values.

To achieve:

  • Replace the value in the root with the value at the end of the array (corresponds to rightmost leaf at depth d).

  • Remove that leaf from the tree.

  • From down the tree, swap the values to restore the order property: each time is the value in the current node < one of its children, then swap its value with the larger child. Ensures that the new root value > both of its children.