Posts

Showing posts from March, 2020

Hash Table and Binary Tree

Image
Hash Table Hash table is a data structure which stores data in an associative manner. Data is stored in an array format in a hash table, where each data has a unique index value. Thus, the insertion and search of a data can be done in a very short period of time, provided we know the index beforehand. These indexes can be found using a technique dubbed Hashing . Hashing            Hashing is a technique to convert certain key values from a data to a range of indexes for an array. There are many ways to hash, the simplest ones include taking the value of key then divide them by the number of available addresses, and take the remainder.             The above code does exactly what the example did. However, one can clearly see a problem with it. If 2 keys result in the same hash, then the first hash will be replaced by the second and so on. This phenomena is ca...

Stack and Queue in Data Structures

Image
Stack In Data Structure, a stack is defined as a linear structure in which certain order of operations are performed. The aforementioned operators will most likely include:        Push : The addition of an item to a stack. If the stack is full, an Overflow condition is ruled        should you use the push operator on it.     Pop : The removal of an item from a stack. If the stack is empty, an Underflow condition is        ruled should you use the pop operator on it.         Peek/Top : Returning the top element of a stack.        isEmpty : Checking whether or not a stack is empty. In a stack, this order can either be LIFO (Last In First Out) or FILO (First In Last Out) because they are basically the same things. LIFO or FILO basically means that, in a list of items, the last one to be added will be taken out first. An example of this would be a sta...

Linked List

Image
Doubly Linked List Doubly linked list (DLL) is a type of linked list in which each node apart from storing its data has two links. The first link points to the previous node in the list and the second link points to the next node in the list. The first node of the list has its previous link pointing to NULL similarly the last node of the list has its next node pointing to NULL. Advantages vs singly linked list A DLL can be traversed in both forward and backward direction. The delete operation in DLL is more efficient if pointer to the node to be deleted is given. We can quickly insert a new node before a given node. In singly linked list, to delete a node, a pointer to the previous node is needed. To get this previous node, sometimes the list is traversed. In DLL, we can get the previous node using the “ previous ” pointer. Disadvantages vs singly linked list Every node of DLL require extra space for a previous pointer All operations require the “previous”...