Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
6520e8d
Update README.md
careermonk Aug 7, 2015
81891fa
Copyright year update
careermonk Aug 7, 2015
660c9ba
revised the errors in the code
haoma7 Aug 9, 2015
3855420
Merge pull request #3 from mhrex/patch-1
careermonk Aug 10, 2015
d64e2e4
Removed DFS test code from BFS
careermonk Nov 14, 2015
61a5a36
Remove DFS test code
careermonk Nov 15, 2015
37d7a62
Update Table of Contents
careermonk Nov 20, 2015
ae3c3ee
Update Sample
careermonk Nov 20, 2015
03a3a92
Interpolation Search
careermonk Dec 11, 2015
b0da040
New Problems
careermonk Feb 22, 2016
a2c7f68
code
careermonk Jun 4, 2016
f2e2208
Matrix Rotation
careermonk Jul 22, 2016
9fc0fe8
Update LinkedList.py
Jul 26, 2016
c7fe1c6
Number of set bits in all numbers from 1 to n
careermonk Aug 10, 2016
b7c67ee
Code Updates
careermonk Aug 14, 2016
e3c4393
Code Updates
careermonk Aug 14, 2016
47953a0
Code updates
careermonk Aug 14, 2016
90c1cab
Merge pull request #4 from Guangzhan/patch-1
careermonk Jan 20, 2017
a57e445
Bug Fix
careermonk Jan 20, 2017
39a5089
Bug Fix
careermonk Mar 25, 2017
8fa5f73
Update
careermonk Mar 25, 2017
99f5407
Update
careermonk Mar 25, 2017
3e58e73
Update
careermonk Mar 25, 2017
8cfc777
Create finding_single_peak_with_linear_search.py
careermonk Jun 15, 2017
c0fbdf5
Create finding_highest_peak_with_linear_search.py
careermonk Jun 15, 2017
4a21231
Create finding_all_peaks_with_linear_search.py
careermonk Jun 15, 2017
1d95d97
Create finding_peak_with_binary_search.py
careermonk Jun 15, 2017
c9b4579
Create find_peak-2d.py
careermonk Jun 17, 2017
a84190e
New Problems
narkarum Jun 18, 2017
d8e564d
Update FindApplesCount.py
careermonk Jun 20, 2017
9026bcb
Create Count_Apples_with_3ways_of_reaching.py
careermonk Jun 20, 2017
d1b5627
Create longest_common_subsequence_brute_force.py
careermonk Jun 20, 2017
72b69bf
Rename longest_common_subsequence_brute_force.py to longest_common_su…
careermonk Jun 20, 2017
dfe3b80
Update longest_common_subsequence_recursive.py
careermonk Jun 20, 2017
a791b4d
Update longest_common_subsequence_recursive.py
careermonk Jun 20, 2017
fc521aa
Create tribonacci_series.py
careermonk Jun 20, 2017
d20581e
Create largestHistrogram_n^3.py
careermonk Jun 20, 2017
2c65531
Create largestHistrogram_n^2.py
careermonk Jun 20, 2017
49aba6b
Update ExponentialWithDivideAndConquer.py
careermonk Jul 3, 2017
93c115b
Update BitSequences.py
careermonk Aug 7, 2017
0c67f51
Update TwoElementsWithSumKEfficientWithSorting.py
careermonk Aug 16, 2017
3296e8a
Update CheckDuplicatesNegationTechnique.py
careermonk Oct 22, 2018
f946adc
Update LinkedList.py
careermonk Oct 22, 2018
4248975
Update KthSmallestBST.py
careermonk Oct 23, 2018
c3ba8b8
Create checkingDuplicates.py
careermonk Oct 24, 2018
5d82c7e
Create findDeletedElement.py
careermonk Oct 24, 2018
779541b
Create twoElementsWithSumK.py
careermonk Oct 24, 2018
f7dbe26
Rename MajorityElement.py to MajorityElement2.py
careermonk Oct 24, 2018
84f528d
Create planting.py
careermonk Oct 24, 2018
a5ba6d8
Create pivot.py
careermonk Oct 24, 2018
f7da1e7
Create KthNode.py
careermonk Oct 24, 2018
d7946b4
Create stack.py
careermonk Oct 24, 2018
9d3cb16
Create queue.py
careermonk Oct 24, 2018
c9b7d61
Create minimuminstack.py
careermonk Oct 24, 2018
222de28
Create queuewithstacks.py
careermonk Oct 24, 2018
999c564
Create queuewithstacks.py
careermonk Oct 24, 2018
fcd7dae
Update README.md
careermonk Oct 24, 2018
5e20093
Update InterpolationSearch.py
careermonk Jan 22, 2019
f19005a
Create singleUniqueNumber.py
narkarum Feb 6, 2019
f7bb7d5
Merge pull request #7 from narkarum/patch-1
careermonk Feb 6, 2019
06865ef
Rename QuickSort.py to QuickSort2.py
careermonk Feb 7, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Number of set bits in all numbers from 1 to n
Number of set bits in all numbers from 1 to n
  • Loading branch information
careermonk committed Aug 10, 2016
commit c7fe1c6f099a6769b0b943c35df175c8e34b1e8c
29 changes: 29 additions & 0 deletions src/chapter21miscconcepts/CountNumberofSetbitsin1toN.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright (c) Dec 22, 2014 CareerMonk Publications and others.
# E-Mail : [email protected]
# Creation Date : 2014-01-10 06:15:46
# Last modification : 2008-10-31
# by : Narasimha Karumanchi
# Book Title : Data Structures And Algorithmic Thinking With Python
# Warranty : This software is provided "as is" without any
# warranty; without even the implied warranty of
# merchantability or fitness for a particular purpose.



def countingNumberofOnesin1toN(n):
count = 0
for i in range(1, n+1):
j = i;
while(j):
count += 1
j &= j - 1
print count

n = 2
countingNumberofOnesin1toN(n)
n = 5
countingNumberofOnesin1toN(n)
n = 7
countingNumberofOnesin1toN(n)
n = 8
countingNumberofOnesin1toN(n)