Showing posts with label 2-3 Search Trees. Show all posts
Showing posts with label 2-3 Search Trees. Show all posts

November 24, 2019

#Algorithms Part 1: Graphs, BFS,DFS, Dijkstra Algorithm, Bellman-Ford Algorithm

Graph Traversal
  • Its the process of visiting and exploring a graph for processing.
  • In this we visit and explore each vertex and edge in a graph such that all the vertices's are explored exactly once.
  • Visiting a node means selecting a node, where as exploring means exploring the children nodes of the node which we have visited.
Breadth First Search
  • Its an algorithm for traversing trees and graphs.
  • In BFS we start with the root node, explores all sibling nodes before moving on to the next level of siblings.
  • Queue is the main data structure which is used while performing BFS.
  • BFS is used as a crawlers in web-engines. It is the main algorithm which is used for indexing the web pages, it starts from the source page and follows all the links associated with that page. In this case each link is considered as a node in the graph.
  • BFS is also used in GPS navigation to find the neighboring locations.
  • BFS is also used in finding the shortest path

Binary Search Trees, Balance Search Trees, 2-3 ST, Red- Black BST

Tree Data Structure
  • If we compare sorted arrays with linked list: Search is fast in SA (O(logn)) and slow in LL (O(n)), but insert & delete is slow in SA (O(n)) and fast in LL (O(1)).
  • Binary search trees are very balanced in the sense that all these common operations like insert, delete, and search take about the same time (log n).
  • In Binary search trees we have the nodes, which contain the data. Nodes are connected to other nodes through edges. The top node of the tree is called the root node (in a tree data structure, there can only be one root node).
  • A node which has no children is called a leaf node. 
  • Any node may be considered to be the root of a subtree, which consists of its children and its children's children and so on. The level of a node tells us how far it is from the root.