Posts

Showing posts from March, 2020

Hasing and Hash Table

Image
Hashing      Hashing is an important Data Structure that is designed to use a special function called the Hash function which is used to map a given value with a particular key for faster access of elements. The efficiency of mapping depends on the efficiency of the hash function used.      In hashing, a string of characters is transformed into a shorter length value or key that represents the original string. Hash Table      Hash table is a table (array) where we store the original string. The index of the table is the hashed key while the value is the original string.  Hash Function      A hash function is any function that can be used to map data of arbitrary size to fixed-size values. The values returned by a hash function are called hash values, hash codes, digests, or simply hashes. The values are used to index a fixed-size table called a hash table.      A good hash function shoul...

Stack and Queue

Image
  Stack     A stack is a linear data structure that follows a particular order in which the operations are performed. The order may be LIFO(Last In First Out) or FILO(First In Last Out). Stack has two fundamental operations which are push and pop.      A real-life example of a stack is when you stack a plate on top of each other.  The plate which is at the top is the first one to be removed and  the plate which has been placed at the bottommost position remains in the stack for the longest time. So, it can be seen to follow LIFO(Last In First Out) or FILO(First In Last Out) order. Stacks are widely used to: Reverse the order of data Convert infix expression into postfix Convert postfix expression into infix Backtracking problem System stack is used in every recursive function Converting a decimal number into its binary equivalent Stack operations push(x): add item x to the top of the stack pop(): remove an item from the...

Linked List

Image
     A linked list is a linear data structure, in which the elements are not stored at contiguous memory locations. The elements in a linked list are linked using pointers as shown in the below image:      A linked list consists of nodes where each node contains a data field and a reference to the next node in the list. Linked List VS Array - Array:      a) Linear collection of data elements       b) Store value in consecutive memory locations      c) Can be random in accessing of data - Linked List:      a) Linear collection of nodes       b) Doesn't store its nodes in consecutive memory locations       c) Can be accessed only in a sequential manner Types of Linked List 1. Single Linked List 2. Double/Doubly Linked List 3. Circular Single Linked List 4. Circular Doubly Linked List