1622011800

# Algorithms Visualized

Bubble sorting is based on the idea of repeatedly comparing pairs of adjacent values and then swapping their positions when the values are out of order. It is an intuitive sorting method because it’s logic is based on the comparison of values, one at a time. The downside is that this method is inefficient and time consuming when compared to other sorting methods.

Here is an implementation of Bubble Sort in JavaScript.

The function involves a nested loop, iterating over the array for each element in the array again. The outer nested loop is how the passes over the array are made and the inner nested loop is the iteration over each item within each pass.

Here is the console.log() outputs from the bubble sort of the [7, 3, 4, 2, 1] array. We can see that it correctly sorts the array from smallest value (1) to largest value (7) in the final output below.

The final sorted array is: [1, 2, 3, 4, 7]

_Let’s break down the _BubbleSort function to get a better idea of how it works. Because the input array length is 5, the function makes 5 passes, zero indexed from 0 to 4 (the outer loop).

### First Pass

The sortMe array input array starts off as:

We can see that the value 7 is the the largest number in the array and is all the way on the left at the first position. The idea is to move the bigger numbers to the right. The inner loop iterates again through the array on each pass. This iteration moves the largest number on the left to the right. So, 7 will be “bubbling up” to the right in the process of the first pass. Here we can see it visually.

7 “bubbles” all the way to the right

With each iteration in the inner loop, adjacent values are compared from left to right, and the larger of the two compared values gets swapped if they are out of order, moving the larger value to the right, ready to be compared again with the next value.

Because 7 is the larger value at every comparison in the first pass, it swaps positions at every iteration, finally landing in the last position in the array. The array is partially sorted after the first pass.

#bubble-sort #javascript

1591177440

## Visual Analytics and Advanced Data Visualization

Visual Analytics is the scientific visualization to emerge an idea to present data in such a way so that it could be easily determined by anyone.

It gives an idea to the human mind to directly interact with interactive visuals which could help in making decisions easy and fast.

Visual Analytics basically breaks the complex data in a simple way.

The human brain is fast and is built to process things faster. So Data visualization provides its way to make things easy for students, researchers, mathematicians, scientists e

#blogs #data visualization #business analytics #data visualization techniques #visual analytics #visualizing ml models

1593347004

## A greedy algorithm is a simple

The Greedy Method is an approach for solving certain types of optimization problems. The greedy algorithm chooses the optimum result at each stage. While this works the majority of the times, there are numerous examples where the greedy approach is not the correct approach. For example, let’s say that you’re taking the greedy algorithm approach to earning money at a certain point in your life. You graduate high school and have two options:

#computer-science #algorithms #developer #programming #greedy-algorithms #algorithms

1591184760

## Visual Analytics Services for Data-Driven Decision Making

Visual analytics is the process of collecting, examining complex and large data sets (structured or unstructured) to get useful information to draw conclusions about the datasets and visualize the data or information in the form of interactive visual interfaces and graphical manner.

Data analytics is usually accomplished by extracting or collecting data from different data sources in the form of numbers, statistics and overall activity of any organization, with different deep learning and analytics tools, which is then processed using data visualization software and presented in the form of graphical charts, figures, and bars.

In today technology world, data are reproduced in incredible rate and amount. Visual Analytics helps the world to make the vast and complex amount of data useful and readable. Visual Analytics is the process to collect and store the data at a faster rate than analyze the data and make it helpful.

As human brain process visual content better than it processes plain text. So using advanced visual interfaces, humans may directly interact with the data analysis capabilities of today’s computers and allow them to make well-informed decisions in complex situations.

It allows you to create beautiful, interactive dashboards or reports that are immediately available on the web or a mobile device. The tool has a Data Explorer that makes it easy for the novice analyst to create forecasts, decision trees, or other fancy statistical methods.

#blogs #data visualization #data visualization tools #visual analytics #visualizing ml models

1596427800

## KMP — Pattern Matching Algorithm

Finding a certain piece of text inside a document represents an important feature nowadays. This is widely used in many practical things that we regularly do in our everyday lives, such as searching for something on Google or even plagiarism. In small texts, the algorithm used for pattern matching doesn’t require a certain complexity to behave well. However, big processes like searching the word ‘cake’ in a 300 pages book can take a lot of time if a naive algorithm is used.

# The naive algorithm

Before, talking about KMP, we should analyze the inefficient approach for finding a sequence of characters into a text. This algorithm slides over the text one by one to check for a match. The complexity provided by this solution is O (m * (n — m + 1)), where m is the length of the pattern and n the length of the text.

Find all the occurrences of string pat in string txt (naive algorithm).

``````#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

string pat = "ABA"; // the pattern
string txt = "CABBCABABAB"; // the text in which we are searching

bool checkForPattern(int index, int patLength) {
int i;
// checks if characters from pat are different from those in txt
for(i = 0; i < patLength; i++) {
if(txt[index + i] != pat[i]) {
return false;
}
}
return true;
}

void findPattern() {
int patternLength = pat.size();
int textLength = txt.size();

for(int i = 0; i <= textLength - patternLength; i++) {
// check for every index if there is a match
if(checkForPattern(i,patternLength)) {
cout << "Pattern at index " << i << "\n";
}
}

}

int main()
{
findPattern();
return 0;
}
view raw
main6.cpp hosted with ❤ by GitHub
``````

# KMP approach

This algorithm is based on a degenerating property that uses the fact that our pattern has some sub-patterns appearing more than once. This approach is significantly improving our complexity to linear time. The idea is when we find a mismatch, we already know some of the characters in the next searching window. This way we save time by skip matching the characters that we already know will surely match. To know when to skip, we need to pre-process an auxiliary array prePos in our pattern. prePos will hold integer values that will tell us the count of characters to be jumped. This supporting array can be described as the longest proper prefix that is also a suffix.

#programming #data-science #coding #kmp-algorithm #algorithms #algorithms

1624867080