Posts

Showing posts from March, 2020

Summary

Linked List Linked lists can be thought of as dynamic arrays which means that the size does not need to be specified and can keep growing as long as we still have memory in our RAM. A linked list consist of a node, which is just like a single block of memory in an array, and in the node we can store data. The node also consist of a 'next' pointer which points to the next node in the linked list. The next pointers are essentially what connects the linked list together. In a doubly linked list, we have an extra 'prev' pointer which points to the previous node in the linked list. We also need a head pointer which points to the first node of the linked list. We can also use a tail pointer which points to the last node of the linked list, but this is optional. A linked list contains of several operations such as, push head, push tail, insert after, delete, print and many more. Here is a program which contains several of those operations: Stack A stack is the...

Binary Search Tree

Image
Binary Search Tree Theory Why do we use BST (Binary Search Tree) for storing data? Well, BST allows for faster searching and sorting, insertion and deletion of data. This can happen because of the fundemental rules of Binary Search Trees, which are:  For every node in a BST, the left subtree of the node must contain elements which are smaller than the element stored in the node. For every node in a BST. the right subtree of the node must contain elements which are greater than the element stored in the node Therefore, traversing through a binary search will just be a matter of asking the question of greater or smaller.  Basic BST Operations Search This search algorithm will return a struct Node* datatype, this is just something that we need to keep in mind when applying this algorithm in our main function Insert Delete This deletion operation requires some sort of visualisation to fully understand, especially on line 28. Howev...

Hash Tables and Trees

Image
Hash Tables and Hashing Hashing Hashing is a technique used to store and allocate data (in a hash table array for example) by obtaining a key from the inputted data and processing it to its respective index. This hashing process through a Hash Function which has many different forms and each will spit out different results even from one key. For example, we may have a series of string such as "apple", "dog" and "cat" and we want to place this is an array of strings. Sure, we can just insert them using a For-loop and the resulting array will be : { "apple", "dog","cat"}.  Now assume we have hundreds of different strings and we one to search for the string "cat" in the array. We now have to do a linear search through the array which has the time complexity of O(n). This wouldn't be an effective method of storing and searching data if we have a large amount of data stored. A way to make the time...