RunestoneInteractive / RunestoneInteractive/pythonds

pop(i) is O(k) not O(n)

Open
#53 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
273
Forks
160
PR merge metrics
No merged PRs in 30d

Description

Error reported in course FIT5211 on page Lists by user lwoo0004 lindy.woodburn@gmail.com
Incorrect info on page ... pop(i) is O(k) not O(n).
e.g. popping from an indexed location from the end of a list

See python docs:
https://wiki.python.org/moin/TimeComplexity
Pop intermediate O(k)

And revised code:

popzero = timeit.Timer("x.pop(0)", "from main import x")
popend = timeit.Timer("x.pop()", "from main import x")
popend_minus = timeit.Timer("x.pop(-2)", "from main import x") . # ADDED

print("pop(0) pop() pop(-2)")
for i in range(1000000,100000001,1000000):
x = list(range(i))
pt = popend.timeit(number=1000)
x = list(range(i))
pz = popzero.timeit(number=1000)
x = list(range(i))
pe = popend_minus.timeit(number=1000)
print("%15.5f, %15.5f, %15.5f" %(pz,pt,pe))
pop(0) pop() pop(-2)
0.40309, 0.00010, 0.00015
1.20204, 0.00009, 0.00017
1.93542, 0.00009, 0.00014
2.73203, 0.00009, 0.00014
3.45721, 0.00010, 0.00015
4.21476, 0.00011, 0.00015
5.14111, 0.00010, 0.00017

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Lists page in the FIT5211 course material and compare its pop(i) complexity statement with the Python TimeComplexity documentation linked in the issue. Update the complexity explanation and the example to cover indexed pops such as pop(-2), then verify that the displayed timing output and wording are consistent.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.