Data structures binary search trees flashcards
This set of flashcards covers essential concepts and terminology related to binary search trees in computer science, focusing on their structure, operations, and applications.
Quiz(24 questions)
1. What is the primary property of a binary search tree (BST)?
Terms in this Study Set(24)
Flashcards 1(12)
What is a binary search tree?
A binary search tree (BST) is a data structure that maintains sorted data. Each node has at most two children. Left child < Node < Right child.
True or False: BSTs can have duplicate values.
False. BSTs do not allow duplicate values to maintain unique paths.
How do you find a value in a BST?
Start at the root, compare the value. If less, go left; if more, go right. Repeat until found or null.
What is the time complexity for searching in a BST?
Average case: , Worst case: when unbalanced.
Complete the sentence: The height of a balanced BST is...
...approximately , where is the number of nodes.
What are the benefits of using a BST?
- Fast search, insert, delete operations - Dynamic size - Ordered data access
Compare BST and arrays for searching.
BST: average search time. Array: average search time. BST requires more memory.
Fill in the blank: The in-order traversal of a BST outputs...
...the values in ascending order.
What is a leaf node in a BST?
A leaf node is a node with no children, meaning it is at the end of a branch.
True or False: All BSTs are height-balanced.
False. Some BSTs can become unbalanced, leading to poorer performance.
What is the purpose of rotations in BSTs?
To maintain balance during insertions and deletions, ensuring optimal search times.
Demonstrate inserting 5 into a BST with root 3:
1. Start at 3 (root). 2. 5 > 3, go right. 3. Right is null, insert 5 there.
Flashcards 2(12)
What is a balanced binary search tree?
A tree where the height is minimized to ensure efficient operations. Common types include AVL trees and Red-Black trees.
True or False: BSTs can have duplicate values.
False. In a standard binary search tree, each value must be unique to maintain order.
Insert 15, 10, 20 in order.
Resulting BST: 15 as root, 10 left of 15, and 20 right of 15.
What does the 'height' of a tree represent?
The number of edges in the longest path from the root to a leaf.
Fill in the blank: The time complexity for searching in a balanced BST is ____.
O(log n), where n is the number of nodes.
Comparison: BST vs. Array for search operations.
BST: O(log n) average time; Array: O(n) average time. BST is more efficient when data is dynamic.
What is the worst-case scenario for BST operations?
When the tree becomes skewed, resembling a linked list, leading to O(n) time complexity.
Cause → Effect: Unbalanced BST.
Causes inefficient operations, increasing time complexity to O(n) for search, insert, and delete.
What is a leaf node?
A node that has no children. It represents the end of a path in the binary search tree.
Delete node with one child: Example.
To delete node 10 with child 5: Replace 10 with 5. Tree remains valid.
True or False: All BSTs are binary trees.
True. Every binary search tree is a type of binary tree.
What are inorder traversal results?
The output of visiting nodes in ascending order. E.g. for 10, 15, 20: output is 10, 15, 20.
Questions in this Study Set(24)
1. What is the primary property of a binary search tree (BST)?
2. What is the primary purpose of a balanced binary search tree?
3. Which of the following is true about duplicate values in a BST?
4. Which statement about duplicate values in a binary search tree is correct?
5. If you are searching for a value in a BST and the value is less than the current node's value, what is the next step?
6. If you insert 30, 20, and 40 in that order into a BST, what will the structure look like?
7. What is the worst-case time complexity for searching in an unbalanced BST?
8. What does the height of a binary search tree indicate?
9. How is the height of a balanced BST related to the number of nodes, n?
10. Fill in the blank: The time complexity for insertion in a balanced BST is ____.
11. Which benefit is NOT associated with using a BST?
12. When comparing search operations, which is the correct time complexity for a binary search tree versus an unsorted array?
13. When comparing average search times, how do BSTs and arrays differ?
14. What is the worst-case scenario for operations in a binary search tree?
15. In an in-order traversal of a BST, what is the resulting order of the node values?
16. What effect does having an unbalanced BST have on operations?
17. What characterizes a leaf node in a binary search tree?
18. Which of the following describes a leaf node in a binary search tree?
19. Which statement about height-balanced BSTs is false?
20. How do you delete a node with one child from a BST?
21. What is the main purpose of performing rotations in a BST?
22. True or False: All binary search trees are a type of binary tree.
23. If you want to insert a value of 7 into a BST with a root of 4, where would you place it?
24. What is the result of an inorder traversal of a BST?
Related Study Sets
Informatyka studia – Algorytmy i struktury danych
Hashing Kollisionsauflösung Prüfungsfragen
Minimaler Spannbaum Kruskal Prim Klausurvorbereitung
AVL-Bäume Rotationen Klausurvorbereitung
Sortieren einfach erklärt Karteikarten
Breitensuche und Tiefensuche Definitionen
Heap und Heapsort Karteikarten
Mergesort und Quicksort Laufzeit Definitionen
Create Your Own Study Set
Upload a PDF, paste your notes, or describe a topic – AI generates flashcards, quizzes and more in seconds.

