LogoRajagopalan
  • Home
  • Posts
  • Interactive
  • Notes
  • AppBox
  • Github Contributions
Logo Inverted Logo
  • Posts
  • General
  • Math Tricks
  • Template Library
  • Time Complexity Analysis
  • Tutorials
  • GSoc Blogs
    • Coding week no 2 and 3
    • Coding week No.1
    • Introduction GSoc
    • Mid Community Bonding--Progress
  • Useful Datastructures
    • Trees
  • Useful Techniques
    • Bellman Ford
    • Binary Search
    • DFS - Ordering
    • LCA
    • Patience Sort
    • SCC
Hero Image
Trees

Some Facts about trees Simple path is a path that doesn’t contain any node twice. A tree has n-1 edges! Segment Trees Use segment trees for questions on updating values and querying. Can be used with complex operations like pairs,sets etc. Find very effecient and faster updating (used to insert too), by Finding path to root from one node. void update(int pos,int val){ pos += k; tree[pos] = val; int odd = 1; //this switches between alternate levels of the segment tree goes upwards while(pos>>=1 >0){ /* use this in case for level switching if(odd) tree[pos] = tree[2*pos] | tree[2*pos+1]; else tree[pos] = tree[2*pos] ^ tree[2*pos+1]; odd = 1-odd; */ tree[pos]=tree[2*pos]+tree[2*pos+1]; } } for(int i=0;i<n;i++){ int val; cin>>val; update(i,val); }

June 8, 2020 Read
Navigation
  • About
  • Skills
  • Experiences
  • Education
  • Projects
  • Roles and Responsibilities
  • Recent Posts
  • Accomplishments
  • Memorabilia
Contact me:
  • Email: g.raju2000@gmail.com
  • Phone: +91-9941154469

Stay up to date with email notification

We'll never share your email with anyone else.

Built with 🧡 by Rajagopalan