<?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: steve kimoi </title>
    <description>The latest articles on DEV Community by steve kimoi  (@stephenkimoi).</description>
    <link>https://dev.to/stephenkimoi</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%2F880290%2F965835d4-9504-4b50-a852-29c59468d0e3.png</url>
      <title>DEV Community: steve kimoi </title>
      <link>https://dev.to/stephenkimoi</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/stephenkimoi"/>
    <language>en</language>
    <item>
      <title>WHAT IS THE DIFFERENCE BETWEEN PROOF OF WORK AND PROOF OF STAKE?</title>
      <dc:creator>steve kimoi </dc:creator>
      <pubDate>Sat, 07 Jan 2023 13:08:31 +0000</pubDate>
      <link>https://dev.to/stephenkimoi/what-is-the-difference-between-proof-of-work-and-proof-of-stake-2cme</link>
      <guid>https://dev.to/stephenkimoi/what-is-the-difference-between-proof-of-work-and-proof-of-stake-2cme</guid>
      <description>&lt;p&gt;&lt;strong&gt;Proof of Work (PoW)&lt;/strong&gt; and &lt;strong&gt;Proof of Stake (PoS)&lt;/strong&gt; are both &lt;strong&gt;consensus mechanisms&lt;/strong&gt; that help keep the blockchain secure and add new transactions on the blockchain.  &lt;/p&gt;

&lt;p&gt;A &lt;strong&gt;consensus mechanism&lt;/strong&gt; is a way in which the nodes agree on the authenticity of transactions that have been recorded in the blockchain.  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Proof of Work (PoW)&lt;/strong&gt;: this is a consensus mechanism whereby nodes (computers) compete to be the first to solve a complex computational problem (try to guess the “hash” number) for them to come up with new blocks and add them on the blockchain. The miner who comes up with the block is then awarded with new coins. Check out my blog on Mining (PoW) &lt;a href="https://dev.to/stephenkimoi/what-is-mining-in-blockchain-47mm"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Proof of Stake (PoS)&lt;/strong&gt;: this is a consensus mechanism whereby a node ‘stakes’ a certain amount of the native cryptocurrency for them to validate transactions and create new blocks. This crypto that they’ve staked acts as collateral for them to participate as validators. The chances of a node being selected as a validator depend on the amount they’ve staked. Once the validator is choosen to come up with the new block, they are awarded a portion of the gas fees (transaction fees).  &lt;/p&gt;

&lt;p&gt;The purpose of introducing proof of stake was to combat environmental challenges that were being caused by Proof of Work.  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The differences between proof of work and proof of stake are:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;em&gt;In PoS the block creators are known as validators&lt;/em&gt;: they check the transactions, verify the activity, vote on outcomes and maintain records. &lt;/li&gt;
&lt;li&gt;
&lt;em&gt;In PoW the block creators are known as miners&lt;/em&gt;: the miners work to solve for the “hash”, then they are awarded with a coin. &lt;/li&gt;
&lt;li&gt;&lt;p&gt;In PoS for you to become a validator, you &lt;em&gt;only need to own enough tokens or coins to stake&lt;/em&gt;. The use of stake promotes:&lt;br&gt;&lt;br&gt;
I) Decentralization: this is because validators are chosen according to their stake in the network rather than computational power. It ensures decentralization since you do not need high computational power to participate as a validator.&lt;br&gt;&lt;br&gt;
II) Security: since the validators have a financial stake in the network, they will act in the best interests of the network. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In PoW &lt;em&gt;for you to become a miner, you must invest in equipment and energy to power the computers solving the computations&lt;/em&gt;.  This makes PoW less accessible to individual users and more dominated by large mining pools with access to economies of scale.  &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;PoS systems are more energy efficient as compared to PoW&lt;/em&gt;, this is because you need less computational power as compared to PoW systems.  &lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;One of the downsides of PoS is that an entity or a group of people can decide to acquire a significant portion of total stake in the network, thus causing some form of “centralization”. Which can enable them to have a level of influence on the network, as they will have a greater probability of being chosen as validators therefore having more opportunity to earn rewards.  &lt;/p&gt;

&lt;p&gt;However, there are mechanisms that are in place to prevent validators from acting maliciously against the best interest of the network e.g slashing.&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Slashing&lt;/strong&gt; is a mechanism where validators who might have violated the rules of the network have a portion of their stake confiscated. &lt;/p&gt;

&lt;p&gt;Thread version of this article can be found at: &lt;br&gt;
&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;WHAT IS THE DIFFERENCE BETWEEN PROOF OF WORK AND PROOF OF STAKE?&lt;br&gt;&lt;br&gt;The terms Proof of Work(PoW) and Proof of Stake(PoS) tend to be confusing a times if you are new in the blockchain ecosystem. &lt;br&gt;&lt;br&gt;What do they mean in simple definitions and what are their differences? Let’s see &lt;a href="https://t.co/MC4emtspqC"&gt;pic.twitter.com/MC4emtspqC&lt;/a&gt;&lt;/p&gt;— steve.eth (@stevekimoi) &lt;a href="https://twitter.com/stevekimoi/status/1611712253266370562?ref_src=twsrc%5Etfw"&gt;January 7, 2023&lt;/a&gt;
&lt;/blockquote&gt; 

&lt;p&gt;Thank you. Don't forget to check the rest of my &lt;a href="https://dev.to/stephenkimoi"&gt;blogs&lt;/a&gt; if you'd like to learn more about blockchain and web3!&lt;/p&gt;

&lt;p&gt;Cover image by &lt;a href="https://bitpay.com/"&gt;bitpay&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>WHAT IS MINING IN BLOCKCHAIN?</title>
      <dc:creator>steve kimoi </dc:creator>
      <pubDate>Fri, 23 Dec 2022 15:45:20 +0000</pubDate>
      <link>https://dev.to/stephenkimoi/what-is-mining-in-blockchain-47mm</link>
      <guid>https://dev.to/stephenkimoi/what-is-mining-in-blockchain-47mm</guid>
      <description>&lt;p&gt;Have you ever heard the term "mining" in the context of blockchain and thought it had something to do with extracting cryptocurrency from the earth? While that may sound funny, the concept of mining in blockchain is quite important and complex.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Mining in blockchain refers to two main processes:&lt;/strong&gt; &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;It is the process by which new transactions are verified and added to the blockchain.
&lt;/li&gt;
&lt;li&gt;It is the process by which new “digital coins” are created through a process called Proof of Work(PoW).
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;So how does mining work?&lt;/strong&gt; &lt;br&gt;
The process of mining usually involves a A decentralized network of specialized computers, known as "miners," compete to verify and record new transactions on the blockchain. The first miner to solve a complex cryptographic puzzle and provide the correct 64-digit hexadecimal number (called a "hash") is rewarded with new coins. The verified transactions are then added to the blockchain as a new block. &lt;/p&gt;

&lt;p&gt;The process of mining can be resource-intensive, as it requires a lot of computational power to solve cryptographic puzzles. Miners often use specialized hardware, such as application-specific integrated circuits (ASICs) or graphics processing units (GPUs), to increase their chances of solving the puzzles and earning rewards. &lt;/p&gt;

&lt;p&gt;The rewards for mining are not just limited to new coins. Miners also receive transaction fees (gas fees) from users who want their transactions to be included in the next block. These fees incentivize miners to prioritize and include the transactions in their blocks. The higher the gas fee the higher the probability of your transaction being added to the block.  &lt;/p&gt;

&lt;p&gt;The process of mining is designed to be difficult, as it helps to ensure the security of the blockchain. As more miners join the network and the competition for rewards increases, the puzzles become harder to solve, requiring even more computational power. This ensures that it is not easy for attackers to manipulate the blockchain by adding fraudulent transactions. &lt;/p&gt;

&lt;p&gt;The concept of Proof of Work (PoW) is not used by all blockchain networks. Some alternative consensus algorithms, such as Proof of Stake (PoS), do not rely on mining to verify transactions and create new blocks. Instead, they use a different process, such as selecting the next block creator through a randomized "lottery" based on their stake (i.e. the amount of coins they hold) in the network. An example of a blockchain network that uses PoS is Ethereum.   &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why is mining important?&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Mining helps to decentralize the network: By allowing anyone with the necessary hardware and resources to participate in the process of mining, the blockchain becomes decentralized and not controlled by a single entity. This ensures that the network is resistant to censorship and manipulation.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Mining ensures the integrity of the blockchain: By verifying transactions and adding them to the blockchain, miners help to ensure the integrity and accuracy of the data on the blockchain. This is especially important for financial transactions, as it helps to build trust and confidence in the network. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;For cryptocurrencies like bitcoin, mining is the only way to release new coins into circulation. It also gives miners voting power in the network and verifies and secures the blockchain, allowing it to function as a decentralized network without the need for third parties.  &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Additionally, mining helps to prevent the "double spend" problem, where a single digital coin is spent twice. &lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In conclusion, mining plays a crucial role in the functioning and security of blockchain networks and is essential for the creation and circulation of new digital coins. &lt;/p&gt;

</description>
    </item>
    <item>
      <title>ACCESSING NFT SMART CONTRACT CODE</title>
      <dc:creator>steve kimoi </dc:creator>
      <pubDate>Sat, 03 Dec 2022 08:22:27 +0000</pubDate>
      <link>https://dev.to/stephenkimoi/accessing-nft-smart-contract-codes-56e6</link>
      <guid>https://dev.to/stephenkimoi/accessing-nft-smart-contract-codes-56e6</guid>
      <description>&lt;p&gt;Web3 is fascinating! Did you know that you are able to access the source code of any NFT smart contract deployed in the Ethereum network? &lt;/p&gt;

&lt;p&gt;Let's see how: &lt;/p&gt;

&lt;p&gt;The best way to view the smart contracts is through Etherscan, an Ethereum block explorer. Etherscan allows users to easily search and browse transactions and blocks. It’s like the Google of Ethereum. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_SGe105r--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6m452jgxo0s3atu4ux9j.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_SGe105r--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6m452jgxo0s3atu4ux9j.png" alt="Image description" width="300" height="168"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Go to Etherscan through &lt;a href="https://etherscan.io:"&gt;https://etherscan.io:&lt;/a&gt; This is the landing page that you’ll see: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---469c1G---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kqy4dsor2t4jr89wp2ol.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---469c1G---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kqy4dsor2t4jr89wp2ol.png" alt="Image description" width="880" height="432"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, we are going to search the smart contract of a popular NFT marketplace,&lt;a href="https://boredapeyachtclub.com/"&gt;Bored Ape Yatch Club&lt;/a&gt;. We will type in the symbol which is BAYC inside the search bar.  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--A4rC-lSg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/swe8lyobyzxef2ab9lxe.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--A4rC-lSg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/swe8lyobyzxef2ab9lxe.png" alt="Image description" width="880" height="432"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Scroll down through the filter search bar under Tokens (ERC 721).  &lt;/p&gt;

&lt;p&gt;Click on the “BoredApeYachtClub(BAYC)” and you'll be automatically redirected to the site containing the contract details.  &lt;/p&gt;

&lt;p&gt;You will immediately see this page:  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--A16OzwLs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qb8mbsp040cm06dydljy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--A16OzwLs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qb8mbsp040cm06dydljy.png" alt="Image description" width="880" height="432"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;On your far right you will see “Profile summary” containing the contract address, the official site link and the social profles.   &lt;/p&gt;

&lt;p&gt;Click on the contract address. This is the site that you’ll see:  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ERHB6WiI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sg46ctoi50ws34fe7tel.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ERHB6WiI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sg46ctoi50ws34fe7tel.png" alt="Image description" width="880" height="432"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Scroll downwards and you’ll immediately see this:&lt;br&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--5h_yyHh7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ohtos71d6v8ceilpf7j1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5h_yyHh7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ohtos71d6v8ceilpf7j1.png" alt="Image description" width="880" height="432"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Click on the contract tab that has a green tick on the right. You will be immediately redirected to this page:  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--cSaa741i--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0bkgg3tl1lhkpn3gvnof.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--cSaa741i--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0bkgg3tl1lhkpn3gvnof.png" alt="Image description" width="880" height="432"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Scroll downwards and you’ll see the smart contract code. Fascinating!&lt;br&gt;&lt;br&gt;
A practical example of decentralization in web3. &lt;/p&gt;

</description>
    </item>
    <item>
      <title>WHAT IS GAS IN THE ETHEREUM BLOCKCHAIN NETWORK?</title>
      <dc:creator>steve kimoi </dc:creator>
      <pubDate>Thu, 20 Oct 2022 12:27:49 +0000</pubDate>
      <link>https://dev.to/stephenkimoi/what-is-gas-in-the-ethereum-blockchain-network-2o94</link>
      <guid>https://dev.to/stephenkimoi/what-is-gas-in-the-ethereum-blockchain-network-2o94</guid>
      <description>&lt;p&gt;&lt;strong&gt;&lt;u&gt;GAS:&lt;/u&gt;&lt;/strong&gt;&lt;br&gt;
Gas in the blockchain ecosystem is normally compared to the gasoline that is required by a car to move.  &lt;/p&gt;

&lt;p&gt;Why do we give such a comparison, and what is gas anyway? Let's have a look: &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Gas&lt;/strong&gt;: this is the fee that is required to successfully run a transaction or execute a smart contract in the Ethereum blockchain network.   &lt;/p&gt;

&lt;p&gt;The main reason for introducing the concept of gas was:  &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;To pay the Ethereum miners for the energy they’ve used to conduct transactions. This is why it is described as the fuel that is needed to run the Ethereum network.
&lt;/li&gt;
&lt;li&gt;To provide a layer of security by making it expensive for users to spam the network.
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A lot of people hate gas fees because they can be very expensive. Why is this so?  &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;When there is a surge in activity of the network; a lot of people trying to conduct transactions at once, the gas fees usually skyrocket. This is because as more transactions occur, the blockchain needs more computational power, thus leading to the surge in gas prices.
&lt;/li&gt;
&lt;li&gt;When you’re executing a transaction that requires more computational power. Simple transactions such as a peer-to-peer transaction of sending ether, doesn’t require a lot of computational power thus it will use little gas. But complex transactions such as interacting with smart contracts will require higher gas fees.
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Now that we have an idea of what is gas, let's see at  how gas fees are calculated:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How are gas fees calculated:&lt;/strong&gt;&lt;br&gt;
Gas fees are paid in Ethereum’s native currency, ether (ETH). The gas prices are usually denoted in gwei (a denomination of ETH i.e 1 gwei = 0.000000001 ETH (10^-9 ETH).  &lt;/p&gt;

&lt;p&gt;Gas fees are usually calculated using the formular:&lt;br&gt;&lt;br&gt;
&lt;code&gt;Gas limit * Gas price per unit = Gas fees&lt;/code&gt; &lt;/p&gt;

&lt;p&gt;Gas limit is the maximum amount of gas a user can use to in a transaction.  &lt;/p&gt;

&lt;p&gt;Gas price is the the amount of ETH paid to the miners for processing the transactions.  &lt;/p&gt;

&lt;p&gt;So, if the gas limit was 30,000 and price unit was 300 gwei, the result would be:  &lt;/p&gt;

&lt;p&gt;&lt;code&gt;30,000 * 300 = 9,000,000 gwei or 0.004ETH&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;That sums it all. I hope you now have a good understanding of what gas is in the blockchain ecosystem and how it works. &lt;/p&gt;

&lt;p&gt;Thank you for reading this far!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>103: DATA STRUCTURES IMPLEMENTATION</title>
      <dc:creator>steve kimoi </dc:creator>
      <pubDate>Thu, 18 Aug 2022 11:22:00 +0000</pubDate>
      <link>https://dev.to/stephenkimoi/103-data-structures-implementation-1on6</link>
      <guid>https://dev.to/stephenkimoi/103-data-structures-implementation-1on6</guid>
      <description>&lt;p&gt;In my previous article, &lt;a href="https://dev.to/stephenkimoi/102a-deep-dive-into-data-structures-and-algorithms-1heb"&gt;102(a):Deep dive into data structures&lt;/a&gt;, I expounded more on the various types of data structures that are commonly used and theoretically explained how they are implemented.&lt;br&gt;
In this article, we will get our hands a little bit dirty by practically implementing them.&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Note:&lt;/strong&gt; &lt;br&gt;
&lt;em&gt;I’ve used python for implementation since it is human friendly thus can be understood by a vast number of people.&lt;/em&gt;&lt;br&gt;
&lt;em&gt;Link to the GitHub repository that contains the sample codes can be found in their respective sections&lt;/em&gt; &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1.Stack data structure:&lt;/strong&gt;&lt;br&gt;
As we stated earlier, stack is a data structure that follows the LIFO principle, that is, elements that get in last come out first. Any time an element is added it goes onto the top of the stack and the only element that can be removed is the element on top of the stack. It is an example of a &lt;a href="https://www.tutorialspoint.com/difference-between-linear-and-non-linear-data-structures#:~:text=A%20Linear%20data%20structure%20have,level%20and%20in%20single%20run."&gt;linear data structure&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Types of stacks:&lt;/strong&gt;&lt;br&gt;
There are two types of stacks:  &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Register stack: It is a memory element present in the 
memory unit and can handle a small amount of data only. It is small compared to memory stack.
&lt;/li&gt;
&lt;li&gt;Memory stack: It handles a large amount of memory data. It’s height is quite flexible as compared to register stack.
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Applications of stack:&lt;/strong&gt; &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Reverse a word: you can push a given word to stack letter by letter then pop letters from the stack.
&lt;/li&gt;
&lt;li&gt;Redo and undo features in places such as editors &lt;/li&gt;
&lt;li&gt;Backtracking algorithms, as it helps you come back from the previous state. This can be seen in games such as chess, finding your way through a maze e.t.c
&lt;/li&gt;
&lt;li&gt;Forward and backward features in browsers
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Implementation of stack:&lt;/strong&gt; &lt;br&gt;
Stacks can be implemented in two ways: &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Arrays&lt;/li&gt;
&lt;li&gt;Linked lists &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;a)Implementing stacks using arrays:&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_e9E8pu8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s4w336pe4zfs2p07ztsh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_e9E8pu8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s4w336pe4zfs2p07ztsh.png" alt="Implementing stacks using arrays in python" width="880" height="454"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--YrPgulpm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0guad5mlbsrxr8bayi2e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YrPgulpm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0guad5mlbsrxr8bayi2e.png" alt="Implementing stacks using arrays in python" width="767" height="329"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--DzWIMDn7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w3i61wmsymm051blhjiz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--DzWIMDn7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w3i61wmsymm051blhjiz.png" alt="Implementing stacks using arrays in python" width="767" height="329"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;output&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--jIfPz7Bx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/aj50pgg1402ld3lf7roo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--jIfPz7Bx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/aj50pgg1402ld3lf7roo.png" alt="Implementing stacks using arrays in python" width="767" height="182"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/Stephen-Kimoi/Data-Structures-and-Algorithims/blob/master/Data-structures/Stacks/array-stacks.py"&gt;Github link&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;b)Implementing stacks using linked lists:&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--cqMKia4H--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v6ek9jum29tpw4891di6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--cqMKia4H--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v6ek9jum29tpw4891di6.png" alt="Implementing stacks using linked lists in python" width="777" height="476"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--uFA3p18_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9hesgy8zxbk3fkmgk7mr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--uFA3p18_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9hesgy8zxbk3fkmgk7mr.png" alt="Implementing stacks using linked lists in python" width="780" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ZmQrotfs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r3tmpu3dn6hxb3lgfjlc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ZmQrotfs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r3tmpu3dn6hxb3lgfjlc.png" alt="Implementing stacks using linked lists in python" width="784" height="366"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--bEVnNXNb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zjbd2l65yr2vge93au2c.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--bEVnNXNb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zjbd2l65yr2vge93au2c.png" alt="Implementing stacks using linked lists in python" width="784" height="201"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Output: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--u1KSWL26--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/04blks7tzqv1klllv26q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--u1KSWL26--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/04blks7tzqv1klllv26q.png" alt="Implementing stacks using linked lists in python" width="698" height="132"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://github.com/Stephen-Kimoi/Data-Structures-and-Algorithims/blob/master/Data-structures/Stacks/linked-list-stack.py"&gt;Github link&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2.Queue data structure:&lt;/strong&gt; &lt;br&gt;
This is also a type of linear data structure in which addition of an element takes place from one end called the rear(tail) and removal of an element takes place from the other end also called front(head).&lt;br&gt;&lt;br&gt;
It follows the FIFO (first in first out) principle, meaning the first element to be inserted will be the first element to be removed.&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Applications of queue:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Serving requests on a single shared resource e.g printer
&lt;/li&gt;
&lt;li&gt;In call center stations, queues are used to put callers on hold until a service representative is free
&lt;strong&gt;Implementation of queue:&lt;/strong&gt;
Queue can be implemented using:

&lt;ul&gt;
&lt;li&gt;Arrays &lt;/li&gt;
&lt;li&gt;Linked lists
&lt;/li&gt;
&lt;/ul&gt;


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

&lt;p&gt;&lt;strong&gt;a)Implementing using arrays:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--IMc2NtbY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jlgejr4xin9aei2gn5x9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--IMc2NtbY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jlgejr4xin9aei2gn5x9.png" alt="Implementing queue using arrays" width="698" height="553"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--c3Ht1e63--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zkfwz3711z959vathfuo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--c3Ht1e63--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zkfwz3711z959vathfuo.png" alt="Implementing queue using arrays" width="740" height="332"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--fpJijNWv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8hofxtoxk8lwb3ufjzg8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--fpJijNWv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8hofxtoxk8lwb3ufjzg8.png" alt="Implementing queue using arrays" width="746" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Output: &lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--M-b0PPXX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ccd02fu1d7hxa6lc49m8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--M-b0PPXX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ccd02fu1d7hxa6lc49m8.png" alt="Implementing queue using arrays" width="337" height="190"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://github.com/Stephen-Kimoi/Data-Structures-and-Algorithims/blob/master/Data-structures/Queue/array-queue.py"&gt;Github link&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;b)Implementing using Queue from queue library:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--IcYoItmU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3tndn1v4qx5xix7vfr6e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--IcYoItmU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3tndn1v4qx5xix7vfr6e.png" alt="Implmenting queue using queue library" width="698" height="472"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Output:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--La9fRaVs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/unnszzzxl5fvi2d0t93t.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--La9fRaVs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/unnszzzxl5fvi2d0t93t.png" alt="Implmenting queue using queue library" width="698" height="51"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/Stephen-Kimoi/Data-Structures-and-Algorithims/blob/master/Data-structures/Queue/Queue-queue.py"&gt;Github link&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3.HashMap data structure:&lt;/strong&gt;&lt;br&gt;
As I stated in the previous article, a HashMap is a type of data structure that maps certain keys to certain values.&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Implementation of HashMap:&lt;/strong&gt;&lt;br&gt;
HashMaps are implemented in python using dictionaries&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example 1:&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--XVrKzrSf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vy86olnorlddo9xdx0l4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--XVrKzrSf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vy86olnorlddo9xdx0l4.png" alt="Implementing hashmaps in python" width="698" height="409"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Output: &lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--O57TVh5Q--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zqh9icqlqm8nmnv7gmv0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--O57TVh5Q--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zqh9icqlqm8nmnv7gmv0.png" alt="Implementing hashmaps in python" width="873" height="115"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/Stephen-Kimoi/Data-Structures-and-Algorithims/blob/master/Data-structures/HashMap/hashmap1.py"&gt;Github link&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example 2:&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--vKPOsA6C--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1ixfo4i6y5t4z0eksmpq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vKPOsA6C--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1ixfo4i6y5t4z0eksmpq.png" alt="Implementing hashmaps in python" width="873" height="591"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--yC8OlPj5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/la77ymtillxdypdaf2c6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--yC8OlPj5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/la77ymtillxdypdaf2c6.png" alt="Implementing hashmaps in python" width="880" height="571"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--A9OUZHsG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bgqj4r30ps1qs25qsdpt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--A9OUZHsG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bgqj4r30ps1qs25qsdpt.png" alt="Implementing hashmaps in python" width="880" height="503"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--eM0D5yC5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b8jfwfm76gutmshhs2fd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--eM0D5yC5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b8jfwfm76gutmshhs2fd.png" alt="Implementing hashmaps in python" width="880" height="420"&gt;&lt;/a&gt;&lt;br&gt;
Output: &lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--x5dd-LEv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zauc4oyr6xtwyp05f98b.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--x5dd-LEv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zauc4oyr6xtwyp05f98b.png" alt="Implementing hashmaps in python" width="880" height="134"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/Stephen-Kimoi/Data-Structures-and-Algorithims/blob/master/Data-structures/HashMap/hashmap2.py"&gt;GitHub link&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4.Graph data structure:&lt;/strong&gt;&lt;br&gt;
Graphs are a type of non-linear data structure that arranges data as multiple nodes. They are connected together using edges. Nodes represent entities where data is stored and the relationship between nodes are expressed by edges.&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Types of graphs:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Undirected: a type of graph where all the edges are bi-directional, the edges do not point at a specific direction.&lt;/li&gt;
&lt;li&gt;Directed graph: a type of graph where all edges are uni-directional, the edges point at a specific direction.
&lt;/li&gt;
&lt;li&gt;Weighted graph: a graph that has a value associated with every edge.
&lt;/li&gt;
&lt;li&gt;Unweighted graph: a type of graph that has no value or weight associated with the edge.
&lt;strong&gt;Applications of graph:&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Used in social networks such as Facebook and LinkedIn &lt;/li&gt;
&lt;li&gt;Used in blockchain technology, where the nodes are blocks that store many transactions while edges connect many subsequent blocks&lt;/li&gt;
&lt;li&gt;Google maps also uses graphs &lt;/li&gt;
&lt;li&gt;It also helps define the flow of computational software programs.
&lt;strong&gt;Implementation of graphs:&lt;/strong&gt;
&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--D3OaFi79--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p9vp82vs3j7f2ng8xwt1.png" alt="Implementation of graphs:" width="880" height="571"&gt; &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Output:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--8Cx0OvOR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iwynmpqd0uxmbeowyqau.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--8Cx0OvOR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iwynmpqd0uxmbeowyqau.png" alt="Implementation of graphs:" width="880" height="73"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/Stephen-Kimoi/Data-Structures-and-Algorithims/blob/master/Data-structures/Graphs/graphs-using-dict.py"&gt;GitHub link&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5.Set data structure:&lt;/strong&gt;&lt;br&gt;
This is a type of data structure that can store any unique values. It does not allow repeating of values &lt;br&gt;
&lt;strong&gt;Applications of set data structures:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It is used in eliminating duplicates &lt;/li&gt;
&lt;li&gt;It is used to sort, because it is ordered &lt;/li&gt;
&lt;li&gt;It is also used for searching, checking whether a given 
element is present in the in the set. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Implementations of set data structures:&lt;/strong&gt;&lt;br&gt;
They can be implemented using the set() function in python &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--6vUudqoI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jagtk284xdlyior5dl9m.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--6vUudqoI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jagtk284xdlyior5dl9m.png" alt="Implementations of set data structures" width="880" height="285"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Output: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ERwh947h--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/br3s8qlq1ylu5cadou0e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ERwh947h--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/br3s8qlq1ylu5cadou0e.png" alt="Implementations of set data structures" width="880" height="206"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/Stephen-Kimoi/Data-Structures-and-Algorithims/blob/master/Data-structures/Sets/set_function.py"&gt;GitHub link&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thank you for reading this far! &lt;/p&gt;

</description>
    </item>
    <item>
      <title>102(b):DEEP DIVE INTO DATA STRUCUTURES AND ALGORITHMS:</title>
      <dc:creator>steve kimoi </dc:creator>
      <pubDate>Tue, 19 Jul 2022 06:35:00 +0000</pubDate>
      <link>https://dev.to/stephenkimoi/102bdeep-dive-into-data-structures-and-algorithms-hp8</link>
      <guid>https://dev.to/stephenkimoi/102bdeep-dive-into-data-structures-and-algorithms-hp8</guid>
      <description>&lt;p&gt;&lt;strong&gt;Deep dive into Algorithms:&lt;/strong&gt;&lt;br&gt;
In my first &lt;a href="https://dev.to/stephenkimoi/introduction-to-data-structures-and-algorithms-4jgd"&gt;article&lt;/a&gt;, I gave a very brief introduction to algorithms, its definition, characteristics, types and their importance. In this article, I’ll give an in-depth explanation. &lt;/p&gt;

&lt;p&gt;We will cover:  &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Time complexity
&lt;/li&gt;
&lt;li&gt;Space complexity &lt;/li&gt;
&lt;li&gt;Asymptotic notations &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;An algorithm is said to be efficient if it takes less time and consumes less memory. The performance of an algorithm is based on the time complexity and space complexity. Thus, knowing time and space complexity enables us to make the program behave in required optimal conditions. This makes us efficient programmers. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Time complexity:&lt;/strong&gt;&lt;br&gt;
Time complexity of a program is the total time required by a program to run till its completion. It does not examine the total execution time but rather it gives information about the variation (increase or decrease) in execution time when the number of operations (increase or decrease) in an algorithm.  &lt;/p&gt;

&lt;p&gt;Time complexity of an algorithm is usually expressed using the &lt;strong&gt;big-0 notation.&lt;/strong&gt; This is an &lt;strong&gt;asymptotic notation&lt;/strong&gt; to represent the time complexity.   &lt;/p&gt;

&lt;p&gt;Time complexity is estimated by counting the number of steps performed by and algorithm to finish its execution.&lt;br&gt;&lt;br&gt;
A basic example could be:&lt;br&gt;&lt;br&gt;
We are told to find the square of any number, n. One solution can be running a loop for n times, and adding the number n to itself n times:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;         ``` 
          for i = 1 to n:  
             n = n + n  
             return n
         ```
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or we can simply use the mathematical operator * to find the square:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;          ```
          return n * n
          ```
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For the first solution, the loop will run n number of times, thus, the time complexity will be n at least, and as the value of n increases the time taken also increases.&lt;br&gt;&lt;br&gt;
For the second solution, the time taken will be independent of the value of n. Thus, the time complexity will be constant.  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Calculating time complexity:&lt;/strong&gt; &lt;br&gt;
Disclaimer: I have used the same example as &lt;a href="https://www.studytonight.com"&gt;study tonight&lt;/a&gt; site.&lt;br&gt;&lt;br&gt;
The most common way of calculating time complexity is by using the big-0 notation. This method removes all the constants, so that the running time can be estimated using n as n approaches infinity.&lt;br&gt;&lt;br&gt;
For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;             ```
             statement
             ```
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For the above statement, the running time will not change in relation to n. This will make the time complexity constant.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;               ```
               for x in range(n):  
                   statement
               ```
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The time complexity for the above algorithm will be linear. The running time of the loop will be directly proportional to n. When n increases, so does the running time.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;               ```
               for x in range(n):  
                   for j in range(n):  
                       statement
               ```
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The time complexity for the above code will be quadratic.  This is because the running time of the above loops is proportional to the square of n.  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Types of notation for time complexity:&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
The various notations used for time complexity are:&lt;br&gt;&lt;br&gt;
      1. Big 0 notation (oh) &lt;br&gt;
      2. Big Ω notation (omega) &lt;br&gt;
      3. Big theta notation (theta)  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Big Oh:&lt;/strong&gt;represents worst case of an algorithm’s time &lt;br&gt;
        complexity. A set of functions that grow slower than, &lt;br&gt;
        or at the same rate as the expression. It indicates &lt;br&gt;
        maximum time required by an algorithm for all input &lt;br&gt;
        values.&lt;br&gt;
   &lt;strong&gt;2. Big Omega:&lt;/strong&gt; represents best case of an algorithms &lt;br&gt;
        time complexity. It is a set of functions that grow &lt;br&gt;
        faster than or at the same rate as the expression. It &lt;br&gt;
        indicates minimum time required by an algorithm for &lt;br&gt;
        all input values. &lt;br&gt;
   &lt;strong&gt;3. Big theta:&lt;/strong&gt; represents average case of an &lt;br&gt;
        algorithm’s time and space complexity. Consists of &lt;br&gt;
        all functions that lie in both O and Omega.  &lt;/p&gt;

&lt;p&gt;Now let’s understand what space complexity is:  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Space complexity:&lt;/strong&gt;&lt;br&gt;
Space complexity is the amount of memory required by the algorithm during the time of its execution. It includes both auxiliary space and space used by the input. Auxiliary space is the extra/temporary space used by an algorithm.&lt;br&gt;&lt;br&gt;
     &lt;code&gt;Space complexity = auxiliary space + input space&lt;/code&gt;  &lt;/p&gt;

&lt;p&gt;The following components in an algorithm generally require space: &lt;br&gt;
      1. Data space: this is the space required to store all &lt;br&gt;
         the constants and variables (including temporary &lt;br&gt;
         variables). &lt;br&gt;
      2. Instruction space: this is the space required to &lt;br&gt;
         store the executable version of the program.  &lt;br&gt;
      3. Environmental space: this is the space used to store &lt;br&gt;
         the environment information used to restore the &lt;br&gt;
         suspended function. E.g when a function (x) calls a &lt;br&gt;
         function (y), the variables of the function (x) are &lt;br&gt;
         stored in the system stack temporarily while &lt;br&gt;
         function (y) is being executed inside function (x). &lt;/p&gt;

&lt;p&gt;When we are calculating the space complexity, we usually consider data space only and neglect instruction space and environment space.    &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Calculating the space complexity:&lt;/strong&gt; &lt;br&gt;
In order to calculate the space complexity, we need to know the amount of memory used by different data variables, although it may be different for different operating systems, the method of calculation is the same.  &lt;/p&gt;

&lt;p&gt;Let's compute the space complexity using a few examples:&lt;br&gt;&lt;br&gt;
Disclaimer: the examples below are copied from &lt;a href="https://www.studytonight.com/"&gt;study tonight&lt;/a&gt;.  &lt;/p&gt;

&lt;p&gt;&lt;em&gt;Example 1:&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;            ```
            def myFunction():  
                 Int(a) = x + y + z  
                 return a 
            ```
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the example above, the total amount of memory used is ( 4 + 4 + 4 + 4 ) = 20 bytes since the variable types are all integers . The additional 4 bytes is for the return value.&lt;br&gt;&lt;br&gt;
This is a &lt;em&gt;Constant Space Complexity&lt;/em&gt;, since the memory required is fixed.  &lt;/p&gt;

&lt;p&gt;&lt;em&gt;Example 2:&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;              ```
              def myFunction():  
                 int( sum( int(arr[]), int(n) )) 
                 int(x) = 0   
                 for i in range(n):  
                     x = x + arr[i]  
                     return x 
              ```
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above example, 4*n bytes is required for the arr[]. &lt;br&gt;
4 bytes each is required for x, n and i &lt;/p&gt;

&lt;p&gt;Thus, the total memory required will be (4n + 12), thus the space complexity will be called Linear Space Complexity.&lt;/p&gt;

&lt;p&gt;Now that we have a good understanding of time and space complexity, we’re going to look at the standard ways of expressing them.  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Asymptotic notations:&lt;/strong&gt; &lt;br&gt;
These are standard notations that are used to express the time and space required by an algorithm. This is because it's impossible to provide an exact number of time and space required by the algorithm.&lt;br&gt;
There are three main types of Asymptotic notations:&lt;br&gt;&lt;br&gt;
       1. Big O notation&lt;br&gt;&lt;br&gt;
       2. Theta notation&lt;br&gt;
       3. Omega notation &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Big O notation:&lt;/strong&gt; &lt;br&gt;
This usually represents the worst-case scenario of an algorithm.  It is also known as the upper bound of the running time of an algorithm. It represents the complexity of your code using algebraic terms.  &lt;/p&gt;

&lt;p&gt;It tells us that a function will never exceed a specified time for any value of input n.  &lt;/p&gt;

&lt;p&gt;Example: let us consider a linear search algorithm where we pass through elements inside an array, one after the other, to search for a particular number. Our worst-case scenario will be if the element is located at the end of an array.  This leads to a time complexity of n, where n is the total number of the elements.  When we use Big O notation, we say that the time complexity will be O(n). This means that the time complexity will never exceed n. This defines the upper bound, which means that it can be less than or equal to n.  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Omega notation:&lt;/strong&gt; &lt;br&gt;
This is used to define the best-case scenario. It defines the lower bound. It indicates the minimum time required for an algorithm.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Theta notation:&lt;/strong&gt; &lt;br&gt;
Time complexity represented by this notation is the average value or range within which the actual time of execution will be.  &lt;/p&gt;

</description>
    </item>
    <item>
      <title>102(a) : DEEP DIVE INTO DATA STRUCTURES AND ALGORITHMS:</title>
      <dc:creator>steve kimoi </dc:creator>
      <pubDate>Mon, 04 Jul 2022 12:53:53 +0000</pubDate>
      <link>https://dev.to/stephenkimoi/102a-deep-dive-into-data-structures-and-algorithms-1heb</link>
      <guid>https://dev.to/stephenkimoi/102a-deep-dive-into-data-structures-and-algorithms-1heb</guid>
      <description>&lt;p&gt;We started off by having a brief introduction to data structures and algorithms in our first article, lets now have a more in depth look into each of these:   &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; I’ll be using python through these series of articles.  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Deep dive into data structures:&lt;/strong&gt;&lt;br&gt;
In our first article, &lt;a href="https://dev.to/stephenkimoi/introduction-to-data-structures-and-algorithms-4jgd"&gt;Introduction to data structures and algorithims&lt;/a&gt;, we began by defining what data structures are, now let's have a more detailed understanding of them.  &lt;/p&gt;

&lt;p&gt;The term data structure is made up of two words, “Data” and “Structures”.  Data itself means collection of some information e.g some users information. Structure in simple words can be described as organizing. Combining the two, data structures can be described as organizing a bunch of data in such a way that it can be used efficiently with respect to time and memory.  &lt;/p&gt;

&lt;p&gt;Before having a deeper look into the classic and fundamental data structures, let’s first distinguish the &lt;strong&gt;difference between data structures and data types:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Data type:&lt;/strong&gt; this is a classification that defines which type of value a variable has and which type of mathematical, relational or logical operations can be applied to it without an error. Examples: float, strings, integers e.t.c   &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Data structures:&lt;/strong&gt; as we have said, data structures are collection of different forms and types of data that has a set of specific operations that can be performed. It can be described as a collection of data types. Examples: stacks, queues, linked lists, binary tree e.t.c &lt;/p&gt;

&lt;p&gt;Now let’s have a deeper look into the classic and fundamental data structures: &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A.  Array:&lt;/strong&gt;&lt;br&gt;
A data structure that stores data types by allocating memory slots. It is the simplest way to store information in a computer.  &lt;/p&gt;

&lt;p&gt;All elements stored in an array have to be of the same data type.  &lt;/p&gt;

&lt;p&gt;Arrays are usually used in numerical computation tasks or as a supporting data structure to implement other data structures e.g stacks, lists, queues.  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Implementing array data structure in python:&lt;/strong&gt;&lt;br&gt;
In order to use arrays in python you’ll have to import a library like &lt;a href="https://www.w3schools.com/python/numpy/default.asp"&gt;NumPy library&lt;/a&gt;.  &lt;/p&gt;

&lt;p&gt;Python has a numeric implementation of arrays with the &lt;a href="https://techvidvan.com/tutorials/python-array-module/#:~:text=What%20is%20Array%20Module%20in,stored%20in%20them%20is%20constrained."&gt;array module&lt;/a&gt;  &lt;/p&gt;

&lt;p&gt;It helps users specify the python data type that the array holds at initiation.  &lt;/p&gt;

&lt;p&gt;Python array comes in with built in functions like:  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.w3schools.com/python/ref_list_append.asp"&gt;append(item)&lt;/a&gt;: for adding items to the end of the array.  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.w3schools.com/python/ref_list_count.asp"&gt;count(item)&lt;/a&gt;: for counting the number of occurrences of an item within an array.  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.w3schools.com/python/ref_list_insert.asp"&gt;insert(item, index)&lt;/a&gt;: to insert item at position index.  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.programiz.com/python-programming/methods/list/remove"&gt;remove(item)&lt;/a&gt;: for deleting the item.  &lt;/p&gt;

&lt;p&gt;You can check out more methods over &lt;a href="https://www.w3schools.com/python/python_ref_list.asp"&gt;here&lt;/a&gt;.  &lt;/p&gt;

&lt;p&gt;There are more specialized implementations of arrays in python:  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://en.wikiversity.org/wiki/Python_Concepts/Bytes_objects_and_Bytearrays#:~:text=A%20bytes%20object%20is%20an,conceptually%20similar%20to%20a%20string.&amp;amp;text=of%20a%20bytes%20object%20is,%3Dx%3E%3D0.%7D"&gt;bytes objects&lt;/a&gt;: this is an immutable sequence of single bytes.  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.programiz.com/python-programming/methods/built-in/bytearray"&gt;bytearray()&lt;/a&gt;: this is a mutable arrays of single bytes.  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.programiz.com/python-programming/methods/built-in/str"&gt;str objects&lt;/a&gt;:  immutable arrays of unicode characters declared as single quotes, double quotes or tripple quotes.  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.w3schools.com/python/python_tuples.asp#:~:text=Tuples%20are%20used%20to%20store,which%20is%20ordered%20and%20unchangeable."&gt;tuple objects&lt;/a&gt;:  an immutable sequence for storing multilpe items in a single variable.  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;B.  Stack(LIFO):&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
This is a container of objects where item insertion and deletion are carried out according to last in first out (LIFO) principle.  &lt;/p&gt;

&lt;p&gt;The insert and deletion operations are normally called push() and pop() respectively.   &lt;/p&gt;

&lt;p&gt;A practical example of where stack is used in an application is: the “undo” button in a text editor checks the last inserted command, and removes it from the stack.  &lt;/p&gt;

&lt;p&gt;Some other functions associated with stack are:  &lt;/p&gt;

&lt;p&gt;empty(): returns whether a stack is empty   &lt;/p&gt;

&lt;p&gt;size(): returns the size of the stack   &lt;/p&gt;

&lt;p&gt;top() / peek(): returns a reference to the topmost element of the stack.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Implementing stack data structure in python:&lt;/strong&gt;&lt;br&gt;
Stacks in python can be implemented using the following ways:  &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Lists &lt;/li&gt;
&lt;li&gt;Collections.deque
&lt;/li&gt;
&lt;li&gt;Queue.LifoQueue &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;1. Lists:&lt;/strong&gt; &lt;br&gt;
Pythons built in lists can be used as a stack.  &lt;/p&gt;

&lt;p&gt;append() is used to put elements on top of the stack while pop() is used to remove the elements in the LIFO order.  &lt;/p&gt;

&lt;p&gt;One of the shortcomings of using list as stack is speed issues as the list grows. If the stack grows bigger than the block of memory that currently holds it, then python needs to do some memory allocations. This can cause some append() calls taking more time than others.  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. collections.deque:&lt;/strong&gt; &lt;br&gt;
Python stack can also be implemented using the &lt;a href="https://www.geeksforgeeks.org/deque-in-python/"&gt;deques&lt;/a&gt; class from the &lt;a href="https://www.geeksforgeeks.org/python-collections-module/"&gt;collections&lt;/a&gt; module.   &lt;/p&gt;

&lt;p&gt;This is preferred from the list in the cases where we need quicker append and pop operations from both ends of the container.  &lt;/p&gt;

&lt;p&gt;The same methods, append() and pop(), used in lists are also used in deque.  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Queue.LifoQueue:&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://www.geeksforgeeks.org/queue-in-python/"&gt;Queue&lt;/a&gt; module in python has a &lt;a href="https://www.geeksforgeeks.org/python-queue-lifoqueue-vs-collections-deque/#:~:text=in%20Python.,in%20the%20very%20same%20process."&gt;LIFO&lt;/a&gt; queue which works as a stack.  &lt;/p&gt;

&lt;p&gt;Data is inserted using the put() function and removed using the get() function. &lt;/p&gt;

&lt;p&gt;There are a number of functions available in this module, they can be found &lt;a href="https://www.simplilearn.com/tutorials/python-tutorial/queue-in-python#:~:text=put(item)%3A%20Inserts,in%20a%20queue"&gt;here&lt;/a&gt;.  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;C.  Queue (FIFO):&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
They are collection of items that hold elements. They collect elements according to the “First in First out” concept. The first element to be added is the first to be deleted.  &lt;/p&gt;

&lt;p&gt;The two main operations are; enqueue(): adding item to the back of the queue and dequeue(): remove item at the front of the queue.   &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Implementing Queue data structure in python:&lt;/strong&gt;&lt;br&gt;
Queues in python can be implemented using the following methods:  &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Lists
&lt;/li&gt;
&lt;li&gt;collections.deque &lt;/li&gt;
&lt;li&gt;queue.Queue
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;1. Lists:&lt;/strong&gt; &lt;br&gt;
You can implement the FIFO principle using slicing. This is well explained in the &lt;a href="https://docs.python.org/3/tutorial/datastructures.html#using-lists-as-queues"&gt;python documentation&lt;/a&gt;.  &lt;/p&gt;

&lt;p&gt;Instead of using enqueue() and dequeue(), the append() and pop() functions are used. Lists are slow in this since in order to add or delete the item it will require you to shift all the other elements by one.  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. collections.deque:&lt;/strong&gt; &lt;br&gt;
Queue in python can also be implemented using the &lt;a href="https://www.geeksforgeeks.org/deque-in-python/"&gt;deque class&lt;/a&gt; from the &lt;a href="https://www.geeksforgeeks.org/python-collections-module/"&gt;collections module&lt;/a&gt;.  &lt;/p&gt;

&lt;p&gt;Instead of enqueue() and dequeue(), append() and popleft() functions are used.  &lt;/p&gt;

&lt;p&gt;Deques are preferred over lists when we need a quicker add and remove operations from both ends of the container.  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. queue.Queue:&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://docs.python.org/3/library/queue.html"&gt;Queue&lt;/a&gt; is a built-in module of python used to implement the queue.  &lt;/p&gt;

&lt;p&gt;queue.maxsize(maxsize) initializes a variable to a maximum size of maxsize.  &lt;/p&gt;

&lt;p&gt;To add items you use the put() function and to remove or get an item you use the get() function.  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;D. Map:&lt;/strong&gt; &lt;br&gt;
This is a data structure, (also referred to as hash tables, lookup tables, hashmaps or associative arrays), which is a collection of named items.  &lt;/p&gt;

&lt;p&gt;It is efficient in item insertion, lookup and deletion. But it requires more space than other data structures, since it is implemented as a key-value table.  &lt;/p&gt;

&lt;p&gt;Maps have the following operations:  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;set(key, value) - adds a key-value mapping to the map.
&lt;/li&gt;
&lt;li&gt;delete(key) -  removes a key and its associated value.
&lt;/li&gt;
&lt;li&gt;get(key) - retrieves the value associated with the given key.
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Implementing map data structure in python:&lt;/strong&gt; &lt;br&gt;
Maps in python can be implemented by using &lt;a href="https://www.w3schools.com/python/python_dictionaries.asp"&gt;dictionaries&lt;/a&gt;.  &lt;/p&gt;

&lt;p&gt;Dictionaries are used to store values in key value pairs. Python has a built in function dict() that can be used to create dictionaries.  &lt;/p&gt;

&lt;p&gt;Values in the dictionary can be accessed using the key values, built in functions and loops.  &lt;/p&gt;

&lt;p&gt;For the built in functions we have:  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;get() - enables you to access the items &lt;/li&gt;
&lt;li&gt;keys() - this returns a list of all the keys in the dictionary
&lt;/li&gt;
&lt;li&gt;values() - this will return a list of all values in the dictionary
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can check more on the access methods over &lt;a href="https://www.w3schools.com/python/python_dictionaries_access.asp"&gt;here&lt;/a&gt;.  &lt;/p&gt;

&lt;p&gt;Values in the dictionary can be changed using the following method:  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Update() - updates the dictionary with items of the given argument.
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;More on how to change the values an implement the update() function can be found &lt;a href="https://www.w3schools.com/python/python_dictionaries_change.asp"&gt;here&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;The update() method can also be used to add an item to the dictionary. More on how to add an item can be found &lt;a href="https://www.w3schools.com/python/python_dictionaries_add.asp"&gt;here&lt;/a&gt;.  &lt;/p&gt;

&lt;p&gt;Items can be removed using the pop() function. There are other methods on how to remove an item that can be checked &lt;a href="https://www.w3schools.com/python/python_dictionaries_remove.asp"&gt;here&lt;/a&gt;.  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;E. Graph:&lt;/strong&gt; &lt;br&gt;
Graph is a type of data structure that arranges data as multiple nodes. The nodes are connected together using edges. They are used to model pairwise relations between objects.  &lt;/p&gt;

&lt;p&gt;They are used to model networks that naturally occur in real life. They are used in social networks such as Facebook and LinkedIn.  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Implementing graph data structures in python:&lt;/strong&gt;&lt;br&gt;
The first way is by use of a dictionary. The keys in the dictionary used are the nodes of our graph and the corresponding values are the lists with each node.   &lt;/p&gt;

&lt;p&gt;For more on how to implement a graph using dictionaries in python, you can check out &lt;a href="https://www.geeksforgeeks.org/generate-graph-using-dictionary-python/"&gt;here&lt;/a&gt;.  &lt;/p&gt;

&lt;p&gt;We can also use the NetworkX Library. This library allows you to easily add or remove nodes and edges. It also comes with a lot of out-of-the-box methods such as: finding the shortest path between the nodes, measures of associativity and centrality within the graph.  &lt;/p&gt;

&lt;p&gt;You can check out more on NetworkX library &lt;a href="https://networkx.org/documentation/networkx-1.10/overview.html"&gt;here&lt;/a&gt;.  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;D.  Set:&lt;/strong&gt;&lt;br&gt;
This is a data structure in python with an unordered and unindexed collection of elements. Each element in a set is unique and the set does not allow any duplication of elements.  &lt;/p&gt;

&lt;p&gt;Sets can be used to perform mathematical set operations like union, intersection, symmetric difference e.t.c &lt;/p&gt;

&lt;p&gt;Sets are usually used for validating data, finding the difference between the two data sets, joining unique data sets together and more.  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Implementing set data structure in python:&lt;/strong&gt; &lt;br&gt;
There are two main methods for implementing sets in python:  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Using the &lt;a href="https://www.w3schools.com/python/python_sets.asp#:~:text=The%20set()%20Constructor,make%20a%20set."&gt;set function&lt;/a&gt; available in python.  &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Typing the list of various elements using the &lt;a href="https://www.w3schools.com/python/python_sets.asp#:~:text=Sets%20are%20written%20with%20curly%20brackets."&gt;curly “{}” braces&lt;/a&gt;.   &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Sets have the following operations:  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.w3schools.com/python/python_sets_add.asp#:~:text=Add%20Items,the%20add()%20method."&gt;add()&lt;/a&gt; function: this function adds an element to the set. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.w3schools.com/python/python_sets_add.asp#:~:text=Add%20Sets,the%20update()%20method"&gt;update()&lt;/a&gt; function: this function is used to add multiple elements to the set. Items from another set can also be added using this function.   &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.w3schools.com/python/python_sets_remove.asp#:~:text=Example,the%20remove()%20method%3A"&gt;remove()&lt;/a&gt; and &lt;a href="https://www.w3schools.com/python/python_sets_remove.asp#:~:text=raise%20an%20error.-,Example,Remove%20%22banana%22%20by%20using%20the%20discard()%20method%3A,-thisset%20%3D%20%7B%22apple"&gt;discard()&lt;/a&gt; functions:  they are used to remove an item from a set.  &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Wrapping up:&lt;/strong&gt; &lt;br&gt;
As we finalize ,let's have some recap, in this article we’ve learned about: &lt;br&gt;
    1. The 6 fundamental data structures &lt;br&gt;
    2. How to implement the various data structures in python&lt;br&gt;&lt;br&gt;
I'll be giving a thorough explanation on algorithms in the next article. Stay tuned!      &lt;/p&gt;

</description>
    </item>
    <item>
      <title>101: INTRODUCTION TO DATA STRUCTURES AND ALGORITHMS</title>
      <dc:creator>steve kimoi </dc:creator>
      <pubDate>Tue, 21 Jun 2022 07:47:31 +0000</pubDate>
      <link>https://dev.to/stephenkimoi/introduction-to-data-structures-and-algorithms-4jgd</link>
      <guid>https://dev.to/stephenkimoi/introduction-to-data-structures-and-algorithms-4jgd</guid>
      <description>&lt;p&gt;We have all heard about data structures and algorithms, and how essential they are to any programmer or software engineer/developer. But do we really have a good understanding of what data structures and algorithms are?  &lt;/p&gt;

&lt;p&gt;Let’s dive deep into it:   &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;DEFINITIONS:&lt;/strong&gt;&lt;br&gt;
What is a data structure: it is a named location that can be used to store and organize data.  &lt;/p&gt;

&lt;p&gt;What is an algorithm: they are steps that can be used to solve a particular problem.  &lt;/p&gt;

&lt;p&gt;Having a good understanding of the above allows you (a programmer) to write efficient and optimized computer programs. This leads us to our next question, what is a computer program?  &lt;/p&gt;

&lt;p&gt;A computer program is a sequence of instructions in a programming language that a computer can execute or interpret. A computer program may need to store data, retrieve data and perform computations on the data.  &lt;/p&gt;

&lt;p&gt;Now that we have a basic understanding of data structures and algorithms and how they’re related to a computer program, let’s see the various types of data structures:  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;TYPES OF DATA STRUCTURES:&lt;/strong&gt; &lt;br&gt;
There are several basic and advanced types of data structures, all designed to arrange data to suit a specific purpose. There are 8 commonly used data structures every programmer must know:  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Arrays:&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
An array is a structure of fixed size that can hold items of the same data type e.g integers, strings, floating point numbers e.t.c. The type of elements that can be stored in the form of array is determined by the programming language. Random access of the data is possible since they are indexed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Linked lists:&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
A sequential structure that consists of a sequence of items in linear order that are linked to each other. Random access is not possible since you have to access the data sequentially. Elements in a linked lists are known as nodes. Each node contains a key and a pointer to its successor node.  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Stacks:&lt;/strong&gt; &lt;br&gt;
A stack is a LIFO (Last in first out) structure which can be found in many programming languages. This structure is named as “stack” since it resembles a real-world stack – e.g a stack of plates. It is named this way since the last element to go in comes out first.   &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Queues:&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
This behaves in the opposite manner as compared to stack. It uses the FIFO (First in first out) principle, where the element to go in first comes out first. It is named “queue” since it represents a real world queue.  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. Hash tables:&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
A data structure that stores values which have keys associated with each one of them. It supports lookup efficiently if we know a key associated with the value.   &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;6. Trees:&lt;/strong&gt; &lt;br&gt;
This is a hierarchical structure where the data is organized hierarchically and are linked together. It is a bit different from a linked list since a linked list has items linked together.   &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;7. Heaps:&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
 A special case of a binary tree where the parent nodes are compared to their children with their values and are arranged accordingly.   &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;8. Graphs:&lt;/strong&gt; &lt;br&gt;
This is a fine set of vertices or nodes and a set of edges connecting these vertices. Order of the graph is the number of vertices in the graph and the size of the graph is the number of edges in the graph.  &lt;/p&gt;

&lt;p&gt;Let us now look on the importance of data structures.  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;WHY ARE DATA STRUCTURES IMPORTANT:&lt;/strong&gt; &lt;br&gt;
Data types such as integers and floating-point values that are available in most programming languages are not sufficient to capture the logical intent for data processing and use. Data structures bring together the data elements in a logical way and facilitate their effective use, persistent and sharing of data. They provide a formal model that describes the way the data elements are organized.  &lt;/p&gt;

&lt;p&gt;Basically, data structures are the building blocks for more sophisticated applications. &lt;/p&gt;

&lt;p&gt;We now understand what are data structures and the various types, we can now have a look into algorithms.  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;ALGORITHIMS:&lt;/strong&gt;&lt;br&gt;
We started off by defining what algorithms are at the start of this article, now let’s have a look into how algorithms work, their characteristics, the various types and their importance in computer programming.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How do algorithms work:&lt;/strong&gt;&lt;br&gt;
As I had mentioned earlier, algorithms are basically steps that are used to solve a particular problem. They can be expressed as natural languages(e.g English), &lt;a&gt;pseudocodes&lt;/a&gt;, programming languages, flowcharts and control tables.  Programming languages are the ones commonly used for expressing algorithms used by a computer.  &lt;/p&gt;

&lt;p&gt;It usually takes an input, and passes it through a set of instructions. The input acts as the initial data. It then gives out an output, which is usually the last step.  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What are the characteristics of algorithms:&lt;/strong&gt;&lt;br&gt;
In order for a program to become an algorithm, it usually has some type of characteristics:  &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Finiteness: it should have a finite number of steps, and should end after a finite time.
&lt;/li&gt;
&lt;li&gt;Well defined inputs: the inputs of an algorithm must be well defined. &lt;/li&gt;
&lt;li&gt;Well defined outputs: the algorithm must clearly define what output will be yielded and it should be well defined as well.
&lt;/li&gt;
&lt;li&gt;Clear and unambiguous: each of the steps should be clear in all aspects and must lead to one meaning.
&lt;/li&gt;
&lt;li&gt;Language independent: it must be plain instructions that can be implemented in any language, and the output will be the same as expected.
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Types of algorithms:&lt;/strong&gt;&lt;br&gt;
There are several types of algorithms available, some important ones are:  &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Brute force algorithm: straightforward methods of solving a problem that rely on sheer computer power. &lt;/li&gt;
&lt;li&gt;Recursive algorithm: Based on &lt;a href="https://www.geeksforgeeks.org/recursion/"&gt;recursion&lt;/a&gt;. A problem is broken into smaller sub-parts and called the same function over and over. &lt;/li&gt;
&lt;li&gt;Backtracking algorithms: It builds the solution by searching among all possible solutions. In short it builds a solution incrementally, one piece at a time.
&lt;/li&gt;
&lt;li&gt;Searching algorithm: they are algorithms that are used to search for elements or groups of elements from a particular data structure.
&lt;/li&gt;
&lt;li&gt;Sorting algorithms: sorting is arranging a group of data in a particular manner according to the requirement. Algorithms that help performing this kind of task are called sorting algorithms.
&lt;/li&gt;
&lt;li&gt;Hashing algorithms: they work similarly to searching algorithms but the difference is, they contain index with a key ID. A key is assigned to a specific data. &lt;/li&gt;
&lt;li&gt;Divide and conquer algorithm: involves breaking a problem into sub-problems, and merges the solutions together to get the final solution. &lt;/li&gt;
&lt;li&gt;Greedy algorithm: the solution is built part by part. The solution of the next part is built based on the immediate benefit of the next part. &lt;/li&gt;
&lt;li&gt;Dynamic programming algorithm: Uses the concept of using the already found solution to avoid repetitive calculation of the same part of the problem. &lt;/li&gt;
&lt;li&gt;Randomized algorithms: we use a random number so it gives immediate benefit. The random number helps in deciding the expected outcome. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Importance of algorithms:&lt;/strong&gt;&lt;br&gt;
Algorithms are very key and important to computer programming. The best-chosen algorithm makes sure the computer will do the given task in the best possible manner.&lt;/p&gt;

&lt;p&gt;Some of the importance of algorithms are:  &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;To improve the efficiency of a computer program: the best algorithm enables the computer produce the very accurate results.
&lt;/li&gt;
&lt;li&gt;Proper utilization of resources: an algorithm determines the amount of memory used by the program and also amount of processing power determined by the program. A good algorithm will use less recourses.
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;References: &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://towardsdatascience.com/8-common-data-structures-every-programmer-must-know-171acf6a1a42"&gt;Towards data science&lt;/a&gt;  &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.techtarget.com/searchdatamanagement/definition/data-structure#:~:text=A%20data%20structure%20is%20a,they%20need%20in%20appropriate%20ways."&gt;Tech target&lt;/a&gt; &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.geeksforgeeks.org/introduction-to-algorithms/"&gt;Geeks for Geeks&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.techtarget.com/whatis/definition/algorithm"&gt;Tech target&lt;/a&gt; &lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

</description>
    </item>
  </channel>
</rss>
