<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: MohamedHarmoush</title>
    <description>The latest articles on DEV Community by MohamedHarmoush (@mohamedharmoush).</description>
    <link>https://dev.to/mohamedharmoush</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F612828%2Fa29bd480-6563-4b48-b668-855f9362fdbf.png</url>
      <title>DEV Community: MohamedHarmoush</title>
      <link>https://dev.to/mohamedharmoush</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mohamedharmoush"/>
    <language>en</language>
    <item>
      <title>HashTable Data Structure</title>
      <dc:creator>MohamedHarmoush</dc:creator>
      <pubDate>Wed, 23 Mar 2022 15:58:51 +0000</pubDate>
      <link>https://dev.to/mohamedharmoush/hashtable-data-structure-4o3m</link>
      <guid>https://dev.to/mohamedharmoush/hashtable-data-structure-4o3m</guid>
      <description>&lt;p&gt;In the next few posts, I'll be talking about some data structures&lt;/p&gt;

&lt;p&gt;======================================&lt;/p&gt;

&lt;p&gt;Today, I'll be talking about &lt;br&gt;
 and how we can implement it from scratch using Java.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Hash table → data structure lets us construct a mapping from keys to values via a technique called "hashing"&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Hashing → is a technique that retrieves the value using the index obtained from a key without performing a search.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Each Hash table contains:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Array to hold data.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Hash function (is a function that maps a key 'x' to an index in a fixed range)&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Type of hash functions:
&lt;/h2&gt;

&lt;p&gt;→ There are various types of hash functions in the data structure:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Division Hash Function (h(k) = k mod m )&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;k → key, m → hash table size&lt;/p&gt;

&lt;p&gt;ex: h(1276) = 1276 mod 10 = 6&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Multiplication Method ( h(k) = floor( n( kA mod 1 ) ) )&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;k → key and A → can be any constant value between 0 and 1, n → hash table size&lt;/p&gt;

&lt;p&gt;ex: n = 4, a = 0.568, key = 56 ,&lt;/p&gt;

&lt;p&gt;h(56) = floor( 4 * ((560.568) mod 1)) = floor (4 (31.808 mod 1))&lt;/p&gt;

&lt;p&gt;= floor (4 * 0.808) = floor(3.232) = 3&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Mid Square Hash Function (h(K) = h(k x k)) → squaring the value of the key and then extracting the middle r digits as the hash value&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;ex: k = 50 , k*k = 2500, r = 2&lt;/p&gt;

&lt;p&gt;h(50) = 50 , then the hash value obtained is 50&lt;/p&gt;

&lt;h2&gt;
  
  
  The characteristic of a good hash function:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;It should be easy to compute.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;It reduces the chance of collisions.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A hash collision is when two objects x, y hash to the same value (i.e. H(x) = H(y)).&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It should guarantee an even distribution of the values.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Example:&lt;/p&gt;

&lt;p&gt;Consider an example of hashtable of size 4, Item are in (key,value) format.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;(1 ,20)  =&amp;gt; key → 1   , hash = 1   % 4 = 1 ,  array index → 1&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;(2 ,70)  =&amp;gt; key → 2   , hash = 2   % 4 = 2 ,  array index → 2&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;(3,36)   =&amp;gt; key → 3   , hash = 3   % 4 = 3 ,  array index → 3&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;(42,80) =&amp;gt; key → 42 , hash = 42 % 4 = 2 ,  array index → 2&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;(4,25)   =&amp;gt; key → 4   , hash = 4   % 4 = 0 ,  array index → 0&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Hash collisions happened in &lt;/p&gt;

&lt;p&gt;(2 ,70) , (42,80)  hashed to index → 2&lt;/p&gt;

&lt;p&gt;What do we do if there is a hash collision?&lt;/p&gt;

&lt;p&gt;We use one of many hash collision resolution techniques to handle this&lt;/p&gt;

&lt;h2&gt;
  
  
  Hash collision resolution techniques:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Separate chaining (Open Hashing)&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Deals with hash collisions by maintaining a data structure (usually a linked list) to hold all the different values which hashed to a particular value.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;Open addressing (Closed Hashing)&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Deals with hash collisions by finding another place within the hash table until an empty bucket is found.&lt;/li&gt;
&lt;li&gt;There are various methods to find these empty buckets:

&lt;ul&gt;
&lt;li&gt;Linear Probing&lt;/li&gt;
&lt;li&gt;Quadratic Probing&lt;/li&gt;
&lt;li&gt;Double Hashing&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In the attached images you'll find a two different implementations of HashTables without handling the hash collisions.&lt;/p&gt;

&lt;p&gt;Next post I'll be talking about how to handle the hash collisions.&lt;/p&gt;

&lt;p&gt;Github: shorturl.at/fvAOZ&lt;/p&gt;

&lt;h2&gt;
  
  
  Resources:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;shorturl.at/gnvN2&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;shorturl.at/gvwAV&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;shorturl.at/djG24&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;shorturl.at/hvzL5&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  datastructures #java #github
&lt;/h1&gt;

</description>
    </item>
    <item>
      <title>Quick Introduction to types of SQL Statements</title>
      <dc:creator>MohamedHarmoush</dc:creator>
      <pubDate>Mon, 18 Oct 2021 10:54:06 +0000</pubDate>
      <link>https://dev.to/mohamedharmoush/types-of-sql-statements-27aj</link>
      <guid>https://dev.to/mohamedharmoush/types-of-sql-statements-27aj</guid>
      <description>&lt;h3&gt;
  
  
  Types of SQL Statements
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;DDL – Data Definition Language&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Used to define Database (creating or modifying) objects like Table, View, Index, Sequence&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Commands ⇒ CREATE, ALTER, DROP, TRUNCATE, RENAME&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Samples&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;CREATE TABLE STUDENTS (&lt;br&gt;
          ID INT NOT NULL PRIMARY KEY, &lt;br&gt;
          Name VARCHAR2(10), &lt;br&gt;
          Address VARCHAR2(20)&lt;br&gt;
);&lt;/p&gt;

&lt;p&gt;DROP TABLE STUDENTS;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;DML – Data Manipulation Language.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Used to manipulate the data in Database objects like Table, View, Index&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Commands ⇒ INSERT, UPDATE, DELETE&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Samples&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;INSERT INTO STUDENTS&lt;br&gt;
(ID, Name, Address)&lt;br&gt;
VALUES (1, "Mohamed Harmoush", "Alexandria, Egypt");&lt;/p&gt;

&lt;p&gt;DELETE FROM Student WHERE ID = 3&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;DRL/DQL – Data Retrieval Language/Data Query Language.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Used to retrieve information from the database objects. It is for read only purpose.&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Commands ⇒ SELECT&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Samples&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;SELECT Name, Address FROM STUDENTS&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;TCL- Transaction Control Language or TCS - Transaction Control Statement.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;TCL ⇒ manage changes made by DML statements&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Commands ⇒ COMMIT, ROLLBACK, SAVEPOINT,SET TRANSACTION&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Samples&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;DELETE FROM STUDENTS&lt;br&gt;
WHERE ID = 3;&lt;br&gt;
COMMIT;&lt;/p&gt;

&lt;p&gt;SAVEPOINT SAVEPOINT_NAME;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;DCL – Data Control Language.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In DCL, we control access to data. This is used for permission management and who can access the data.&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Commands ⇒ GRANT, REVOKE&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Samples&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;GRANT SELECT, UPDATE ON STUDENTS TO Mohamed, ANOTHER_USER;&lt;/p&gt;

&lt;p&gt;REVOKE SELECT, UPDATE ON STUDENTS FROM Mohamed, USER2;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;SCL – Session Control Language or SCS - Session Control Statement&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Session Control Statements dynamically manage the properties of a user session&lt;/li&gt;
&lt;li&gt;Commands ⇒ ALTER SESSION, SET ROLE&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;




&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Useful Resources:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://way2tutorial.com/sql/type-of-sql-statements.php"&gt;https://way2tutorial.com/sql/type-of-sql-statements.php&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.javatpoint.com/dbms-sql-command"&gt;https://www.javatpoint.com/dbms-sql-command&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.c-sharpcorner.com/blogs/types-of-sql-statements-with-example"&gt;https://www.c-sharpcorner.com/blogs/types-of-sql-statements-with-example&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.guru99.com/sql-commands-dbms-query.html"&gt;https://www.guru99.com/sql-commands-dbms-query.html&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>sql</category>
      <category>database</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
