GRAPH DATA STRUCTURE
Initializing a Graph When a new graph object is created using the Graph() constructor, an empty dictionary is initialized in the init method: def init(self): self.adj_list = {} This dictionary will hold the adjacency list for the graph. The keys in the dictionary will be the vertices of the graph, and the values will be lists of the vertices that are adjacent to the key vertex. Adding Edges to a Graph The add_edge method adds a new edge to the graph.
Read moreSORTING INTERVIEW QUESTIONS
Interview Questions On Sorting Sorting is an essential task in computer science and is used in various applications. In this article, we will discuss interview questions related to sorting and the best sorting algorithm for specific scenarios. 1 - Sort 10 schools around your house by distance Insertion sort - really fast for small data sets. It’s easy to code and understand, and has a space complexity of O(1). It’s also stable, which means that if two items have the same value, they will remain in the same order in the sorted list.
Read moreMINIMUM WAITING TIME
Minimum Waiting Time You are given a non-empty array of positive intergers representing the amounts of time that specific queries take to execute. Only one query can execute at a time. A queries waiting time is defined as the amount of time that it must wait before its execution starts. If a query is executed second then its waiting time is the duration of the first query; if a query is executed third then its waiting time is the sum of the durations of the first two queries.
Read moreBINARY SEARCH
Binary Search Algorithm Tutorial Introduction Welcome to this tutorial on implementing a Binary Search algorithm in Python. In this tutorial, we’ll learn how to use the Binary Search algorithm to search for an element in a sorted list or array. Algorithm The Binary Search algorithm works by repeatedly dividing the search interval in half until the target element is found or the search interval is empty. Here’s the basic structure of the algorithm in Python:
Read moreDEPTH FIRST SEARCH
I recently completed a code challenge going over Depth First Search (DFS) algorithm. I learned a lot from this challenge and the research I done trying to figure out how to solve the problem. Most of the research I done was after trying to solve the algorithm because of the desire to solve the challenge on my own, which I was able to do to my suprise. Here are some things I learned.
Read moreHOISTING IN JAVASCRIPT
Working with JavaScript can be very frustrating sometimes, just ask anyone familiar with the language. Knowing how it works under the hood can shed light on a weird bug or issue you are having. So let’s talk about hoisting. What is Hoisting? Hoisting is a term used to describe the behavior of JavaScript where variable and function declarations are moved to the top of their respective scopes. This means that even if you declare a variable or function later in your code, it will be treated as if it was declared at the top of the scope.
Read moreLOGIN REQUIRED DECORATOR
Today I have been working on my Django website on preventing unauthenticated users from accessing other authenticated users profile page. The first step in acheiving this is to go to your settings.py file and at the bottom add the login url. LOGIN_URL = 'users:login' Next step would be to go to views.py and import the login_required decorator from Django’s auth library which is very powerful and has a ton of useful resources.
Read moreDJANGO LOGIN REDIRECT
Django has built authentication that makes it easy to design and implement logging in and out for your websites. The regular document flow for logging in, after you have designed your login page, would automatically redirect you to /accounts/profile/ after hitting the submit button. Generally speaking we would want something more to our liking, something like a product page you would see after logging in to a e-commerce site. Django makes accomplishing this fairly straight forward.
Read moreNAMING ROUTES
Today I learned about naming routes when using Vue Router. This ability makes it easier to navigate to a route. For example if we have 3 routes like this: const routes = [ { path: "/", component: Home, }, { path: "/about", component: About, }, { path: "/manage", component: Manage, }, ]; Then your header would look like this: <li> <router-link class="px-2 text-white" to="/about">About</router-link> </li> <li> <router-link class="px-2 text-white" to="/manage">Manage</router-link> </li> <li> <router-link class="px-2 text-white" to="/home">Home</router-link> </li> Instead you can name your routes like this:
Read moreVUE SIGNING OUT
Continuing with my Vue music player app, I have been working on authentication. This app has firebase firestore on the backend and I am using pinia for maintaining state. I want to write about how I was able to implement logging out in the app. The first thing I did was use a browser built-in function to refresh the page after a successful login or registration of an account. This makes sure the modal closes and everything is loaded correctly.
Read more