Posts

Binary Search Tree

Image
Binary Search Tree Binary Search Trees (BST), biasanya disebut ordered atau sorted binary trees, ini sebuah kontainer, sebuah data struktur yang menyimpan item seperti angka ataupun nama. BST adalah binary tree yang rooted, yang dimana internal nodes menyimpan sebuah kunci, dan satu kunci ada 2 sub trees, yang biasanya disebut left and right. Code: // C function to search a given key in a given BST struct node* search( struct node* root, int key) {      // Base Cases: root is null or key is present at root      if (root == NULL || root->key == key)         return root;             // Key is greater than root's key      if (root->key < key)         return search(root->right, key);          // Key is smaller than root's k...

Hashing & Binary Tree

Image
Hashing Data Structure Hashing is an important Data Structure which is designed to use a special function called the Hash function which is used to map a given value with a particular key for fster access of elements. Example: list of values are [11,12,13,14,15] it will be stored at index {1,2,3,4,5} apart from the regular starting from 0. An example of hash table. Given a limited range array contains both positive and non-positive numbers. Since range is limited, we can use index mapping (or trivial hashing). We use values as the index in a big array, therefore we can search and insert elements in O(1) time. Binary Tree Unlinke arrays, linked lists, stack and queues, which are linear data structures, trees are hierarchical data structures. The topmost node is called a root of the tree, elements that are directly under an element are called its children so to speak. Why do we use binary trees in our data structure? the first reason is to you want to store info...
Image
Single Linked List adalah sekumpulan dari node yang saling terhubung dengan node lain menggunakan sebuah pointer. Rangkaian linked list tersebut diawali dengan sebuah head untuk menyimpan alamat awal dan di akhiri dengan node yang mengarah ke NULL. Single linked list hanya memiliki satu arah dan tidak bisa kembali ke data sebelumnya.Ada juga yang bernama double linked list yang dapat mengakses data sebelumnya menggunakan pointer yang mengarah ke alamat sebelumnya. Contoh gambar single linked list: Di dalam linked list ada juga yang disebut dengan push, yaitu mendorong sebuah value ke dalam node yang terhubung tersebut. Dibagi dua menjadi push depan dan push belakang. contoh kodingan push depan dan push belakang adalah sebagai berikut. void pushHead(int n){ struct node *temp = (struct node*)malloc(sizeof(struct node*)); if(head == NULL){ temp->nilai = n; temp->next = NULL; head = temp; tail = temp; } else { temp->next = head; temp->n...