Binary Tree Data Structure

BestCalculus avatar
BestCalculus
·
·
Download

Start Quiz

Study Flashcards

12 Questions

What is the maximum number of children a node can have in a binary tree?

2

How is a binary tree represented?

A binary tree is represented by a pointer to the topmost node (commonly known as the 'root') of the tree.

What are the three types of traversals in a binary tree?

In order traversal, Pre-order traversal, Postorder traversal

What are adjacent nodes in a graph?

Any two nodes which are connected by an edge in a graph are called adjacent nodes.

What is a function parameter in C++?

A variable declared in the prototype or declaration of a function.

List four Storage Classes in C++.

  1. Global variables
  2. Local variables
  3. Register variables
  4. Static variables

Why is it necessary to overload an operator in C++?

To define a new relation task to an operator and specify its meaning in relation to the class to which the operator is applied.

Write a C++ code to swap two variables using reference variables in a function.

#include using namespace std; void swap(int &a, int &b) { int temp = a; a = b; b = temp; }

What are the two most common ways to represent a graph?

Adjacency Matrix and Adjacency List

How is a node represented in a tree data structure?

A node in a tree data structure is represented using a struct with a data field and pointers to its child nodes.

What are the differences between merge sort and quick sort?

Merge sort is a stable sorting algorithm with a time complexity of O(n log n), while quick sort is an unstable sorting algorithm with a time complexity of O(n log n) on average.

What are the two types of graph traversal algorithms?

Breadth First Search (BFS) and Depth First Search (DFS)

Study Notes

Binary Tree

  • A node in a binary tree can have a maximum of two children.
  • A binary tree is represented using nodes and edges, where each node has a value and at most two children (left and right).

Graph Traversal

  • Adjacent nodes in a graph are nodes that are connected by an edge.
  • There are two main types of graph traversal algorithms: Breadth-First Search (BFS) and Depth-First Search (DFS).

C++ Programming

  • A function parameter in C++ is a variable declared in the function declaration that receives a value when the function is called.
  • There are four storage classes in C++: Automatic, Register, Static, and Extern.
  • Operator overloading is necessary in C++ to allow operators to work with user-defined data types, such as classes and structures.

Swapping Variables

  • Here is a C++ code to swap two variables using reference variables in a function:
void swap(int &a, int &b) {
    int temp = a;
    a = b;
    b = temp;
}

Graph Representation

  • The two most common ways to represent a graph are: Adjacency Matrix and Adjacency List.

Tree Data Structure

  • A node in a tree data structure is represented by a data value and a set of child nodes.

Sorting Algorithms

  • Merge sort and quick sort are two popular sorting algorithms that differ in their approach:
    • Merge sort: divides the array into smaller chunks, sorts each chunk, and then merges them.
    • Quick sort: selects a pivot element, partitions the array around it, and then recursively sorts the subarrays.

Learn about the definition and representation of a binary tree, where each node can have at most 2 children named left and right child. Understand the parts of a binary tree node including data, pointer to the left child, and pointer to the right child.

Make Your Own Quizzes and Flashcards

Convert your notes into interactive study material.

Get started for free
Use Quizgecko on...
Browser
Browser