<?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 Tanya  on Medium]]></title>
        <description><![CDATA[Stories by Tanya  on Medium]]></description>
        <link>https://medium.com/@tanya4850.be22?source=rss-f17d3fab187f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*vNPZMPeJBpVEH7cl</url>
            <title>Stories by Tanya  on Medium</title>
            <link>https://medium.com/@tanya4850.be22?source=rss-f17d3fab187f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 04:07:06 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@tanya4850.be22/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[Dependency Injection in ASP.NET Core]]></title>
            <link>https://medium.com/@tanya4850.be22/dependency-injection-in-asp-net-core-9b5c66a4135b?source=rss-f17d3fab187f------2</link>
            <guid isPermaLink="false">https://medium.com/p/9b5c66a4135b</guid>
            <category><![CDATA[dependency-injection]]></category>
            <category><![CDATA[dotnet]]></category>
            <category><![CDATA[aspnetcore]]></category>
            <dc:creator><![CDATA[Tanya ]]></dc:creator>
            <pubDate>Thu, 25 Apr 2024 19:39:01 GMT</pubDate>
            <atom:updated>2024-04-25T19:47:29.891Z</atom:updated>
            <content:encoded><![CDATA[<p>Building Better Apps: How Dependency Injection Boosts Flexibility in ASP.NET Core</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/626/0*ini6sDMSEUDxigrl" /></figure><p><strong>—: Understanding Dependency Injection in ASP.NET Core: —</strong></p><p>Dependency Injection (DI) is a fundamental concept in modern software development that plays a crucial role in making applications more maintainable, testable, and scalable. In the context of ASP.NET Core, DI is an integral part of the framework, facilitating the management and resolution of dependencies within an application.</p><p><strong>—: What is Dependency Injection?: —</strong></p><p>At its core, Dependency Injection is a design pattern that promotes loose coupling between components in an application by removing the responsibility of creating and managing dependencies from the consuming classes. Instead of classes creating their dependencies directly, they rely on an external entity (usually a DI container) to provide these dependencies.</p><p><strong>—: Benefits of Dependency Injection: —</strong></p><ol><li><strong>Decoupling: </strong>DI promotes a loosely coupled architecture where components are independent and easier to maintain, modify, and test.</li><li><strong>Testability:</strong> By injecting dependencies, it becomes easier to mock or substitute dependencies during unit testing, enabling more effective testing strategies.</li><li><strong>Flexibility:</strong> DI allows for easier swapping of implementations, making it simpler to change behaviors or introduce new features without affecting the entire application.</li><li><strong>Scalability:</strong> Applications built using DI are often more scalable as they can adapt to changes and accommodate new requirements seamlessly.</li></ol><p><strong>—: Implementing Dependency Injection in ASP.NET Core: —</strong></p><p>ASP.NET Core has built-in support for DI through its built-in container, which is configured in the application’s startup process. Let’s walk through a simple example to demonstrate how DI works in ASP.NET Core.</p><ol><li>Define Interfaces and Implementations:</li></ol><p>public interface IWeatherService<br>{<br> string GetWeatherForecast();<br>}</p><p>public class WeatherService: IWeatherService<br>{<br> public string GetWeatherForecast()<br> {<br> return “Sunny with a chance of clouds!”;<br> }<br>}</p><p>2. Configure DI Container in Startup:</p><p>In the Startup.cs file, configure services in the ConfigureServices method:</p><p>public void ConfigureServices(IServiceCollection services)<br>{<br> services.AddTransient&lt;IWeatherService, WeatherService&gt;();<br> // Other service configurations<br>}</p><p>3. Consuming Dependencies:</p><p>Inject the dependencies into your controllers or services.</p><p>public class WeatherController : ControllerBase<br>{<br> private readonly IWeatherService _weatherService;</p><p>public WeatherController(IWeatherService weatherService)<br> {<br> _weatherService = weatherService;<br> }</p><p>public IActionResult GetForecast()<br> {<br> var forecast = _weatherService.GetWeatherForecast();<br> return Ok(forecast);<br> }<br>}</p><p>4. Run and Test: Run your ASP.NET Core application, and when the GetForecast the endpoint is called, it will use the injected IWeatherService implementation to provide the weather forecast.</p><p><strong>— :Conclusion: —</strong></p><p>Dependency Injection is a powerful technique that promotes better software design, code reusability, and testability. In ASP.NET Core, it’s seamlessly integrated, making it easy to implement and manage dependencies across your application. By understanding and leveraging DI, developers can build more maintainable and robust applications that can evolve with changing requirements and technologies.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9b5c66a4135b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Optimal Strategies for Managing API Responses and Errors in ASP.NET and .NET Core Web API]]></title>
            <link>https://medium.com/@tanya4850.be22/optimal-strategies-for-managing-api-responses-and-errors-in-asp-net-and-net-core-web-api-a232805dce38?source=rss-f17d3fab187f------2</link>
            <guid isPermaLink="false">https://medium.com/p/a232805dce38</guid>
            <category><![CDATA[exception-handling]]></category>
            <category><![CDATA[dotnet]]></category>
            <category><![CDATA[api]]></category>
            <category><![CDATA[error-handling]]></category>
            <category><![CDATA[webapi]]></category>
            <dc:creator><![CDATA[Tanya ]]></dc:creator>
            <pubDate>Thu, 25 Apr 2024 19:23:02 GMT</pubDate>
            <atom:updated>2024-04-25T19:23:02.464Z</atom:updated>
            <content:encoded><![CDATA[<h3>Optimal Strategies for Managing API Responses and Errors in ASP.NET and .NET Core Web API</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/626/0*1hEtrBpj2mCjk3Y8" /></figure><p>In modern API development, the effective handling of responses and errors is crucial. A well-designed API response not only improves user experience but also streamlines debugging and error tracing. This article will take you through the best practices for managing API responses and error handling in ASP.NET Core.</p><p><strong>— : Unified Response Format: —</strong></p><p>The Unified Response Format, or Consistent Response Schema, is like having a common language for how your API communicates with other software. It ensures that no matter what happens — whether things go right or wrong — the response always follows a clear and predictable pattern. This makes it easier for different parts of a program to understand each other and work together smoothly, making the whole system more reliable and user-friendly.</p><p>here’s a simple example in C# that demonstrates a unified response format for API responses:</p><p>using System;</p><p>public class ApiResponse&lt;T&gt;<br>{<br> public bool IsSuccess { get; set; }<br> public T Result { get; set; }<br> public string ErrorMessage { get; set; }</p><p>public ApiResponse()<br> {<br> IsSuccess = false;<br> ErrorMessage = string.Empty;<br> }</p><p>public ApiResponse(T result)<br> {<br> IsSuccess = true;<br> Result = result;<br> ErrorMessage = string.Empty;<br> }</p><p>public ApiResponse(Exception ex)<br> {<br> IsSuccess = false;<br> Result = default(T);<br> ErrorMessage = ex.Message;<br> }<br>}</p><p>In the above given code, <strong>ApiResponse</strong><strong>&lt;T&gt;</strong> is a generic class that represents the unified response format.</p><ul><li>It has properties like <strong>IsSuccess </strong>to indicate if the operation was successful, <strong>Result</strong> to hold the data in case of success, and <strong>ErrorMessage</strong> for error messages.</li><li>The class includes constructors to handle success and error scenarios, similar to the previously discussed <strong>ApiResponse</strong><strong>&lt;T&gt;</strong> model.</li></ul><p><strong>— :ApiResponse&lt;T&gt; in Controller Actions: —</strong></p><p>Now, you can use the ApiResponse&lt;T&gt; model in your controller actions to return consistent responses.</p><p>using Microsoft.AspNetCore.Mvc;<br>using System;</p><p>[Route(“api/[controller]”)]<br>[ApiController]<br>public class MyController : ControllerBase<br>{<br> [HttpGet]<br> public IActionResult Get()<br> {<br> try<br> {<br> // Perform some operation<br> var data = new { Name = “John Doe”, Age = 30 };</p><p>// Return success response<br> return Ok(new ApiResponse&lt;object&gt;(data));<br> }<br> catch (Exception ex)<br> {<br> // Log the exception<br> Console.WriteLine($”An error occurred: {ex.Message}”);</p><p>// Return error response<br> return BadRequest(new ApiResponse&lt;object&gt;(ex));<br> }<br> }<br>}</p><p>In the Get action of your controller, you can see how ApiResponse&lt;T&gt; is used to wrap both successful and error responses. When the operation is successful, you create an instance ApiResponse&lt;T&gt; with the data and return it using Ok(). In case of an exception, you catch it, log it (you can also log it to a file or a logging service), and then return an error response BadRequest() along with the ApiResponse&lt;T&gt; instance containing the exception message.</p><p>This approach ensures that your API responses follow a consistent pattern and provide meaningful information on whether the operation succeeds or encounters an error. Adjust the T type parameter of ApiResponse&lt;T&gt; as per the data type you expect to return in your API responses.</p><p><strong>—: Dealing with Errors: —</strong></p><p>It’s important to handle errors properly to keep our API reliable. We use a system to manage different types of errors in our service layer, like when there are validation problems or the server has issues.</p><p>public class UserService<br>{<br> public void CreateUser(UserModel user)<br> {<br> try<br> {<br> // Check if required fields are missing<br> if (string.IsNullOrWhiteSpace(user.Name) ||<br> string.IsNullOrWhiteSpace(user.Email) ||<br> user.Age &lt;= 0)<br> {<br> throw new ValidationException(“Name, Email, and Age are required.”);<br> }</p><p>// Process user data (this part is simplified)<br> Console.WriteLine(“User created successfully.”);<br> }<br> catch (ValidationException)<br> {<br> // Rethrow the validation exception as it is<br> throw;<br> }<br> catch (Exception ex)<br> {<br> // Log the exception and throw a simplified error message<br> LogException(ex);<br> throw new Exception(“An error occurred while processing the request.”);<br> }<br> }</p><p>private void LogException(Exception ex)<br> {<br> // Simulated logging, replace with actual logging logic<br> Console.WriteLine($”Exception logged: {ex.Message}”);<br> }<br>}</p><p>public class UserModel<br>{<br> public string Name { get; set; }<br> public string Email { get; set; }<br> public int Age { get; set; }<br>}</p><p>// Sample usage<br>var userService = new UserService();<br>var user = new UserModel { Name = “John Doe”, Email = “<a href="/service/mailto:johndoe@example.com">johndoe@example.com</a>”, Age = 30 };<br>userService.CreateUser(user);</p><p><strong>Advantages of Using the Same Response Style</strong></p><p>Using a consistent response style has many advantages. It makes handling errors on the client side easier because all responses follow the same pattern. Also, debugging becomes simpler because error messages are consistent and easier to understand.</p><p><strong>Recording and Debugging Errors</strong></p><p>Keeping track of exceptions is really important for managing errors. By using the LogException method, we gather important details that help in debugging and spotting potential issues.</p><p>private void LogException(Exception ex)<br>{<br> // Add your custom logging system here<br> // Record the exception details like message, stack trace, and other relevant info<br>}</p><p><strong>— :Conclusion: —</strong></p><p>Managing API responses and errors plays a vital role in creating robust and user-friendly APIs. Adopting a unified response format like the ApiResponse model, along with structured exception handling, brings several benefits. It simplifies error handling on the client side by providing a consistent response format, making it easier for clients to understand and process API responses uniformly. Furthermore, structured exception handling helps capture and manage different types of errors gracefully. By throwing custom exceptions and logging them appropriately, you can streamline the debugging process and identify issues more efficiently. This approach not only improves the overall user experience but also enhances the reliability and maintainability of your ASP.NET Web API. In summary, by following best practices such as using a unified response format and implementing structured error-handling techniques, you can elevate the quality of your API, reduce development time, and ensure a smoother experience for both developers and end-users.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a232805dce38" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Elevate Your API Testing Game with Postman]]></title>
            <link>https://medium.com/@tanya4850.be22/elevate-your-api-testing-game-with-postman-6b9307b14427?source=rss-f17d3fab187f------2</link>
            <guid isPermaLink="false">https://medium.com/p/6b9307b14427</guid>
            <category><![CDATA[postman-testing]]></category>
            <category><![CDATA[postman]]></category>
            <category><![CDATA[webapi]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[api]]></category>
            <dc:creator><![CDATA[Tanya ]]></dc:creator>
            <pubDate>Wed, 24 Apr 2024 16:38:16 GMT</pubDate>
            <atom:updated>2024-04-24T16:38:16.801Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/244/0*-sEaMr-g9rk8VfLW" /></figure><p>This article will teach you how to use POSTMAN to test Web API Services. You’ll see examples and learn how to send requests and check responses to make sure your APIs work correctly.</p><p>This article will cover the following topics:-</p><ol><li>Introduction to Postman</li><li>Importance Of Testing Web API Services with Postman</li><li>Understanding Postman’s request and response features</li><li>Using Postman for testing Get, Post, Put, and Delete requests</li></ol><p><strong>—: Introduction to Postman: —</strong></p><p>Postman is a powerful tool used for testing and working with web APIs. It simplifies the process of sending requests to web servers and receiving responses, which is essential for developers who need to test and debug their APIs. Postman provides a user-friendly interface that allows users to create, organize, and automate API tests, making it a valuable asset for anyone involved in API development or testing.</p><p><strong>—: Importance Of Testing Web API Services with Postman: —</strong></p><p>Testing Web API Services with Postman is a crucial aspect of ensuring the functionality and reliability of your APIs. Postman provides a user-friendly interface that allows you to create and send requests to your API endpoints easily. You can test various HTTP methods such as GET, POST, PUT, and DELETE, as well as handle parameters, headers, and authentication methods within Postman. Additionally, Postman allows you to organize and save your API tests, collaborate with team members, and automate testing workflows, making it an indispensable tool for developers and testers working with web APIs.</p><p><strong>—: Understanding Postman’s request and response features: —</strong></p><p><strong>1. Request Features:</strong></p><p><strong>HTTP Methods:</strong> Postman supports various HTTP methods like GET, POST, PUT, DELETE, etc., allowing you to interact with APIs according to their requirements.</p><p><strong>Request URL:</strong> You can specify the URL of the API endpoint you want to test or work with.</p><p><strong>Headers:</strong> You can add custom headers such as Content-Type, Authorization, etc., to your request. These headers provide additional information to the server about the request.</p><p><strong>Parameters: </strong>Postman allows you to add query parameters or request body parameters depending on the HTTP method and API specifications.</p><p><strong>Authentication:</strong> Postman supports various authentication mechanisms like Basic Auth, OAuth, API keys, JWT Token, etc., making it easy to test APIs that require authentication.</p><p><strong>Pre-request Scripts:</strong> You can write scripts in JavaScript that run before sending the request. This is useful for setting up dynamic data or environment variables.</p><p><strong>Body:</strong> For requests that require a body (e.g., POST or PUT requests), you can define the body content using various formats like JSON, form-data, x-www-form-urlencoded, raw text, etc.</p><p><strong>2. Response Features:</strong></p><p><strong>Status Code:</strong> Postman displays the HTTP status code (e.g., 200 OK, 404 Not Found, 204 No Content, 500 Internal Server Error, 201 Created) returned by the server in the response.</p><p><strong>Headers:</strong> It shows the response headers returned by the server, such as Content-Type, Cache-Control, etc.</p><p><strong>Response Body:</strong> Postman displays the response body received from the server. This can be in different formats like JSON, XML, HTML, or plain text, depending on the API’s response format.</p><p><strong>Test Scripts:</strong> You can write test scripts in JavaScript that automatically validate the response received. These scripts can check for specific values, status codes, headers, etc., and provide feedback on whether the API is working as expected.</p><p><strong>Response Time:</strong> Postman measures and displays the time taken to receive the response from the server, helping you assess performance.</p><p><strong>—: Using Postman for testing Get, Post, Put, and Delete requests: —</strong></p><p><strong>GET Request:-</strong><br>Choose the “GET” HTTP Method and input the URL of your Web API, following the example shown in the image below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/965/1*Ihxd7-qrSJl2PksZ-8B59g.png" /></figure><p>After clicking the Send button, an HTTP request is dispatched to the specified URL. The subsequent response from the Web API Server is presented in the image below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/930/1*7qYnS27vpo6-AdOThz3Rpw.png" /></figure><p>As depicted in the image above, the HTTP response includes both data and response status. This capability enables you to utilize Postman for testing your Web API as well.</p><p><strong>POST Request:-</strong></p><p>Select the POST HTTP method, then set the URL accordingly. Additionally, ensure the Content-Type is set to application/JSON. You can achieve this by navigating to the Header tab and providing the key-value pair as demonstrated in the image below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/955/1*NqkuKn7vdMO38eTGzixLPA.png" /></figure><p>To add a string value to the string array, you’ll need to provide the string values in the request body. To accomplish this, click on the Body tab and input the string value as demonstrated below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*po2VWFLKhnkfF_TXe7uqKA.png" /></figure><p>After entering the string value in the request body, click on the Send button to initiate a POST request to the web API. Similarly, you can test PUT and DELETE requests by selecting the respective HTTP methods, setting the appropriate URL and parameters, and then clicking Send to send the requests to the API endpoint. This allows you to test different CRUD operations and ensure your API functions correctly for each type of request.</p><p>In conclusion, Postman is an invaluable tool for API testing and development, offering a comprehensive suite of features to streamline the process. By leveraging Postman’s capabilities, developers can easily send requests, inspect responses, and validate API functionality across various HTTP methods like GET, POST, PUT, and DELETE. The ability to handle parameters, headers, authentication, and scripting further enhances testing capabilities, ensuring APIs work as expected. With Postman, developers can enhance their API testing workflows, collaborate effectively, and deliver robust and reliable web API services.</p><p>THANKYOU !!!!!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6b9307b14427" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Explore Nine Essential C #.NET Code Snippets]]></title>
            <link>https://medium.com/@tanya4850.be22/explore-nine-essential-c-net-code-snippets-9623b254d878?source=rss-f17d3fab187f------2</link>
            <guid isPermaLink="false">https://medium.com/p/9623b254d878</guid>
            <category><![CDATA[basics-of-programming]]></category>
            <category><![CDATA[dotnet-core]]></category>
            <category><![CDATA[jwt-token]]></category>
            <category><![CDATA[model]]></category>
            <category><![CDATA[controller]]></category>
            <dc:creator><![CDATA[Tanya ]]></dc:creator>
            <pubDate>Tue, 23 Apr 2024 11:34:58 GMT</pubDate>
            <atom:updated>2024-04-23T11:34:58.251Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-DIbe-Muq5ERIYlyc4vyUQ.jpeg" /></figure><p>When it comes to C# programming in the.NET framework, simplicity and efficiency are critical. Code readability may be improved and development workflows can be significantly simplified by utilizing the power of concise and useful code snippets. Knowing these ten helpful code snippets can improve the quality and maintainability of your C# programs and increase your productivity.</p><ol><li><strong>Design Model Classes- </strong>Creating blueprints for the structure and manipulation of data inside an application is the process of designing model classes. The attributes and behaviors of real-world entities are usually defined and represented in these classes. For software development projects to maintain code organization, readability, and scalability, well-designed model classes are essential.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/662/1*GvZgK87S54Nmivy7wP2S6w.png" /></figure><p><strong>2. Object Initialization- </strong>Object creation is the process of instantiating a class to generate an object in programming. It includes allocating memory for the object and defining its state based on the class structure and any constructor parameters provided. Object creation is essential to object-oriented programming (OOP) paradigms, allowing for the creation of instances that encapsulate data and behavior within a software system.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/738/1*yuB-kDz93jTKNlLlAXyppA.png" /></figure><p><strong>3. Exception Handling-</strong>Exception handling is an important part of building strong and dependable code in any programming language. It involves detecting and responding to unusual situations that may arise during program execution, such as runtime faults or unexpected behavior. In C#, exception handling is commonly accomplished with try-catch blocks, which contain code that may throw an exception and particular exception-handling logic in catch blocks.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/610/1*QetbSFucLE7wso9OLxFQ4A.png" /></figure><p><strong>4. Entity Framework Core for Database Operations- </strong>Entity Framework Core simplifies database operations in C# by introducing an object-relational mapping (ORM) framework. It enables developers to interact with databases directly using C# objects, abstracting most of the underlying SQL code. EF Core allows one to effortlessly conduct CRUD activities (Create, Read, Update, Delete) on database entities, manage relationships, and execute queries, which speeds up development and reduces boilerplate code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/442/1*oyHy9z6AkPUYQYKg-OfAFw.png" /></figure><p><strong>5. Controller Template- </strong>A controller template in ASP.NET MVC often contains boilerplate code for handling incoming HTTP requests and interacting with model and view components. It defines action methods to respond to various HTTP methods (GET, POST, PUT, DELETE) communicates with the model layer to fetch or change data, and returns appropriate views or JSON replies. Controller templates are the key component for routing and processing user requests in MVC web applications.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/990/1*yzOxHQXCrsX7QSRjpVEmYQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5FNw_Crino7Ps3ZJN_p8nA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/901/1*zEw9cv3nayRepAF0TQe9kA.png" /></figure><p><strong>6. JWT Template- </strong>A JWT (JSON Web Token) template offers a standardized approach to creating and validating JWTs in web applications. It includes code for creating tokens with specified claims, signing and verifying tokens with cryptographic techniques, and managing token-based authentication and authorization.</p><p>var claims = new List&lt;Claim&gt;<br>{<br> new Claim(ClaimTypes.Name, “username”),<br> new Claim(ClaimTypes.Role, “admin”),<br> // Add more claims as needed<br>};</p><p>var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(“your_secret_key”));<br>var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256);</p><p>var token = new JwtSecurityToken(<br> issuer: “your_issuer”,<br> audience: “your_audience”,<br> claims: claims,<br> expires: DateTime.Now.AddMinutes(30),<br> signing credentials: creds);</p><p>return new JwtSecurityTokenHandler().WriteToken(token);</p><p><strong>7. Ternary Operator- </strong>The ternary operator in C# is a simplification for writing conditional expressions with three operands: a condition, a value to return if the condition is true, and a value to return if the condition is false.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/496/1*HBMUUvkoEHf3E4HRoCHDGA.png" /></figure><p><strong>8. Basic Template of Program.cs file- </strong>In a C# console project, the Program.cs file normally contains the application’s entry point. It initializes the program, configures it as needed, and runs the core logic. Setting up dependency injection and launching the application’s principal functionality are examples of common Programs.cs duties.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/465/1*q6zzkwPI7zqn4VSA81ZmsQ.png" /></figure><p><strong>9. Swagger for API documentation- </strong>Swagger is a popular tool for creating interactive API documentation using OpenAPI It makes API testing and research easier by offering a user-friendly interface that identifies endpoints, specifies request and response formats, and enables users to make API calls directly from the documentation page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/683/1*XcJCQP9pmT9kSreESPtjKQ.png" /></figure><p>Thankyou!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9623b254d878" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mastering Modern .NET Web Development]]></title>
            <link>https://medium.com/@tanya4850.be22/mastering-modern-net-web-development-87828bd794b0?source=rss-f17d3fab187f------2</link>
            <guid isPermaLink="false">https://medium.com/p/87828bd794b0</guid>
            <category><![CDATA[authentication]]></category>
            <category><![CDATA[authorization]]></category>
            <category><![CDATA[dotnet]]></category>
            <category><![CDATA[ef-core]]></category>
            <category><![CDATA[ef]]></category>
            <dc:creator><![CDATA[Tanya ]]></dc:creator>
            <pubDate>Tue, 23 Apr 2024 10:35:47 GMT</pubDate>
            <atom:updated>2024-04-23T10:36:35.441Z</atom:updated>
            <content:encoded><![CDATA[<h3>Mastering Modern .NET Web Development</h3><p><em>A Deep Dive into Cutting-Edge Techniques and Best Practices</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ArEEmMjPlq_nSU8Wdbw_4w.jpeg" /></figure><p>The.NET ecosystem stands out as an outstanding tool for creating reliable, scalable, and feature-rich web applications. There is an extensive range of advanced topics that go beyond the fundamentals and can push your web development abilities to new heights. Let’s start to find out these cutting-edge ideas and fully utilize them for web development.</p><ol><li><strong>ASP.NET Core MVC: Crafting Dynamic Web Experiences:-</strong></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/647/0*XFWUYNDOTODftqwo.PNG" /></figure><p>Explore the world of ASP.NET Core MVC, a paradigm-shifting framework that follows the Model-View-Controller design. Learn how MVC separates concerns, promotes clean code, and allows developers to create dynamic and interactive web pages.</p><p><strong>2. Entity Framework Core: Simplifying Database Interactions:-</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*rTjdgz7fgZBY121Y.png" /></figure><p>Discover the simplified design of Entity Framework Core (EF Core), which uses object-relational mapping(ORM) to optimize database operations. From data modeling to migrations and beyond, EF Core streamlines.NET developers’ interactions with databases, increasing productivity and maintainability.</p><p><strong>3. Authentication and Authorization: Securing Your Web Applications</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*RvEPyJVQdwY5Kp7uTLOPrQ.png" /></figure><p>Learn about authentication and authorization in ASP.NET Core. Investigate various authentication systems, apply role-based access management, and strengthen your web applications to protect against security threats, guaranteeing a secure and seamless user experience.</p><p><strong>4. Dependency Injection (DI) and Middleware: Building Modular and Scalable Apps</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/462/0*W1U5sHUPqMef4QLm.png" /></figure><p>Use Dependency Injection (DI) and Middleware in ASP.NET Core to create modular, tested, and scalable online applications. Learn how DI promotes loose coupling and how Middleware allows you to plug into the request pipeline and add functionality at various stages of the HTTP request lifecycle.</p><p><strong>5.ASP.NET Core Web API: Empowering API-First Development</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1021/0*Oag9E-5oiptGBkgM.jpg" /></figure><p>ASP.NET Core Web API allows you to join the world of API-First programming. Learn how to create RESTful APIs, manage HTTP requests and responses implement versioning, and protect your APIs using tokens and policies to enable smooth integration and interoperability.</p><p><strong>6. Real-Time Communication with SignalR: Powering Interactive Web Apps</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*TO-ZxbCA0fI7F51DM8c_Iw.png" /></figure><p>Discover SignalR, an ASP.NET Core real-time communication library that allows clients and servers to communicate in both directions. Discover how SignalR makes it easier to create interactive features like live updates, chat applications, and collaborative tools, which improves user engagement and experience.</p><p><strong>7. Testing and DevOps: Ensuring Quality and Efficiency</strong></p><p>Discover the value of testing and DevOps approaches in .NET web development. Learn about unit testing, integration testing, continuous integration (CI), and continuous deployment (CD) pipelines with popular tools such as xUnit, NUnit, Azure DevOps, and GitHub Actions to ensure code quality, stability, and efficiency across the development lifecycle.</p><p><strong>8. Microservices Architecture: Scalability and Agility at Scale</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/539/0*pAORsAEUcyny8Aje.png" /></figure><p>Explore the world of microservices architecture with .NET Core, in which applications are divided into unique independently deployable services. Learn about Docker containers, Kubernetes orchestration, and the benefits of microservices in complex and distributed systems, such as scalability, durability, and agility.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/469/0*gbNgT5ypgZkEP28l.jpg" /></figure><p>As we conclude our exploration of these advanced concepts in .NET web development, it’s clear that the .NET ecosystem offers a rich toolkit for developers to create modern, high-performance web applications. By mastering these concepts, developers can elevate their skills, build scalable and secure solutions, and stay at the forefront of the rapidly evolving web development landscape. Embrace the power of .NET and unleash your creativity in crafting exceptional web experiences.</p><p>Thank you !</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=87828bd794b0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Efficiency Unleashed: Exploring Minimal APIs in .NET]]></title>
            <link>https://medium.com/@tanya4850.be22/efficiency-unleashed-exploring-minimal-apis-in-net-605be5d01757?source=rss-f17d3fab187f------2</link>
            <guid isPermaLink="false">https://medium.com/p/605be5d01757</guid>
            <category><![CDATA[vscode]]></category>
            <category><![CDATA[dotnet-core]]></category>
            <category><![CDATA[endpoints]]></category>
            <category><![CDATA[crud-operations]]></category>
            <category><![CDATA[minimal-api]]></category>
            <dc:creator><![CDATA[Tanya ]]></dc:creator>
            <pubDate>Tue, 23 Apr 2024 07:44:12 GMT</pubDate>
            <atom:updated>2024-04-23T07:44:12.789Z</atom:updated>
            <content:encoded><![CDATA[<h3>Efficiency Unleashed: Exploring Minimal APIs in .NET</h3><p>The following article demonstrates the easy method of developing a minimum API with .NET 8.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-LlQmBap9Jn2WmPhZJ_LeQ.jpeg" /></figure><p>A larger percentage of modern development frameworks are using minimal APIs because of their accessibility, efficiency, and simplicity. They provide a more efficient method of developing APIs by minimizing the quantity of standard code and settings that are typically needed in frameworks such as ASP.NET. To create HTTP APIs with the fewest dependencies possible, the Dotnet team created Minimal APIs. These APIs are ideal for microservices and other applications that require only the necessary ASP.NET Core files, features, and dependencies. They provide a reliable and lightweight framework for developing scalable and effective APIs. Moreover, minimal APIs promote code readability and maintainability by encouraging a more concise and structured coding style. With fewer files and configurations to manage, developers can better organize their codebase and reduce the cognitive load associated with navigating through multiple layers of abstraction.</p><p><strong>“Advantages of Using Minimal APIs in ASP.NET Core”</strong></p><ol><li><strong>Simplicity:</strong> Minimal APIs significantly reduce the amount of boilerplate code and configuration required to create HTTP APIs. This simplicity leads to cleaner and more concise code, making it easier for developers to understand, maintain, and debug their applications.</li><li><strong>Faster Development:</strong> With fewer files, features, and dependencies to manage, developers can create APIs more quickly. Minimal APIs allow developers to focus on defining logic and implementing core functionality without being weighed down by unnecessary complexity.</li><li><strong>Reduced Overhead:</strong> By eliminating unnecessary components and configurations, minimal APIs have lower overhead compared to traditional API setups. This results in faster performance and reduced resource consumption, making them well-suited for high-performance applications and microservices.</li><li><strong>Scalability: </strong>Minimal APIs are designed to be lightweight and scalable, making them ideal for building microservices and cloud-native applications. They provide a solid foundation for creating modular and independently deployable services that can easily scale based on demand.</li><li><strong>Ease of Maintenance:</strong> The simplified structure of minimal APIs makes them easier to maintain over time. With fewer moving parts and dependencies, developers can update and enhance their APIs more efficiently, reducing the risk of compatibility issues.</li></ol><p><strong>—: Creating Minimal APIs Using the Command Line Interface (CLI): —</strong></p><p><strong>dotnet new web -o “output directory or folder name”</strong></p><p>For Example:-</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HrvgQhbndw0DhzLawrhNAg.png" /><figcaption>Creating a Minimal ASP.NET Core Web Project: dotnet new web</figcaption></figure><p>Executing the command ‘dotnet new web -o Mini_Proj will generate an API within the ‘Mini_Proj’ folder. After thoroughly examining, you’ll notice that the folder contains only two crucial files: Program.cs and the .csproj file. Looking into Program.cs, you’ll find a few lines of code, showcasing the simplicity and minimalism of the created API setup.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/886/1*9nlJtFx3x9GN2qTASThoyQ.png" /></figure><p>After running the application, you’ll notice it’s running and listening on localhost.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZLnVHTI9btrY3vyjnptgIw.png" /></figure><p>After this, you are good to go for creating your minimal APIs for various CRUD (Create, Retrieve, Update, Delete) operations based on your application.</p><p>I will be providing the basic syntax for each type of minimal API i.e., GET, POST, PUT, DELETE, and PATCH.</p><p>A GET request’s main objective is to retrieve data from a particular server resource. A webpage, an API endpoint, an image, a file, or any other resource that can be accessed could represent this resource.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/546/1*uA7umthqGuzxXSZ78W8hTg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*Yolml81Owa_dB5OE2IQd8w.png" /></figure><p>The creation of a new resource on the server is one of the main goals of a POST request. This could be any action that leads to the creation of a resource, such as making a new user account or adding a record to a database.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/612/1*LLjFFeCu7kp6ngM5q5D4_A.png" /></figure><p>Although PUT and PATCH are both used to update resources, they use different approaches when it comes to updating data. PATCH is used for partial changes, and PUT is used for complete replacements.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/710/1*HTtrXq05Kn_4V6tk7zLgEg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/927/1*ZOsVNtO9wPZx8FE4A7MmNg.png" /></figure><p>Direct methods such as MapPatch are not accessible in ASP.NET Core Minimal APIs. Alternatively, you may use the app.MapMethods function to handle PATCH requests. You can handle particular HTTP methods with this method, such as PATCH, along with the associated endpoint.</p><p>The app.MapDelete method makes sure that the lambda function’s provided logic is executed when a DELETE request is sent. This logic involves eliminating the resource from your database with the provided ID.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/620/1*S0bnYeDKZLn3WRVJDkv9dg.png" /></figure><p>Thank you!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=605be5d01757" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Getting Started with the Database-First Approach With Entity Framework in.NET]]></title>
            <link>https://medium.com/@tanya4850.be22/getting-started-with-the-database-first-approach-with-entity-framework-in-net-8b74837923b2?source=rss-f17d3fab187f------2</link>
            <guid isPermaLink="false">https://medium.com/p/8b74837923b2</guid>
            <category><![CDATA[template]]></category>
            <category><![CDATA[dotnet-core]]></category>
            <category><![CDATA[reverse-engineering]]></category>
            <category><![CDATA[handlebars]]></category>
            <category><![CDATA[scaffolding]]></category>
            <dc:creator><![CDATA[Tanya ]]></dc:creator>
            <pubDate>Wed, 17 Apr 2024 17:53:28 GMT</pubDate>
            <atom:updated>2024-04-17T17:53:28.925Z</atom:updated>
            <content:encoded><![CDATA[<h3>Getting Started with the Database-First Approach With Entity Framework in.NET 8.0: Implementing Scaffolding Handlebars Templates for PostgreSQL</h3><p>When it comes to specifying the data model and how it interacts with the database as part of .NET development using Entity Framework, developers can employ a variety of methods. These techniques include Code-First, Model-First, and Database-First methodologies, each with its own significance.</p><ol><li>Code-First Approach- Without first designing a database schema, developers begin the Code-First approach by defining the domain classes and their relationships in code. The database schema is then created by Entity Framework during application setup using these classes as a basis.</li><li>Model-First Approach- The Model-First method involves using EDMX (Entity Data Model XML) or the visual designer tools in Entity Framework to create a conceptual model. With these tools, developers create the entity types, relationships, and inheritance structures graphically. From this model, Entity Framework then generates the code classes and database schema.</li><li>Database-First Approach- Database-First is a popular development process that starts with designing the database schema and then generates corresponding code models with Entity Framework.</li></ol><p>This article provides a comprehensive guide for developers interested in exploring the Database-First strategy using Entity Framework in.NET applications, with a specific focus on working with PostgreSQL databases.</p><p><strong>Step 1: Creating Table Schema using DDL Commands</strong></p><p>Let’s say we have to develop a simple web application that tracks events, manages employee data, and handles employee’s salaries.</p><p>This application will have the following tables to illustrate the database-first approach:-<br>1. Employee- for maintaining employee details,</p><p>2. Event- for monitoring events,</p><p>3. Employee Salary- for handling salary information.</p><p>The fundamental elements of a database-driven application built with the database-first approach are displayed in these tables. To create the tables discussed above, the table schema will be defined in a PostgreSQL database using several DDL (Data Definition Language) commands. They describe the structure and constraints of each table in the database.</p><p>Following are the table schemas generated with the CREATE command:</p><p>CREATE TABLE public. employee</p><p>(</p><p>employee_id int PRIMARY KEY GENERATED ALWAYS AS IDENTITY,</p><p>employee_name varchar(100) NOT NULL,</p><p>employee_email varchar(100) NOT NULL,</p><p>designation varchar(80) NOT NULL</p><p>);</p><p>CREATE TABLE public. event</p><p>(</p><p>event_id int PRIMARY KEY GENERATED ALWAYS AS IDENTITY,</p><p>event_name varchar(100) NOT NULL,</p><p>event_date TIMESTAMP NOT NULL,</p><p>event_location varchar(200) NULL,</p><p>event_description varchar(300) NULL</p><p>);</p><p>CREATE TABLE public.employee_salary</p><p>(</p><p>salary_id int PRIMARY KEY GENERATED ALWAYS AS IDENTITY,</p><p>employee_id int NOT NULL,</p><p>salary_amount numeric(12, 2) NOT NULL,</p><p>payment_date TIMESTAMP NOT NULL</p><p>);</p><p>Next, here are the screenshots provided after executing the commands:-</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/746/1*BcpXJ4jD321gUcGV8uDfXw.png" /><figcaption>Table 1: Employee Table</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/746/1*BcpXJ4jD321gUcGV8uDfXw.png" /><figcaption>Table 2: Event Table</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/699/1*sfVUSAC_qh1T5eB-Bx5elA.png" /><figcaption>Table 3: Employee Salary Table</figcaption></figure><p><strong>Step 2: Create a New Dotnet Web Project and Install the Required Packages</strong></p><p>Firstly, create a new dotnet web project in Visual Studio Code by using the command dotnet new webapi in the terminal.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zq7geFlP5oQrpe26zdsfgA.png" /></figure><p>Then, add the following packages to your application to successfully generate the Model classes as per the database schema.</p><p><strong>1. dotnet add package EntityFrameworkCore.Scaffolding.Handlebars — version 8.0.0-beta2</strong></p><p><strong>2. dotnet add package Microsoft.EntityFrameworkCore</strong></p><p><strong>3. dotnet add package Microsoft.EntityFrameworkCore.Design</strong></p><p><strong>4. dotnet add package Npgsql</strong></p><p><strong>5. dotnet add package Npgsql.EntityFrameworkCore.PostgreSQL</strong></p><p><strong>Step 3: Generate the Model Classes</strong></p><p>Further, create a new file named <strong>ScaffoldingDesignTimeServices</strong> and add the below-given code in this file-</p><p>using Microsoft.EntityFrameworkCore.Design;</p><p>public class ScaffoldingDesignTimeServices: IDesignTimeServices</p><p>{</p><p>public void ConfigureDesignTimeServices(IServiceCollection services)</p><p>{</p><p>services.AddHandlebarsScaffolding();</p><p>}</p><p>}</p><p>This class, ScaffoldingDesignTimeServices, is used in the Entity Framework Core (EF Core) context to customize scaffolding design-time services. Its main purpose is for scaffolding database entities with Handlebars templates.</p><p><strong>services.AddHandlebarsScaffolding();- </strong>This line is where the actual customisation occurs.</p><p><strong>AddHandlebarsScaffolding()</strong> is a method that is used to add Handlebars-specific scaffolding services to the IServiceCollection interface. These services could contain custom templates, code generators, and other scaffolding-related utilities based on Handlebars templates.</p><p>Finally, you need to execute the given command to generate the model classes from the database.</p><p>dotnet ef dbcontext scaffold `<br> “Host=localhost; Database=test; Username=postgres; Password=mypassword” `<br> Npgsql.EntityFrameworkCore.PostgreSQL `<br>— output-dir Models `</p><p>Brief explanation of the above command is as follows:-</p><p><strong>dotnet ef dbcontext scaffold-</strong> This portion uses the Entity Framework Core (EF Core) scaffolding tool (dotnet ef) to create C# classes for the database tables using an existing database schema. The dbcontext scaffold command creates a DbContext and entity classes based on the database schema.</p><p><strong>“Host=localhost; Database=test; Username=postgres; Password=mypassword”-</strong> This is the connection string used to connect to the PostgreSQL database named test.</p><p><strong>Npgsql.EntityFrameworkCore.PostgreSQL-</strong> This section defines which EF Core provider to utilize for PostgreSQL databases. In this example, here it utilizes the Npgsql.EntityFrameworkCore. <br> <br><strong>-output-dir Models- </strong>This defines the output directory where the created DbContext and entity classes will be stored. In this case, it is set to Models, which means that the created files will be saved in a folder called Models.</p><p>After following all these steps you will get the following result:-</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vXU6dzqYy1de97UVNd7XQQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/338/1*aX_oiFfS6a7DkipTi37spA.png" /><figcaption>Generated Model classes</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/726/1*Ag7lKGVLDpPtYf-Xx_Bc5A.png" /><figcaption>Employee Class</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/653/1*hs5qe8rKg0YzJRZWOhnT-g.png" /><figcaption>Employee Salary Class</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/690/1*QtrHuWqmP5oirMDnlffJEg.png" /><figcaption>Event Class</figcaption></figure><p><a href="https://drive.google.com/file/d/1UrBA8eyUIulihchokIz_UIuP7Ri691va/view?usp=sharing">templating.mp4</a></p><p><strong>CONCLUSION</strong></p><p>To conclude, we implemented the database-first strategy with Entity Framework in.NET Core 8 by following the procedures mentioned above Initially, we created a database schema for a project using various DDL commands. Next, we installed the necessary Entity Framework packages in Visual Studio Code. Finally, we used the Scaffolding Handlebars command to generate model classes and the database context from the existing database structure.</p><p>Using Entity Framework in a database-first strategy allows developers to easily integrate their existing databases into their.NET Core applications. This solution optimizes development by removing the need to manually create models and context classes.</p><p>Thank you!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8b74837923b2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[“Cracking the Code: Diverse Problem-Solving Approaches]]></title>
            <link>https://medium.com/@tanya4850.be22/cracking-the-code-diverse-problem-solving-approaches-34054b47eda8?source=rss-f17d3fab187f------2</link>
            <guid isPermaLink="false">https://medium.com/p/34054b47eda8</guid>
            <category><![CDATA[approach]]></category>
            <category><![CDATA[data-structure-algorithm]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[algorithms]]></category>
            <dc:creator><![CDATA[Tanya ]]></dc:creator>
            <pubDate>Tue, 10 Oct 2023 08:41:36 GMT</pubDate>
            <atom:updated>2023-10-10T08:41:36.643Z</atom:updated>
            <content:encoded><![CDATA[<p>An algorithm is a set of organized steps and methods designed to solve a problem. Although many algorithms can be developed for different problems, in programming, we emphasize a certain category of algorithms as being critical for problem resolution. The key to effectiveness is to optimize both time and space.<br><strong>1. Brute Force Algorithm</strong></p><p>This is the most fundamental and straightforward sort of algorithm. A Brute Force Algorithm is the simplest solution to a problem, or the first solution that comes to mind when we perceive the problem. More technically, it is the same as iterating through every possible solution to the problem.<br>Assume you need to find the smallest number in an unsorted collection of numbers. A brute force approach would begin by comparing the initial number to each of the other numbers in the list. If it comes across a smaller number, it will update the minimum value. This procedure is performed for each number in the list to ensure that all values have been checked.</p><p>While this method ensures that the smallest value is found, it can be computationally costly for big datasets. The time and resources required by the brute force technique expand exponentially as the size of the problem space grows.</p><p>Despite being normally less effective than optimized alternatives, brute force techniques might be useful in some circumstances. The following are some situations in which a brute-force approach may be appropriate:<br><strong>1.1 </strong>Password cracking frequently uses brute force strategy, particularly when the password is weak or there is no limit on the number of attempts. This algorithm carefully checks each possible character combination until the right password is found.</p><p><strong>1.2</strong> In cryptography, brute force algorithms are used to decrypt encryption codes when other approaches fail. The algorithm carefully investigates every possible key in search of the proper one that unlocks the encrypted message.</p><p><strong>2. Recursive Algorithm</strong></p><p>Recursion is a useful tool; nevertheless, careful attention to memory management is required. Recursion works by invoking a recursive stack each time the recursive function is called. Recursion is essentially the process of calling itself to handle its subproblems.</p><p><strong>a) Divide And Conquer Algorithm<br></strong>An algorithm known as “divide and conquer” is a method of breaking down a big task into more manageable parts. In order to get the desired result, the subproblems must be solved and combined. Hence, it includes three parts namely- divide, conquer and then combine.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/506/1*vlnxWxde4JpTtnmuFC0auA.png" /></figure><p>Some applications are- merge sort, binary search, quick sort etc.<br><strong>b) Dynamic Programming Algorithms<br></strong>A computer programming approach called dynamic programming aids in the quick solution of a group of problems with overlapping subproblems and optimum substructure properties.<br>If we can divide a large problem into smaller ones, and these smaller ones can be divided further, and they share common elements, we can save the solutions to these smaller problems to make things go faster the next time. This method is known as dynamic programming. It makes the computer operate more efficiently by minimizing the need to repeat the same computations in order to obtain the optimum result.<br>There are two versions of this algorithm:<br>1. Top-down approach- Starts solving problems from the beginning in order to arrive at the appropriate subproblem, which is then solved utilizing previously solved subproblems.<br>2. Bottom-up approach- Starts solving the problems from the bottom, i.e. solving the last feasible subproblems first and utilizing the results of those and solving the above subproblems.<br><strong>c)Greedy Approach<br></strong>A greedy algorithm is like making decisions based on what looks best at each stage without considering if it will result in the best overall conclusion. When a decision is made, it is followed through on, even if it subsequently proves to be incorrect. It operates from the top down, without going back.</p><p>However, it is crucial to note that this strategy may not always produce the optimal results for every case. Some applications are- Dijkstra’s shortest path algorithm, minimum spanning tree, network routing etc.</p><p><strong>d)Backtracking Algorithm<br></strong>This strategy is preferable to attempting each option one by one. Instead, we start with an option and work our way to a solution. If that works, great — we have a solution. If not, we return to the previous option and try again. It’s a game of trial and error, but we’re making progress by returning to the previous choice that worked and attempting new ones from there. This is a type of recursion in which we return to a working point and consider alternative choices.<br><strong>3. Randomized Algorithm<br></strong>A Randomised Algorithm is a type of algorithm that employs random numbers to determine what to do at particular points. In Randomised Quick Sort, for example, we utilize a random integer to select the next pivot or shuffle the array at random. This randomness is typically utilized to speed up regular algorithms or to consume less memory. Some applications of this approach are- robotics and path planning, sorting algorithms, cryptography etc.</p><p><strong>4. Hashing Algorithm</strong><br>A hashing algorithm is a function that converts data of any size to a fixed-size value known as a hash or a hash code. <br>Hashing techniques may be found in a wide range of applications, including cryptography, data structures, and databases.<br><strong>5. Searching Algorithm<br></strong>Searching Algorithms are intended to search for or retrieve an element from any data structure in which it is stored. Two main types of searching algorithms are- linear and binary search.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=34054b47eda8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[“Rooted in Logic: The Elegance of Binary Trees”]]></title>
            <link>https://medium.com/@tanya4850.be22/rooted-in-logic-the-elegance-of-binary-trees-e3be23df2055?source=rss-f17d3fab187f------2</link>
            <guid isPermaLink="false">https://medium.com/p/e3be23df2055</guid>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[data-structures-algorithm]]></category>
            <category><![CDATA[binary-tree]]></category>
            <dc:creator><![CDATA[Tanya ]]></dc:creator>
            <pubDate>Tue, 10 Oct 2023 07:16:01 GMT</pubDate>
            <atom:updated>2023-10-10T07:16:01.805Z</atom:updated>
            <content:encoded><![CDATA[<p>Each node in a normal tree can have several children. A binary tree, on the other hand, is a distinct kind of tree structure in which each node is limited to a maximum of two children, referred to as the left child and the right child. Hence, a binary tree refers to a tree in which each node can have a <strong>maximum of two children </strong>indicating that each node can have either 0 children, 1 child, or 2 children, but not more than 2.</p><p><strong>Example-</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/865/1*J8569gy5snV6U9zMYCkl1A.png" /></figure><p>Each node in this example of a binary tree has a maximum of two children, forming a hierarchical structure. A tree with a root at 10 and values 5, 15, 3, 7, 12, 18, 2, 4,14, and 13 results from placing the values in a non-linear arrangement.<br>There are different types of binary trees which are as follows:</p><p><strong>1.</strong> <strong>Strictly Binary Tree</strong></p><p>Each node in a binary tree can have a maximum of two children. However, in a strictly binary tree, every node <strong>must either have two children exactly or none at all.</strong> Hence, Strictly Binary Trees are binary trees in which each node has either two or no children. Full Binary Tree, Proper Binary Tree, and 2-Tree are further names for strictly binary trees.</p><p><strong>Example-</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/886/1*PS6AT4PDYapfCqKknBTUAw.png" /></figure><p>In the above example, each internal node has exactly two children, whereas each leaf node has zero, hence the tree retains the structure of a strictly binary tree.</p><p><strong>2. Complete Binary Tree</strong></p><p>It is a form of binary tree data structure in which all internal nodes-apart from those at the top level-are entirely filled. The nodes in the last level must be filled from as far left as possible.<br>Example-</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*Y2Z9FHQYZOAVLtxCOiWvTQ.png" /></figure><p>The above example corresponds to a complete binary tree in which all levels are entirely filled, with the possible exception of the last level, which is filled from left to right.</p><p><strong>3.</strong> <strong>Perfect Binary Tree</strong></p><p>A tree is considered to be a perfect binary tree if each node has exactly two children and all of its leaf nodes are at the same level.</p><p>Given below is the illustration of a perfect binary tree.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*gMyJVoJ4FH9u-1ZEXkJVTg.png" /></figure><p><strong>4.</strong> <strong>Degenerate Binary Tree</strong></p><p>A degenerate binary tree is one in which all internal nodes have exactly one child.</p><p>Examples-</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/795/1*UgcR2L7I5wlYQyVrZ4hhQA.png" /></figure><p>Because each node has just one child, the above tree is a degenerate binary tree. It is also known as a right-skewed tree since each node has just one right child.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/828/1*jlqEKd2mCzk7gRWwzJdArw.png" /></figure><p>Because each node has just one child, the above tree is also a degenerate binary tree. It is also known as a left-skewed tree since all nodes have only left children.</p><p><strong>5.</strong> <strong>Balanced Binary Tree</strong></p><p>For each node, the height of the left and right subtrees differs by either 0 or 1, making it a balanced binary tree.</p><p>Example-</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/782/1*zKU9HuP-rSnhdZVatV6ogA.png" /></figure><p><strong>Binary Tree Traversals</strong></p><p>The process of displaying or traversing a binary tree’s nodes in order is known as binary tree traversal.</p><p>There are three types of binary tree traversals-</p><p>1. In-order Traversal</p><p>2. Pre-order Traversal</p><p>3. Post-order Traversal</p><p>Take into consideration the following binary tree.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/827/1*unY_t6gYFTvRfuEHm9GEHw.png" /></figure><p><strong>IN-ORDER TRAVERSAL (Left child-root-right child)</strong></p><p>The root node is visited between the left child and the right child in an in-order traversal. The left child node is visited first in this traversal, followed by the root node, and finally the right child node. All of the subtrees in the tree’s root nodes can be traversed using this in-order method. Recursively, this is done for each node in the tree.</p><p>Considering the above example, the In-order traversal for this tree will be</p><p>8–4–9–2–5–1–6–10–3–7</p><p><strong>PRE-ORDER TRAVERSAL (Root-left Child-right Child)</strong></p><p>Pre-order traversal visits the root node before the left child and right child nodes in a tree structure. The root node, its left child, and finally its right child are all visited in this traversal order. All of the subtrees in the tree’s root nodes can be traversed using this pre-order traversal.</p><p>Considering the above example, the Pre-order traversal for this tree will be</p><p>1–2–4–8–9–5–3–6–10–7</p><p><strong>POST-ORDER TRAVERSAL (left Child-right Child-Root)</strong></p><p>The root node is visited in post-order traversal after the left child and the right child. In this traversal, the left child node, the right child, and finally the root node are all visited in that order. Until the rightmost node is reached, this is done again.</p><p>Considering the above example, the post-order traversal for this tree will be</p><p>8–9–4–5–2–10–6–7–3–1</p><p><strong>Binary Tree Representation</strong></p><p>Two techniques are used to represent a binary tree data structure- namely array representation and using linked list.</p><p>One-dimensional arrays (1-D Arrays) are used to represent binary trees in array representations.</p><p>A binary tree is depicted using a double-linked list. Every node in a double-linked list has three fields. The left child address is kept in the first field, the data is kept in the second, and the right child address is kept in the third.</p><p>A node in this linked list form has the following structure.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/617/1*c2Ck-0q8-Zh7rgXkxlXbiA.png" /></figure><p><strong>Heap Data structure</strong></p><p>A specialized binary tree-based data structure is called a heap. A binary tree having unique properties is called a heap. Nodes are placed in a heap data structure according to their values. Binary Heap is another name for a heap data structure.</p><p>There are two types of heap data structures-</p><p>1. Max heap</p><p>2. Min heap</p><p>Also, there are mainly two properties of heap data structure which are-</p><ol><li>Nodes must be organized in a hierarchy depending on their values using either the Max heap or the Min heap.</li></ol><p>2. A heap must have all levels filled up to the last level, and nodes must strictly fill up from left to right.</p><p><strong>MAX HEAP</strong></p><p>Max heap is a specific type of full binary tree where each parent node has a value larger than or equal to that of its children.<br>Example-</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*Z2ScV6ZFL1P6FcoZCWptkQ.png" /></figure><p><strong>Main operations on Max heap</strong></p><p><strong>1.</strong> <strong>Finding the maximum</strong></p><p><strong>2.</strong> <strong>Insertion</strong></p><p><strong>3.</strong> <strong>Deletion</strong></p><p><strong>MAXIMUM VALUE</strong></p><p>It is relatively easy to identify the node with the highest value in a max heap. The root node in a max heap has the highest value compared to all other nodes. Thus, the value of the root node may be clearly shown as the highest value in the max heap.</p><p><strong>INSERTION</strong></p><p>Step 1: Add the new node as the last leaf in a left-to-right direction.</p><p>Step 2: Then, the value of a new node is compared to its parent node.</p><p>Step 3: If the value of the new node exceeds that of its parent (value of new node&gt;parent node), then swap both of them.</p><p>Step 4: Until the new node value is smaller than its parent node or the new node reaches the root, repeat steps 2 and 3.</p><p><strong>DELETION</strong></p><p>Because it doesn’t change the properties of the max heap, eliminating the last node in a max heap is relatively easy.</p><p>Step 1: Swap the root node from the last node in the maximum heap.</p><p>Step 2: Then, the last node is deleted.</p><p>Step 3: Compare the left child to the root value now.</p><p>Step 4: If the root value is less than the left child, compare the left child to the right sibling. Else move on to Step 6.</p><p>Step 5: Swap the root with the left child if the value of the left child is greater than that of the right child; else, swap the root with the right child.</p><p>Step 6: Compare the root value to its right child value if the root value is greater than its left child.</p><p>Step 7: Swap the root with the right child if the root value is less than the right child; otherwise, end the procedure.</p><p>Step 8: Continue doing this until the root node fixes in place accurately.</p><p><strong>MIN HEAP</strong></p><p>The minimal element is present at the root of a Min-Heap.</p><p>Example-</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*OFvOmv7PTNyrAk8f9JJG_g.png" /></figure><p><strong>Main operations on Min heap</strong></p><p><strong>1.</strong> <strong>Peek operation</strong></p><p><strong>2.</strong> <strong>Insertion</strong></p><p><strong>3.</strong> <strong>Deletion</strong></p><p><strong>PEEK OPERATION</strong></p><p>The value of the root node is returned in order to access the smallest element, or the heap’s root.</p><p><strong>INSERTION</strong></p><p><strong>Step 1:</strong> Add the new element to the heap, putting it in the next available place inside the tree’s last level.</p><p><strong>Step 2:</strong> The new element should be compared to its parent. Swap them if the parent element is larger than the new element.</p><p><strong>Step 3:</strong> Repetition of step 2 is required until either the new element reaches the root of the tree or the parent is smaller than or equal to the new value.</p><p><strong>Step 4:</strong> Now that the new element is in the suitable place in the min heap, the heap property is satisfied.</p><p><strong>DELETION</strong></p><p><strong>Step 1:</strong> Determine the smallest element in the min heap, which is located at the root of the heap.</p><p><strong>Step 2:</strong> Put the last element at the top and swap the root with the last element in the heap to remove the smallest element.</p><p><strong>Step 3:</strong> The new root is compared with its children.</p><p><strong>Step 4:</strong> If the parent is larger than its smallest child, swap them to maintain the heap property.</p><p><strong>Step 5:</strong> Until the parent is smaller than both of its children or until it reaches a leaf node, continue to swap the new root with its smallest child.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e3be23df2055" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>