Skip to main content

Posts

Showing posts from March, 2020

Binary Search Tree (BST)

Binary Search Tree or also known as Ordered or Sorted Binary Tree is a type of data structure that store a value like a tree. A Binary Search Tree allow fast searching, adding, and deleting node. This is cause by The Binary Search Tree keep their node in a sorted order so that searching can be done using the binary search method without the additional Sorting needed because it is already sorted by nature. Operation 1. Searching : First and foremost we check if the tree is empty or not. If the tree is empty then the process is cancelled but if the tree is not empty then we check if our key is greater or less then the root key. If it's greater then our node lies in the right subtree and vice versa. This operation can be done in a recursive or iterative way. //A function that is used to search a node in the BST Node *search(Node *root, int val){ //base case //if the tree is empty or the value is at the root if(root==NULL || root->value==val){ return ro...

Hash Table

Hash Table  Hash table kind of data structure that use an associative array, meaning that a hash table can map a value to a certain index/key. Usually this will use a hash function to find out to index/key of a certain value. Hash Table is used speed up searching so that it can reach O(n). In hash table we will find two new term such as : Collision : Is where our hash function generate the same key for two different value. Usually such collision will be handled with some kind of collision handling in the code. Hash Function : A function that will generate key for a value. Hash Function A hash function is usually used to find out the key or index of a certain value. This key will be sued to insert our data into the table. Also there is no hash function that will not generate any collision, meaning that our code will have to be able to handle collision. There are many method that can be used to generate hash key : Division : a Mod b (a is our value, b is the size of ou...
Stack & Queue Stack Stack is type of data structure that store it's data in an orderly manner. Data in stack can only be removed and added from one end of the data. This is called LIFO (Last in First Out) Meaning that the last data that enter will be the first one to be removed. Stack can be implemented with array or linked list. Stack is usually used in backtracking algorithm and also used when making a recursive function (Depth First Search). Queue Queue is also a type of data structure but it's main difference from stack is that in queue data can only be added from behind and data can only be removed from the front of the queue just like a real life queue. This is called FIFO (First In First Out) meaning that the first data that is inserted will be the one that is removed first. Also like stack queue can be implemented with array or linked list. Now queue is used in an algorithm called Breath First Search. Queue also have another type called Circular Que...
Linked List Linked List a sequence of data structure connected together via links. In C a list is usually composed of multiple type of data so we usually use struct so that we can insert multiple amount of data into a single list, also our list also contain a reference(pointer in C) to the next list. So because of this reference our list linked to one another and that is also why this is called linked list. Also in linked list there is another reference that is Head and Tail . Head point to the first list in our linked list and Tail point to the last of our list in the linked list. Now Linked List usually have 2 type that is : 1. Single Linked List 2. Double/Doubly Linked List Single Linked List A single linked list have only one reference that is a reference to the next list. So we could think that a single linked list is like an array.  As seen a single linked list only contain one reference that point to the next list. Also in our tail the next poin...