<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Raithrishika on Medium]]></title>
        <description><![CDATA[Stories by Raithrishika on Medium]]></description>
        <link>https://medium.com/@raithrishika?source=rss-71f37d31436------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*WY4AgBWX4QUaiHzeT2sLAQ.png</url>
            <title>Stories by Raithrishika on Medium</title>
            <link>https://medium.com/@raithrishika?source=rss-71f37d31436------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 04:38:23 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@raithrishika/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Integrating C library in a desktop Flutter app]]></title>
            <link>https://medium.com/@raithrishika/integrating-c-library-in-a-desktop-flutter-app-c2d100ac1285?source=rss-71f37d31436------2</link>
            <guid isPermaLink="false">https://medium.com/p/c2d100ac1285</guid>
            <dc:creator><![CDATA[Raithrishika]]></dc:creator>
            <pubDate>Mon, 22 Aug 2022 10:54:23 GMT</pubDate>
            <atom:updated>2022-08-22T10:54:23.679Z</atom:updated>
            <content:encoded><![CDATA[<p>In Flutter app development, there may be a need for an app to link to an external binary library, or it may be beneficial to write some of the code in a lower-level language like C, C+, or Rust.</p><p>The purpose of this article is to help Flutter developers set up their project to use a native C or C++ library and write a single code base that uses it.</p><h4>Using Dart FFI to access a dynamic library</h4><p>Let’s start by writing a basic math function in C. We’ll use it in a simple Dart application:</p><pre>/// native/add.c</pre><pre>int add(int a, int b)<br>{<br>return a + b;<br>}</pre><p>We can covert our C file to the dynamic library dylib by running the following code:</p><pre>gcc -dynamiclib add.c -o libadd.dylib</pre><p>This results in the following output: add.dylib.</p><p>After making the dll file past both the c/c++ file and dll file into the flutter project folder.</p><h3>Source Code</h3><pre>import &#39;package:flutter/material.dart&#39;;<br>import &#39;dart:developer&#39; as dev;<br>import &#39;package:path/path.dart&#39;;<br>import &#39;dart:ffi&#39; as ffi;</pre><pre><strong>// FFI signature of the add C function<br>typedef AddFuncC = ffi.Int32 Function(ffi.Int32 a, ffi.Int32 b);<br>// Dart type definition for calling the C foreign function<br>typedef AddFuncDart = int Function(int a, int b);</strong></pre><pre>void main() {</pre><pre>  runApp(MaterialApp(home: const MyApp()));</pre><pre>}</pre><pre>class MyApp extends StatefulWidget {<br>  const MyApp({Key? key}) : super(key: key);</pre><pre>  @override<br>  State&lt;MyApp&gt; createState() =&gt; _MyAppState();<br>}</pre><pre>class _MyAppState extends State&lt;MyApp&gt; {<br>  TextEditingController number1 = TextEditingController();<br>  TextEditingController number2 = TextEditingController();<br>  var res;</pre><pre>  // This widget is the root of your application.<br>  @override<br>  Widget build(BuildContext context) {<br>    return Scaffold(<br>      body: Padding(<br>        padding: const EdgeInsets.all(8.0),<br>        child: Column(<br>          children: [<br>            TextField(<br>              controller: number1,<br>              decoration: InputDecoration(<br>                hintText: &#39;Enter first no&#39;<br>              ),<br>            ),<br>            TextField(<br>              controller: number2,<br>              decoration: InputDecoration(<br>                  hintText: &#39;Enter second no&#39;<br>              ),<br>            ),</pre><pre>            TextButton(onPressed: (){<br>     <strong>         final path = absolute(&#39;lib&#39;,&#39;addNumbert.dll&#39;);<br>              print(&#39;path to lib $path&#39;);<br>              final dylib = ffi.DynamicLibrary.open(path);<br>              final AddFuncDart AddTwoNumbers = dylib.lookup&lt;ffi.NativeFunction&lt;AddFuncC&gt;&gt;(&#39;AddTwo&#39;).asFunction&lt;AddFuncDart&gt;();</strong><br>    <strong>          setState((){<br>                res = AddTwoNumbers(int.<em>parse</em>(number1.text),int.<em>parse</em>(number2.text));</strong><br></pre><pre>              });<br>              print(res);<br>            }, child: Text(&#39;ADD&#39;)),<br>            Text(&#39;Result:$res&#39;)<br>          ],<br>        ),<br>      ),<br>    );<br>  }<br>}</pre><p>We’ll follow three steps to call this function in Dart:</p><ol><li>Open the dynamic library containing the function</li><li>Look up the function (<strong><em>N.B.,</em></strong> <em>because types are different in C and Dart, we must specify each respectively</em>)</li><li>Call the function</li></ol><pre>/// run.dart<br>import &#39;dart:developer&#39; as dev;<br>import &#39;package:path/path.dart&#39;;<br>import &#39;dart:ffi&#39;;void main() {<br>final path = absolute(&#39;native/libadd.dylib&#39;);<br>dev.log(&#39;path to lib $path&#39;);<br>final dylib = DynamicLibrary.open(path);<br>final add = dylib.lookupFunction(&#39;add&#39;);<br>dev.log(&#39;calling native function&#39;);<br>final result = add(40, 2);<br>dev.log(&#39;result is $result&#39;); // 42<br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c2d100ac1285" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Depth First Search (DFS)]]></title>
            <link>https://medium.com/@raithrishika/depth-first-search-dfs-b09359113999?source=rss-71f37d31436------2</link>
            <guid isPermaLink="false">https://medium.com/p/b09359113999</guid>
            <dc:creator><![CDATA[Raithrishika]]></dc:creator>
            <pubDate>Thu, 23 Jun 2022 12:36:22 GMT</pubDate>
            <atom:updated>2022-06-23T12:36:22.058Z</atom:updated>
            <content:encoded><![CDATA[<p>The depth-first search (DFS) algorithm <strong>starts with the initial node of graph G and goes deeper until we find the goal node or the node with no children</strong>. Because of the recursive nature, stack data structure can be used to implement the DFS algorithm. The process of implementing the DFS is similar to the BFS algorithm.</p><p>The step by step process to implement the DFS traversal is given as follows -</p><ol><li>First, create a stack with the total number of vertices in the graph.</li><li>Now, choose any vertex as the starting point of traversal, and push that vertex into the stack.</li><li>After that, push a non-visited vertex (adjacent to the vertex on the top of the stack) to the top of the stack.</li><li>Now, repeat steps 3 and 4 until no vertices are left to visit from the vertex on the stack’s top.</li><li>If no vertex is left, go back and pop a vertex from the stack.</li><li>Repeat steps 2, 3, and 4 until the stack is empty.</li></ol><p><em>Source Code</em></p><pre>import &#39;dart:developer&#39;;</pre><pre>List&lt;GraphNode&gt; graph = [];<br>void main() {<br>  generateGraph();<br>  dfsTraversal();<br>}</pre><pre>void generateGraph() {<br>  graph = List.generate(5, (index) =&gt; GraphNode(element: index));<br>  graph[0].addAdjacentElements([1, 2, 3]);<br>  graph[1].addAdjacentElements([0, 2]);<br>  graph[2].addAdjacentElements([0, 1, 4]);<br>  graph[3].addAdjacentElements([0]);<br>  graph[4].addAdjacentElements([2]);<br>}</pre><pre>dfsTraversal() {<br>  Stack&lt;int&gt; stack = Stack&lt;int&gt;([]);<br>  List&lt;int&gt; visited = [];<br>  stack.push(graph.first.element);<br>  while (visited.length &lt; graph.length) {<br>    var temp = stack.top;<br>    stack.pop();<br>    if (visited.contains(temp)) {<br>      continue;<br>    }<br>    visited.add(temp);<br>    var tempNode = graph.singleWhere((node) =&gt; node.element == temp);</pre><pre>    if (tempNode.adj.isNotEmpty) {<br>      for (var j in tempNode.adj) {<br>        if (visited.contains(j)) {<br>          continue;<br>        }<br>        stack.push(j);<br>      }<br>    }<br>  }<br>  print(&quot;DFS traversal of given graph\n $visited&quot;);<br>}</pre><pre>class GraphNode {<br>  final int element;<br>  List&lt;int&gt; adj = [];</pre><pre>  GraphNode({required this.element});</pre><pre>  addAdjacentElements(List&lt;int&gt; adjacent) {<br>    if (adj.isNotEmpty) {<br>      throw &quot;it already has adjacent elements&quot;;<br>    }</pre><pre>    adj = adjacent;<br>  }<br>}</pre><pre>class Stack&lt;T&gt; {<br>  List&lt;T&gt; _elements = &lt;T&gt;[];</pre><pre>  Stack(this._elements);</pre><pre>  pop() {<br>    if (_elements.isEmpty) {<br>      throw &quot;Stack underflow&quot;;<br>    }</pre><pre>    _elements.removeAt(0);<br>  }</pre><pre>  push(T element) {<br>    if (_elements.contains(element)) {<br>      return;<br>    }<br>    _elements.insert(0, element);<br>  }</pre><pre>  get top =&gt; _elements.first;</pre><pre>  get length =&gt; _elements.length;<br>}</pre><p><em>Output</em></p><p>DFS traversal of given graph<br>[0, 3, 2, 4, 1]</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b09359113999" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Breadth-First Search]]></title>
            <link>https://medium.com/@raithrishika/breadth-first-search-fd7cc6280601?source=rss-71f37d31436------2</link>
            <guid isPermaLink="false">https://medium.com/p/fd7cc6280601</guid>
            <dc:creator><![CDATA[Raithrishika]]></dc:creator>
            <pubDate>Thu, 23 Jun 2022 10:30:03 GMT</pubDate>
            <atom:updated>2022-06-23T10:30:03.706Z</atom:updated>
            <content:encoded><![CDATA[<p>The <strong>breadth-first search</strong> (BFS) algorithm visits the closest vertices from the starting vertex before moving on to further vertices.</p><h4>Algorithm</h4><ul><li><strong>Rule 1</strong> − Visit the adjacent unvisited vertex. Mark it as visited. Display it. Insert it in a queue.</li><li><strong>Rule 2</strong> − If no adjacent vertex is found, remove the first vertex from the queue.</li><li><strong>Rule 3</strong> − Repeat Rule 1 and Rule 2 until the queue is empty.</li></ul><p><strong>Source code</strong></p><pre>import &#39;dart:developer&#39;;</pre><pre>List&lt;GraphNode&gt; graph = [];<br>void main() {<br>  generateGraph();<br>  bfsTraversal();<br>}</pre><pre>void generateGraph() {<br>  graph = List.generate(5, (index) =&gt; GraphNode(element: index));<br>  graph[0].addAdjacentElements([1, 2, 3]);<br>  graph[1].addAdjacentElements([0, 2]);<br>  graph[2].addAdjacentElements([0, 1, 4]);<br>  graph[3].addAdjacentElements([0]);<br>  graph[4].addAdjacentElements([2]);<br>}</pre><pre>bfsTraversal() {<br>  Queue&lt;int&gt; queue = Queue&lt;int&gt;([]);<br>  List&lt;int&gt; visited = [];<br>  queue.enqueue(graph.first.element);<br>  while (visited.length &lt; graph.length) {<br>    var temp = queue.top;<br>    queue.dequeue();<br>    if (visited.contains(temp)) {<br>      continue;<br>    }<br>    visited.add(temp);<br>    var tempNode = graph.singleWhere((node) =&gt; node.element == temp);</pre><pre>    if (tempNode.adj.isNotEmpty) {<br>      for (var j in tempNode.adj) {<br>        if (visited.contains(j)) {<br>          continue;<br>        }<br>        queue.enqueue(j);<br>      }<br>    }<br>  }<br>  print(&quot;BFS traversal of given graph\n $visited&quot;);<br>}</pre><pre>class GraphNode {<br>  final int element;<br>  List&lt;int&gt; adj = [];</pre><pre>  GraphNode({required this.element});</pre><pre>  addAdjacentElements(List&lt;int&gt; adjacent) {<br>    if (adj.isNotEmpty) {<br>      throw &quot;it already has adjacent elements&quot;;<br>    }</pre><pre>    adj = adjacent;<br>  }<br>}</pre><pre>class Queue&lt;T&gt; {<br>  List&lt;T&gt; _elements = &lt;T&gt;[];</pre><pre>  Queue(this._elements);</pre><pre>  dequeue() {<br>    if (_elements.isEmpty) {<br>      throw &quot;queue underflow&quot;;<br>    }</pre><pre>    _elements.removeAt(0);<br>  }</pre><pre>  enqueue(T element) {<br>    if (_elements.contains(element)) {<br>      return;<br>    }<br>    _elements.add(element);<br>  }</pre><pre>  get top =&gt; _elements.first;</pre><pre>  get length =&gt; _elements.length;<br>}</pre><p><strong>Output</strong></p><p>BFS traversal of given graph<br>[0, 1, 2, 3, 4]</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fd7cc6280601" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Data Structure & Algorithms — Tree Traversal]]></title>
            <link>https://medium.com/@raithrishika/data-structure-algorithms-tree-traversal-19c9c2a7bae7?source=rss-71f37d31436------2</link>
            <guid isPermaLink="false">https://medium.com/p/19c9c2a7bae7</guid>
            <dc:creator><![CDATA[Raithrishika]]></dc:creator>
            <pubDate>Thu, 23 Jun 2022 08:44:25 GMT</pubDate>
            <atom:updated>2022-06-23T08:44:25.819Z</atom:updated>
            <content:encoded><![CDATA[<h3>Data Structure &amp; Algorithms — Tree Traversal</h3><p><em>Traversal is a process to visit all the nodes of a tree and may print their values too. Because, all nodes are connected via edges (links) we always start from the root (head) node node could have multiple children nodes, but each child could have only one parent node. The root node is the base of the tree, which has no parent node.</em></p><p><em>we use to traverse a tree −</em></p><ul><li><em>In-order Traversal</em></li><li><em>Pre-order Traversal</em></li><li><em>Post-order Traversal</em></li></ul><h3>In-order Traversal</h3><p><em>In this traversal method, the left subtree is visited first, then the root and later the right sub-tree. We should always remember that every node may represent a subtree itself.</em></p><p><em>If a binary tree is traversed </em><strong><em>in-order</em></strong><em>, the output will produce sorted key values in an ascending order.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/370/0*kTt9hvMG2JAUP-sH.jpg" /><figcaption><strong><em>D → B → E → A → F → C → G</em></strong></figcaption></figure><h4>Algorithm</h4><pre>Until all nodes are traversed −<br><strong>Step 1</strong> − Recursively traverse left subtree.<br><strong>Step 2</strong> − Visit root node.<br><strong>Step 3</strong> − Recursively traverse right subtree.</pre><h3>Pre-order Traversal</h3><p><em>In this traversal method, the root node is visited first, then the left subtree and finally the right subtree.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/370/0*H3PGEbYLOonSV5JB.jpg" /></figure><p><em>The output of pre-order traversal of this tree will be −</em></p><p><strong><em>A → B → D → E → C → F → G</em></strong></p><h4>Algorithm</h4><pre>Until all nodes are traversed −<br><strong>Step 1</strong> − Visit root node.<br><strong>Step 2</strong> − Recursively traverse left subtree.<br><strong>Step 3</strong> − Recursively traverse right subtree.</pre><h3>Post-order Traversal</h3><p><em>In this traversal method, the root node is visited last, hence the name. First we traverse the left subtree, then the right subtree and finally the root node.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/371/0*8te0yn8hkicZEm8G.jpg" /></figure><p><em>The output of post-order traversal of this tree will be −</em></p><p><strong><em>D → E → B → F → G → C → A</em></strong></p><h4>Algorithm</h4><pre>Until all nodes are traversed −<br><strong>Step 1</strong> − Recursively traverse left subtree.<br><strong>Step 2</strong> − Recursively traverse right subtree.<br><strong>Step 3</strong> − Visit root node.</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=19c9c2a7bae7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Common Data Structures in Javascript]]></title>
            <link>https://medium.com/@raithrishika/common-data-structures-in-javascript-41e5df48df48?source=rss-71f37d31436------2</link>
            <guid isPermaLink="false">https://medium.com/p/41e5df48df48</guid>
            <dc:creator><![CDATA[Raithrishika]]></dc:creator>
            <pubDate>Tue, 21 Jun 2022 09:12:33 GMT</pubDate>
            <atom:updated>2022-06-21T09:12:33.872Z</atom:updated>
            <content:encoded><![CDATA[<h4>Get a better picture of how data structures work</h4><p>Here we discussing some common data structures and implement them in JavaScript.</p><h4>1. Stack</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/391/0*aVJAy6rxayr5wFgU.png" /></figure><p><em>Stack follows the principle of LIFO (Last In First Out). If you stack books, the top book will be taken before the bottom one. Or when you browse on internet, the back button leads you to the most recently browsed page.</em></p><p><em>Stack has these common methods:</em></p><p><em>push: input a new element</em></p><p><em>pop : remove the top element, return the removed element</em></p><p><em>peek : return the top element</em></p><p><em>length : return the number of element(s) in Stack</em></p><p>source code:</p><blockquote>function Stack() {<br>this.count = 0;<br> this.storage = {};</blockquote><blockquote>this.push = function (value) {<br> this.storage[this.count] = value;<br> this.count++;<br> }</blockquote><blockquote>this.pop = function () {<br> if (this.count === 0) {<br> return undefined;<br> }<br> this.count — ;<br> var result = this.storage[this.count];<br> delete this.storage[this.count];<br> return result;<br> }</blockquote><blockquote>this.peek = function () {<br> return this.storage[this.count — 1];<br> }</blockquote><blockquote>this.size = function () {<br> return this.count;<br> }<br>}</blockquote><h3>2. Queue</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/0*-XAzpIKxCRTGT2-6.png" /></figure><p>Queue is similar to Stack. The only difference is that Queue uses the FIFO principle (First In First Out). In other words, when you queue for bus, the first in the queue will always board first.</p><p>Queue has following methods:</p><ul><li>enqueue: enter queue, add an element at the end</li><li>dequeue: leave queue, remove the front element and return it</li><li>front: get the first element</li><li>isEmpty: determine whether the queue is empty</li><li>size: get the number of element(s) in queue</li></ul><p>source code:</p><blockquote>function Queue() {<br> var collection = [];<br> this.print = function () {<br> console.log(collection);<br> }<br> this.enqueue = function (element) {<br> collection.push(element);<br> }<br> this.dequeue = function () {<br> return collection.shift();<br> }<br> this.front = function () {<br> return collection[0];<br> }</blockquote><blockquote>this.isEmpty = function () {<br> return collection.length === 0;<br> }<br> this.size = function () {<br> return collection.length;<br> }<br>}</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=41e5df48df48" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>