A simple approach to segment trees

A simple approach to Segment Trees!

Everything Under The Sun

A segment tree is a tree data structure that allows aggregation queries and updates over array intervals in logarithmic time. As I see it, there are three major use cases for segment trees:

  1. Static or persistent segment trees: This is probably the most common use case. We preprocess an array of N elements to construct a segment tree in O(N). Now, we can query aggregates over any arbitrary range/segment of the array in O(log N).
  2. Segment tree with point updates: This allows us to update array values, one at a time in O(log N), while still maintaining the segment tree structure. Queries over any arbitrary range still occurs in O(log N).
  3. Segment tree with range updates: This allows us to update a range of array elements at once in O(N) in the worst case, however problem specific optimizations and lazy propagation typically give huge improvements. Queries over any arbitrary range still occurs in O(log N).

In this post, I’ll…

View original post 1,234 more words

Important Topics for Competitive Programming.

vishalpanwar

You may have wondered about the vast and endless nature of topics important(or I should say sufficient) for competitive programming point of view. Well to sum it all I have prepared a list(huge one!!!). It contains all the famous problems,algorithms and data structure…………………………

(a)Number Theory

  1. Prime Number Generation  (Sieve, Segmented Sieve)
  2. Euler Totient Theorem
  3. Fermat’s Theorem
  4. HCF & LCM (Euclid)
  5. Linear Diophantine Equations (Extended Euclid)
  6. Modulus Arithmetic (addition,multiplication,subtraction,modular Inverse)
  7. Cycle Finding (Floyd Algo and Brent Algo)
  8. Integer Factorization (Trial Division , Pollard Rho method)
  9. Lucas Theorem  (Simple & Advance)
  10. Chinese Remainder Theorem
  11. Wilson Theorem
  12. Miller – Rabin Primality Testing
  13. Perfect Numbers
  14. Goldbach Conjecture

(b)Probability

  1. Basic Probability and Conditional Probability
  2. Random Variables
  3. Probability Generating Functions
  4. Expectation
  5. Probability Distribution [Binomial, Poisson, Normal,Bernoulli]

(c)Counting

  1. Pigeonhole principle
  2. Inclusion Exclusion
  3. Special Numbers  [Stirling,Fibonacci,Catalan, Eulerian, Harmonic, Bernoulli]
  4. Polya Counting
  5. Burnside lemma

(d)Permutation Cycles

(e)Linear Algebra

  1. Addition And Subtraction Of Matrices
  2. Multiplication ( Strassen’s algorithm ), Logarithmic…

View original post 433 more words

Suffix Arrays – A simple Tutorial

An Awesome Post on Suffix Arrays !

Outlooking life

Suffix Arrays

It is the data structure to look out for when you are going for string Searching and want to reduce the time complexity greatly.  So, Let us examine and start from basics.

What are Suffix Arrays ?

As simple as it can get , suffix arrays represent the rank of all possible suffixes of a given string .For example ,

String  S = “ABDCASD”

Then the suffixes for the string S (with the numbers in front represent are ,

7 $ *

6 D

5 SD

4 ASD
3 CASD

2 DCASD

1 BDCASD

0 ABDCASD

*$, A null character can be called a suffix of every string as it does no addition to the string itself . We will later on see why we chose to add NULL character to our algorithm . For NULL character that we used, we assume have highest lexicographic priority .

Now,

View original post 746 more words

15,000+ fake views on ChallengePost Project

Hey there!

I hope you enjoyed my previous posts in Technical Hacks category.

Starting with the project of the week – GitHub Profile Scraper. So, as I was done with my latest project GitHub Profile Scraper a few days ago, I decided to post it on ChallengePost. GitHub profile scraper basically, helps you to get details of someone’s GitHub profile and show the information in an elegant way!

As soon as I posted the project on ChallengePost, it really got kind of sudden attention from ChallengePost community and even the co-founder of ChallengePost liked my project and started following me. I was delighted by the immediate attention that I was getting for this (self-)project.

As said by the great men – “The more you get, the more you desire to have!”. Yes, I was not different in this sense. I started looking for more and more visitors to my project and more followers on ChallengePost.

Then an evil idea came in my mind! I thought of automating the project page views as I noticed that they count different page views from same IP address as different page views. This reminded me of how easily this is achievable using Python. So, I opened my weapons i.e. Python IDLE! 😀

I wrote a simple python script within next 10 minutes and ran various versions(keeping time delays different) of it. The result was an increment of almost two thousand page views. My project was soon trending on top on ChallegePost. Soon after that, the co-founder Nealrs came to know about this(probably) and stopped liking the project. But I kept on running the script with increased frequency of the page visits. At a time I was sending almost 20 page requests every seconds. The only thing I was waiting for was a server crash, which didn’t eventually happen and page views on the project were soon 17,000+. Yes, an increase of almost 15,000 page views.

The best part was yet to come! Soon, the other co-founders of ChallengePost came to know about this and instead of taking any action against me or my project(I was actually expecting them to remove my project after this), one of the co-founders, Brandon Kessler (@bkessler) tweeted me something like this –

This absolutely made my day! Then, I replied back with a polite, humble tweet to assure that I will not continue that.

FYI, the project was trending on ChallengePost for almost 3 days, which is really a big thing. Today, it has more than 20,000 page views. 😉

You can view the project on ChallengePost here: GitHub Profile Scraper | ChallengePost

For feedback/suggestions/feature-requests, tweet me @sahildua2305 #FakeViews

DISCLAIMER: Since, I am making this trick public, ChallengePost staff may have problem with it. So, I am removing link to the script. It’s simple enough to write it yourself. 😉