What types of balanced search trees you know? There are several types of balanced search trees, including



Yüklə 12,24 Kb.
tarix24.12.2023
ölçüsü12,24 Kb.
#192182
1-14


  1. What types of balanced search trees you know?

There are several types of balanced search trees, including:
AVL Trees (Adelson-Velsky and Landis Trees) - It's the first self-balancing binary search tree.
Red-Black Trees - It's a type of self-balancing binary search tree and is one of the most widely used balanced search trees. ties such as the property that no red node has a red parent.
Splay Trees - It's a self-balancing binary search tree that balances by moving frequently accessed elements to the root of the tree.

  1. What is the difference between AVL tree and binary search tree?

AVL trees are a type of self-balancing binary search tree, while binary search trees do not maintain balance.

  1. What is the advantage of binary search trees?

Binary Search Trees (BSTs) have several advantages including:
Time efficiency: BSTs allow for fast search, insertion, and deletion operations with an average time complexity of O(log n), where n is the number of nodes in the tree.
Space efficiency: BSTs use a dynamic data structure, so they only use as much memory as needed to store the data.
Sorted data: BSTs store data in a sorted manner, which makes it easier to perform operations like finding the minimum or maximum value in the tree.
Flexibility: BSTs can be used to implement other data structures such as sets, maps, and priority queues.

  1. Given a perfect binary tree of height n, how much time is required to visit all its leaves?

In a perfect binary tree of height n, there are 2^n leaves. To visit all the leaves of such a tree, you need to start from the root node and traverse the tree level by level, visiting all the leaves at each level before moving on to the next level.
The time complexity for visiting all the leaves in a perfect binary tree of height n is O(n), where n is the height of the tree. This is because at each level, you visit all the nodes at that level before moving on to the next level. The height of the tree is proportional to the logarithm of the number of nodes in the tree, so the time complexity is O(log n), where n is the number of nodes in the tree.
Note that this assumes that visiting each node takes constant time. In practice, the actual time to visit all the leaves would depend on the specific implementation and the amount of processing required for each node.

  1. Depth‐first search vs. breadth‐first search: advantages and limitations

DFS is space-efficient and useful for finding paths, but doesn't guarantee an optimal solution. BFS finds the shortest path and is faster for large graphs, but requires more memory.

  1. How can we compare between two algorithms written for the same problem?

Two algorithms can be compared by measuring their performance in terms of time complexity (execution time) and space complexity (memory usage). The algorithm with the better time and space complexity is generally considered to be more efficient and better suited for the problem

  1. . What is complexity of time (space)?

Time complexity refers to the amount of time an algorithm takes to complete its task as a function of the size of the input. Space complexity refers to the amount of memory an algorithm requires to complete its task as a function of the size of the input.

  1. What do you understand by time/space in the Worst case and Best case? 

Worst-case time/space complexity refers to the maximum amount of time/memory an algorithm may need to complete its task for any input of a given size. Best-case time/space complexity refers to the minimum amount of time/memory an algorithm may need to complete its task for any input of a given size.

  1. What are few of the most widely used sorting algorithms? 

Some of the most widely used sorting algorithms are: Quick sort, Merge sort, Bubble sort, Insertion sort and Heap sort.

  1. Complexity of various sorting algorithms: BubbleSort, MergeSort, QuickSort. 

The time complexity of BubbleSort, MergeSort, and QuickSort is as follows:
BubbleSort: O(n^2) in the worst case, O(n) in the best case (already sorted array).
MergeSort: O(nlogn) in both the worst and best cases.
QuickSort: O(n^2) in the worst case, O(nlogn) in the average case, and O(n) in the best case (already sorted array).
Note: n is the number of elements in the array being sorted.

  1. What is greedy algorithm? Give an example of greedy algorithm?

A greedy algorithm is a mathematical optimization approach that makes a series of locally optimal choices, with the hope of finding a global optimal solution. An example of a greedy algorithm is the activity selection problem, where given a set of activities with start and finish times, the goal is to find the maximum number of non-overlapping activities that can be performed. The algorithm makes a greedy choice by selecting the activity with the earliest finish time at each step.

  1. What is HEAP data structure? How it differs from binary search tree? 

A heap is a type of tree-based data structure that satisfies the heap property, where the parent node is either greater than or equal to (for a max-heap) or less than or equal to (for a min-heap) its children. A binary search tree, on the other hand, is a type of tree where the value of each node is greater than or equal to all nodes in its left subtree and less than or equal to all nodes in its right subtree. The main difference between a heap and a binary search tree is the heap property and the fact that a binary search tree allows for efficient searching and sorting of elements, whereas a heap only allows efficient access to the maximum (for a max-heap) or minimum (for a min-heap) element.

  1. What is HASH table? Give example of use of this data structure.

A hash table is a data structure that stores key-value pairs, and uses a hash function to compute an index into an array of buckets or slots, from which the desired value can be efficiently retrieved. An example of the use of a hash table is an implementation of a dictionary, where keys are words and values are definitions, and a hash function is used to map each word to a unique index in an array. This allows for efficient lookups of definitions based on words.

  1. What is STACK? How it differs from QUEUE data structure? Give examples of the use 

A stack is a LIFO data structure, a queue is a FIFO data structure. Examples of stack use include undo in text editors, function call tracking. Examples of queue use include printer queues, modeling lines.
Yüklə 12,24 Kb.

Dostları ilə paylaş:




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©azkurs.org 2024
rəhbərliyinə müraciət

gir | qeydiyyatdan keç
    Ana səhifə


yükləyin