#algos-and-data-structs

1 messages · Page 18 of 1

haughty mountain
#

fwiw, the more traditional chained hashtables are easier to analyze

#

in the probing hash table different probing chains interact with each others

fiery cosmos
#

i still could never figure out how to catch strings in the input. the way i im reading the data now perturbs that and i wasn't able to implement your proposed data reading strategy

fiery cosmos
#

hey my count function is messed up for when bucketsize is 3

#

right now it's this:

#

which was working for regular buckets of size 1

#

its like way wrong like im getting load factor of 8

#

its counting the correct number of elements

#

nvm, i just needed parenthesis 🤦‍♂️

haughty mountain
#

yeah, I was about to say

#

parens matter

fiery cosmos
#

i'm actually really surprised she doubled down on being wrong about the tablesize mod. its fine to be wrong, but the way you handle it matters

#

i wrote two completely separate programs

#

and neither are great, but at least i have a real load factor to work with

#

i have a vague feeling like the probe computation isn't what she wants, beyond just the modulo thing

#

oh yeah i see how quadratic probing is broken

#

oh wait this was chaining 🤔

#

somehow my chaining broke

#

for both programs. so weird

#

must have been some comparison logic i added

fiery cosmos
#

chain you chain together logical operators

#

sry logic

#

like
if var1 is not < var2

stiff plover
#

if not var1 < var2:?

fiery cosmos
#

probably not

dreamy valley
#

fwiw, not < is usually spelled >=

haughty mountain
halcyon plankBOT
#

@haughty mountain :white_check_mark: Your 3.11 eval job has completed with return code 0.

001 | True
002 | False
dreamy valley
#

💯% right, and maybe thinking about that would clarify in someone's mind why they want not < over >=

#

gotta love floating point

vital scaffold
#

Hmm, now i understand that doing in-place operations just alters the list while doing something like

def test(nums):
  list = x
  x = x + [1] # x now  references to a new list so there is no alteration in the original list

arr = [1,2,3]
print(test(arr))

`[1,2,3]

inland crane
#

Hey can anyone help me understand how one is supposed to implement a backtracking problem iteratively??

#

Is it true that any problem can be solved both recursively and iteratively? Or are there certain instances where that isn't the case...

shut breach
#

all recursive programs can be written iteratively and vice versa

fiery cosmos
#

hi all, i think my logic for my chaining insertion scheme could be incorrect

fiery cosmos
#

not all problems have recursive structure

fiery cosmos
cold bluff
#

is there some resources for a bit more intermediate algorithms n data structure? Especially for leetcode

#

and also some math courses? I'm kinda bad in math

fiery cosmos
#

for math you can do khan academy and schaums outlines (physical books) which are very good for getting back up to speed with things you may have forgotten. khan academy is invaluable. then you can move on to the pinned course in this channel

#

hi all,
if each insertion of a hashtable could be O(n) in worst case, and there are n elements, it theoretically could take n^2 time to insert them all, yeah?

lyric berry
#

so if i wanted to make a graph or tree data structure, with a bunch of objects as nodes and be able to access connected nodes via an attribute is that possible

fiery cosmos
#

of course. might be easier with an adjacency list though

lyric berry
#

for example using

for node in node5.children:
[do work on node objects]

#

node.children would have to contain a list of references. but python doesnt have references?

#

so how would you implement that

fiery cosmos
#

so typically a tree structure based on a node class just has pointers as attributes. eg, node.leftchild = node4

#

adjacency lists make everything easy, for graphs

#

trees and graphs can be quite different

lyric berry
#

yea thats how i would do it in c, using pointers

#

im specfically asking how to do it using object references not a adjecency chart

opal oriole
#

Everything in Python is a PyObject *.

#

= copies the pointer.

#

(Like in C)

#

So if you make a new_var = some_obj, they both reference the same object.

lyric berry
#

oh ive been out of python for a while i thought it did a copy

fiery cosmos
#

you'd recursively gather up all the children by calling a method on a node that would get all it's children first, then do something will all of the children you have gathered. it should be easier though if each node is the root of the subtree of all of its children

opal oriole
fiery cosmos
#

then you just say do something for the subtree with this node as the root

cold bluff
lyric berry
cold bluff
fiery cosmos
opal oriole
fiery cosmos
#

i've been there

#

i have 2 schaums outlines

#

one in rudimentary algebra and one in discrete

#

i took calc and stats in college and forgot all of it

#

i want to learn linear, as i said

cold bluff
fiery cosmos
#

and multiple linear regression

cold bluff
#

but my geometry was really bad

fiery cosmos
cold bluff
#

like w the triangles

fiery cosmos
#

eh, you don't really need that

cold bluff
#

mostly circles n triangles

#

for geometry

cold bluff
#

idk if it is in algebra or not

#

I also like to watch it in english

#

soo like because of that idk even what to watch in khanacademy

#

maybe thats why it was a bit bad experience for me

opal oriole
#

Eh, IDK if I can share that due to rules.

cold bluff
#

is pay to learn...

opal oriole
#

Yeah.

#

But it's that or $200 books.

#

Or Khan.

cold bluff
#

idk which ones tho

fiery cosmos
#

schaums outlines

#

ooh i should grab the linear algebra one

opal oriole
haughty mountain
opal oriole
#

Do any of these seem like they are something you need to learn about?

fiery cosmos
#

wow y'all are always on the ball, even on saturdays. bravo 👏 👏 👏

vocal gorge
#

versin? exsec?? excsc??? wow, they really just keep making up functions :p

opal oriole
#

A set of rules for solving such algebraic equations is known as an "algorithm" (algorism) (name also given by same person, محمد بن موسی خوارزمی (Muhammad ibn Musa al-Khwarizmi)).

#

And in many algebra classes you memorize many such algorisms.

dusk anchor
vocal gorge
#

huh, never saw that - why not call them arcsec/arccsc like everything does?

fiery cosmos
#

algebra and algorithm

#

v curious

dusk anchor
brisk saddle
#

hey, so i had an interesting thought when it comes to string searching.

#

this might be the same as doing a regular check if a word appears at index n in a string, but:

#

actually, nevermind.

dusk anchor
#

lol

haughty mountain
brisk saddle
#

👁‍🗨

haughty mountain
# opal oriole

interesting that they used exscs and exsec which makes it very not obvious that the terms are related

#

external secant and external cosecant

#

they go with tan and cotan

brisk saddle
haughty mountain
#

or was

#

for navigation

brisk saddle
#

theres also the haversine

haughty mountain
#

you would have tables of haversine (half versine)

#

right

#

The haversine formula determines the great-circle distance between two points on a sphere given their longitudes and latitudes. Important in navigation, it is a special case of a more general formula in spherical trigonometry, the law of haversines, that relates the sides and angles of spherical triangles.
The first table of haversines in Englis...

brisk saddle
#

im pretty sure all of them can be derived from the base 3 trig functions

#

and tan can be derived from sin and cos

#

and cos can be derived from sin

haughty mountain
#

you can get by with 1

#

yeah

brisk saddle
#

its sin all the way down

haughty mountain
#

✝️

#

begone daemon

brisk saddle
#

yeah that about sums it up

haughty mountain
#

I hope that joke landed

brisk saddle
#

lol

opal oriole
haughty mountain
#

feels weird to hide the actually nice systematic part of it

opal oriole
#

The base needs to be accepted as its own made up words (slightly latin based), since that was translated incorrectly.

haughty mountain
#

isn't sine the only base?

opal oriole
#

Cosine and tangent has their own words.

#

Tangent is the only decently translated.

haughty mountain
#

cosine is a derived term

#

from sine

#

co- as a (systematic) prefix

opal oriole
#

Yea after translation.

#

They needed a word for cosine, and were like, let's just add "co".

#

The older original words are related to construction.

haughty mountain
#

co is... err

#

complementary?

opal oriole
#

Yea more or less, but the Latin root version.

haughty mountain
#

yeah

#

tangent and secant are established names already

opal oriole
#

Tan and cotan make more sense in that regard.

#

Cause if the total line is length say, 1, then cotan 1 - tan

#

So the complement.

#

Like in probability.

#

Sin and cos are a bit more complicated, related through the right triangle.

#

So not exactly complement.

#

(Unless you go by the squares)

haughty mountain
#

it's complimentary in the sense of that one somewhat important trig identity, yes

#

iirc there is a nice symmetry of all the co- stuff

#

with the non co- stuff

#

the non co- version is based on the triangle on one side of the angle

#

the co is the same but for the other side of the angle

dreamy valley
#

cofunc(θ) = func(π/2 - θ)

haughty mountain
#

not that I actually know most of these terms off hand

#

if I need them I usually just represent them in the usual 3

dreamy valley
#

I assume that's why they made me memorize that angles that add to π/2 are called "complementary"

#

er

#

fixed lol

agile sundial
#

complimentary is pi/2 i thought

haughty mountain
#

lol, I was about to say

opal oriole
dreamy valley
#

knew there was something wrong about that

haughty mountain
#

before I saw the edit

opal oriole
#

External memory storage, don't need to remember everything, just the general idea and how it can be used.

haughty mountain
#

so yeah, they are related to the complementary angle

dreamy valley
#

guess I didn't memorize things as well as I thought

haughty mountain
#

(wrt pi/2)

opal oriole
#

Or just 1 - theta if you are not using radians.

haughty mountain
#

I recall in a bunch of US material more than the usual 3 functions

#

like cot scs and...what's the last one?

#

csc?

opal oriole
#

csc

dreamy valley
#

if you are using degrees it would be 90° - θ

opal oriole
#

Degrees are for people using base 60.

haughty mountain
opal oriole
#

We can become French revolutionaries and use gradians.

haughty mountain
#

4 somethings is a revolution?

#

I know there is a 400 degree thing

#

but I've not seen 4

opal oriole
#

There are a whole bunch others, including 2pi = 1

dreamy valley
haughty mountain
#

radians are nice though

#

because the whole arc length thing

opal oriole
#

In Euclidean geometry, an angle is the figure formed by two rays, called the sides of the angle, sharing a common endpoint, called the vertex of the angle.
Angles formed by two rays lie in the plane that contains the rays. Angles are also formed by the intersection of two planes. These are called dihedral angles. Two intersecting curves may also...

haughty mountain
#

yeah, I guess it's the more usual term

#

what's the relevant term from complex analysis...

dreamy valley
#

I use all three at work (degrees, radians, turns)

#

degrees mostly for axis labels though

haughty mountain
#

winding number

#

I guess that doesn't translate to a nice term, huh?

opal oriole
#

Not sure. Knowing math there is probably a term for it.

haughty mountain
#

well, winding is about the process of...winding something around the origin

#

I suspect turn could be the appropriate unit

opal oriole
#

Turn feels ok.

#

Or cycle, or revolution.

haughty mountain
#

revolution for sure pops up in practical applications

#

rpm and whatnot

#

someone should be terrible and shorten rad/s as rpm

#

but in the grand scheme radians is the "right" choice for mathematics

#

a bit like how e is the right choice for exponentials

opal oriole
#

It's kind of arbitrary, but results in better equations than something like degrees.

haughty mountain
#

(and these are somewhat related, radians and e)

opal oriole
#

Which is subjective somewhat (shorter equations typically preferred).

haughty mountain
#

it removes a bunch of leading factors popping out when doing math on it

opal oriole
#

KInd of, because one can just collapse them often.

dreamy valley
#

it can be arbitrary, but it can be practical too.
You minimize floating point error by doing math with all numbers that are more or less close to 1.0

opal oriole
#

Which is effectively the same as changing to radians or whatever.

#

Yeah in CS, which is on topic, it can show up better to no use radians, which many implementations do.

#

For by-hand, degrees can make sense if you use base 60, but we don't typically do that anymore.

haughty mountain
#

wrong message to reply to, but whatever

opal oriole
haughty mountain
opal oriole
#

I can give some ridiculous stuff to it in 2022.

haughty mountain
#

physicists do fun stuff as well, e.g. let c = 1

opal oriole
#

(And eventually when they use more ML, almost anything that is not complete nonsense)

haughty mountain
#

(and let a bunch of other things = 1)

#

what's the name, natural units?

opal oriole
#

Uh, nats?

haughty mountain
#

planck units

#

is one version at least

#

is has some fun consequences for units relevant to us mortals though

opal oriole
#

"The universe does not care about what you prefer"

haughty mountain
#

momentum is surprisingly human sized

opal oriole
#

Energy is also ok.

#

Only kind of big.

vocal gorge
#

so it's, like, a basketball's worth of momentum in one photon

agile sundial
haughty mountain
rough wharf
#

how can we use linkedlist in quicksort

#

is there any way

agile sundial
#

you generally wouldn't use quicksort for linked lists, since it requires random access

rough wharf
#

ohh okay

#

then for linked list which algo we should use ?

meager slate
#

my guess is you can use insertion sort

#

the reason insertion sort is O(n^2) is because inserting in the middle in a vector (list) is O(n)

#

but for linked lists it is O(1)

#

so maybe you can take advantage of that

agile sundial
#

mergesort

dreamy valley
#

inserting at a cursor in a linked list is O(1)

#

but in an insertion sort you have to find the cursor first

agile sundial
meager slate
#

oops

#

my bad

dreamy valley
#

there is no efficient (O(n log n)) in-place sort on linked lists, but mergesort would work as a not-in-place one

#

treesort maybe

meager slate
#

what about a heapsort?

dreamy valley
#

if you're doing heapsort you might as well just collect the list into an array and do quicksort 😛

meager slate
#

lol true

fiery cosmos
#

is remembering the code of the linked list or query important?

agile sundial
#

wdym query. generally you don't memorize code, just the ideas so that you can recreate it if necessary

fiery cosmos
fiery cosmos
#

oh also i need help implementing the logic for removing items from my stack of free array index locations for a hashtable

#

any takers

haughty mountain
#

why not do like I suggested and read all the non-header strings first and then convert?

fiery cosmos
#

pretty sure i got it. before i did not have the logic for removing an array index location from a free space stack after successful insertion for the chaining paradigm. eg, after successful insertion, i need to then go to my free space array and remove that location, so i don't select an occupied location and overwrite it

haughty mountain
#
f.readline()  # skip header
strings = f.read().split()
# ...convert strings to int
haughty mountain
#

don't you just pop from the stack when you actually need a new index?

fiery cosmos
#

its mostly to fulfill a requirement of the assignment, "use a stack to keep track of free space." stack here is just a list i am modifying as i go

fiery cosmos
haughty mountain
#

just use readline to skip the first line

#

then read the rest and split on whitespace

fiery cosmos
#

some inputs have headers that are like 4 lines, and others dont

haughty mountain
#

and the headers have nothing in common, like some marker?

#

maybe post an example

fiery cosmos
#

my inputs just begin with the data as integers. their input has some bullshit like:
`132.145 course name

required input

int1
int2
int3
...
`

#

i just need some conditionals within the try block, i think

#

to avoid headache i should just reformulate their required input lol

#

but they might test this w other files that are similar

haughty mountain
#

is "required input" at the start of any input?

fiery cosmos
#

technically yes, it'd be as above, where it is the last thing i'd read before the keys

#

wedged in there between the keys and the course number line

#

I could add that line to my inputs, to normalize things

#

then i could readline until i come across "Minimal required input:"

#

i think

#

what would that code look like

haughty mountain
#

so...does the data have that line or not?

fiery cosmos
#

their data does, my supplemental data does not, i could add it to make everything the same

#

i could add it to my inputs, yes

haughty mountain
#
# Skip header
while True:
  if f.readline().strip() == 'required input':
    break
fiery cosmos
#

i'll try this now, ty

haughty mountain
#

err, maybe with a strip call

#

since readline includes the '\n'

#

edited

fiery cosmos
#

uhh

#

?

#

i'm really bad at coding, remember

#

i'm pretty good w the logic but my programming is severely lacking

#

ok that's working so far

#

just have to catch strings while casting them to ints? but they are all strings rn

haughty mountain
#

no

#

you don't need any loop over lines

fiery cosmos
#

ok

haughty mountain
#

and why do you do the readline after the while loop?

fiery cosmos
#

i'd like you to assume that i am an extremely inexperienced programmer, and that any illogical series of things i post is due to lack of programmatic logic

#

i'm doing my best

#

ok so that is working to get all the keys

#

so during the process of casting them to int, i need to catch things that are alphabetic?

#

that's what i'm trying to do for error handling, anyhow

haughty mountain
#

you can try-except that conversion

fiery cosmos
#

ok ok on it

haughty mountain
fiery cosmos
#

i am already in a while loop, so i do not need another for string in strings? or i do

fiery cosmos
haughty mountain
#

like, the thing you want to do can be broken down into a few steps

# Skip the header lines
...
# Read the rest of the entries as strings
...
# Convert the strings to int with the error checking
...
#

can you fill in the code for the first two ...?

fiery cosmos
#

well i have both readline and read right now, and i don't know how they differ or can be used together, so i need to go read about that

haughty mountain
#

readline reads the next line

fiery cosmos
#

The read() will read the whole file at once and then print out the first characters that take up as many bytes as you specify in the parenthesis versus the readline() that will read and print out only the first characters that take up as many bytes as you specify in the parenthesis

haughty mountain
#

read without arguments will read the rest of the file

fiery cosmos
#

why would i want to break out of the while loop?

haughty mountain
#

this tells me you don't really get the logic of what you're writing

fiery cosmos
#

well we know that

haughty mountain
#

fill in the first ... part

#

we have a file object f

#

we want to skip past the header part

#

we already mentioned a way to detect the end of the header part before

haughty mountain
#

yes

fiery cosmos
#

why would you want to break out of the loop you're using to parse the file

haughty mountain
#

that's not the loop to parse the file

fiery cosmos
#

wouldn't you want a continue

#

oh

haughty mountain
#

can you explain conceptually what the loop does?

fiery cosmos
#

only that first bit. it's going to continue reading the file via f.readline until it comes across that condition

#

which we know will exist

haughty mountain
#

so it reads until the line we know is at the end of the header

fiery cosmos
#

correct

haughty mountain
#

and then breaks the loop

fiery cosmos
#

so we need to begin a new while loop?

haughty mountain
#

you'll need to read the rest of the file somehow

#

but there are easier ways to get the strings you're after

fiery cosmos
#

like read()

#

wait

#

indent is wrong

haughty mountain
#

that's more sensible yes

#

note that rather than having 1 very complicated and error prone loop, this is 3 distinct and easy steps

fiery cosmos
#

oohh could i print the string that was detected to output???

haughty mountain
#

breaking a complicated problem into simpler parts is important

fiery cosmos
#

like show the error i am catching

#

in a print

haughty mountain
#

aren't you basically doing that already?

fiery cosmos
#

oh i see how

#

duh

#

oh this thing does not have scope of the output

#

this is a separate function outside of main()

#

i'll have to return some things from this to main()

#

will this work?

#

its not coloring like it will

haughty mountain
#

no reason for the second as

fiery cosmos
#

i passed output to the getdata function

haughty mountain
#

no need for args.output as output

fiery cosmos
#

here it is now

haughty mountain
#

why do you have the second thing in the with?

fiery cosmos
#

oh its read by default huh

haughty mountain
#

it's already an opened file

#

if you want to have the program exit if there is an error, why not just let an exception propagate through the program?

#

currently you catch an error, print as if you would stop the program, and then don't stop the program

fiery cosmos
#

ok so i can remove my syntax after except ValueError and then add a try block to my main()

#

and catch it there

haughty mountain
#

I wouldn't catch a ValueError in main

#

that can hide actual errors

fiery cosmos
#

ok so what are you suggesting

haughty mountain
#

you can throw your own exception

#

and only catch that

fiery cosmos
#

ok

haughty mountain
#

then you know that's from you explicitly throwing such an exception

fiery cosmos
#

ah no i don't get it, they are all strings rn

haughty mountain
#

wdym?

fiery cosmos
#

wait maybe i do

#

like this: except "conversion to integer failed."?

haughty mountain
#

no

fiery cosmos
#

oof

haughty mountain
#

you can create your own exception class easily

class MyException(Exception):
    pass
fiery cosmos
#

outside of the getdata function?

haughty mountain
#

why would you define the class inside?

fiery cosmos
#

idk, that's why i'm asking 😂

#

why would i want an exception that just passes

#

exception is a weird word

#

exce

haughty mountain
#

the pass is just there since we don't define any methods or anything for the class

#

we can't just leave the body empty

#

because python

sweet viper
#

Anyone knows good study material/vids for ppl leaning DSA?

haughty mountain
#

MyException inherits from Exception, so it has all the members and functions Exception has

#

so you can then do

def f():
  try:
    something()
  except ValueError:
    raise MyException('something went wrong')

def main():
  try:
    f()
  except MyException as e:
    ...log e to file...
fiery cosmos
haughty mountain
#

any exception not of type MyException will not be caught by the try in main

fiery cosmos
#

i think you are overestimating my abilities here

haughty mountain
#

maybe I shouldn't bother trying to suggest good ways of doing things 🤷‍♂️

#

exceptions is such a core part of python, you should really learn them

#

they can simplify flow like this a bunch

fiery cosmos
#

what is the purpose of having your own exception class

haughty mountain
#

have a guess

fiery cosmos
#

for custom exceptions

#

like, non ValueError or non TypeError

#

stuff

#

custom errors*

haughty mountain
#

what's bad about wrapping my whole code in

try:
  ...
except ValueError:
  ...
fiery cosmos
#

bc ValueError could be many different things that may have gone wrong and its not explicit

haughty mountain
#

yes, you will end up catching things you didn't intend to catch

#

and with your own exception class?

fiery cosmos
#

you can make it very specific to a single error or type of error

haughty mountain
#

catching a generic error like ValueError is fine locally where you know what's going wrong

#

but having such a check globally will just end up hiding errors you didn't expect

#

better to have errors you don't explicitly handle terminate the program

#

that way coding errors will fail loudly rather than being silently ignored

haughty mountain
#

so that the program terminates with a failure, and with the exception printed to the terminal

#

so you can have your logging layer, but better to re-raise the error

fiery cosmos
#

alright let's try this bad boy

#

TypeError: catching classes that do not inherit from BaseException is not allowed

#

never seen this error before

#

ok this is what i have outside of main:

haughty mountain
fiery cosmos
#

oh i need a return

haughty mountain
#

also, name classes with capital letters

#

MyException

fiery cosmos
#

gt it

#

got

haughty mountain
#

why do you implement logic in your class?

#

just inherit from Exception

fiery cosmos
#

wdym

haughty mountain
#

what no

#

you define your own exception class

#

it doesn't need any additional logic than Exception has, it just needs to be its own type

#

then you can raise that exception just like you would any other

fiery cosmos
#

that's what i was trying to do in the code i posted. i think i am not getting the inheritance thing

#

oh the inheritance is conferred by the raise keyword?

haughty mountain
#
class MyException(Exception):
    pass
fiery cosmos
#

how does that class know its an error

#

or an exception

#

we just named it as such

haughty mountain
#

MyException inherits from Exception

fiery cosmos
#

oh oh oh i see

#

i thought Exception was a placeholder for the exception i caught

#

what if i want to pass along the string i found in the input?

#

with open(input) as f, output: AttributeError: __enter__

haughty mountain
haughty mountain
fiery cosmos
#

that would require the class logic no?

haughty mountain
#

no

#

Exception has that logic

#

(actually, maybe it's even BaseException, which Exception inherits from)

fiery cosmos
#

where does it take it as argument

haughty mountain
#

huh?

#

no

#

when you inherit from class you get access to all its functions and similar

#

Exception has an __init__ that takes a string

#

!e

class BaseClass:
  def f(self):
    print(42)

class DerivedClass(BaseClass):
  def g(self):
    print('hi')

x = DerivedClass()
x.f()
x.g()

x = BaseClass()
x.f()
x.g()  # does not work
halcyon plankBOT
#

@haughty mountain :x: Your 3.11 eval job has completed with return code 1.

001 | 42
002 | hi
003 | 42
004 | Traceback (most recent call last):
005 |   File "<string>", line 15, in <module>
006 | AttributeError: 'BaseClass' object has no attribute 'g'
haughty mountain
#

here you can see DerivedClass has access to both f and g

#

BaseClass only has f

fiery cosmos
#

yeah what you wrote above makes total sense

#

so in my context, ValueError has access to the string which threw the error?

#

im not just seeing how to pass it along

#

the string which caused the ValueError

haughty mountain
#

you have access to the variable with the string, no?

fiery cosmos
#

there is no variable associated with it yet, it's just this:

#

probably should have included this:

haughty mountain
#

string is the string that caused the error, no?

fiery cosmos
#

yes

haughty mountain
#

so what's the issue?

#

you probably want to add some formatting rather than just using the string as a message, but other than that you are using string as the message

fiery cosmos
#

right i got you

#

wow this has been a long process to implement, but i learned a lot

haughty mountain
#

I suspect you really want

except ValueError as e:
    raise Myexception(string) from e
#

otherwise you'll get some weird looking errors

fiery cosmos
#

this works fine.. but you're saying not to use as such?

#

this is in my main block

haughty mountain
#

!e I mean compare this error

def f():
  try:
    int('not valid')
  except ValueError:
    raise Exception('other exception')

f()
halcyon plankBOT
#

@haughty mountain :x: Your 3.11 eval job has completed with return code 1.

001 | Traceback (most recent call last):
002 |   File "<string>", line 3, in f
003 | ValueError: invalid literal for int() with base 10: 'not valid'
004 | 
005 | During handling of the above exception, another exception occurred:
006 | 
007 | Traceback (most recent call last):
008 |   File "<string>", line 7, in <module>
009 |   File "<string>", line 5, in f
010 | Exception: other exception
haughty mountain
#

!e to this

def f():
  try:
    int('not valid')
  except ValueError as e:
    raise Exception('other exception') from e

f()
halcyon plankBOT
#

@haughty mountain :x: Your 3.11 eval job has completed with return code 1.

001 | Traceback (most recent call last):
002 |   File "<string>", line 3, in f
003 | ValueError: invalid literal for int() with base 10: 'not valid'
004 | 
005 | The above exception was the direct cause of the following exception:
006 | 
007 | Traceback (most recent call last):
008 |   File "<string>", line 7, in <module>
009 |   File "<string>", line 5, in f
010 | Exception: other exception
haughty mountain
#

this is technically fine, but I would either call exit with a non-zero argument (which means an error)

#

or re-raise the exception

fiery cosmos
#

ahh i see

haughty mountain
#

i.e. you can do

    try:
        data = getdata(input, output)
    except Myexception as e:
        print(str(e) + ' was detected in the inputfile. Please check the inputfile and try again.', file = output)
        raise e
fiery cosmos
#

it prints to console as well

#

exiting with non-zero error works fine too

#

oh wait nvm

haughty mountain
#

exiting with non-zero at least signals something happens

fiery cosmos
#

the output file is wrong

haughty mountain
#

is it?

fiery cosmos
#

wait wait

#

its never generating the outputfile

#

fuuu

haughty mountain
#

re-raise the exception

#

then you can actually tell if that clause actually happens

#

(and this is why failing loudly is good)

fiery cosmos
#

i think this not being in my context manager is causing issue

#

that clause isn't in my context manager because the for datum in data loop is also not

#

is that wrong

haughty mountain
#

share the relevant code

#

without context that stuff just seems weird

#

seems like output is a string there, which would be weird

fiery cosmos
haughty mountain
#

well yeah

#

output is string there

#

it's before you open the file

#

(and the naming doesn't exactly help)

fiery cosmos
#

oh did i accidentally type it as string in argparse?

#

like should i remove that

haughty mountain
#

it's not an issue with argparse

fiery cosmos
#

the output should always be a named file keyed in at the command line

haughty mountain
#

like, just think about it

#

in the print in the except

#

what is output?

fiery cosmos
#

i thought it was the named text file, because just above i have
output = args.output

haughty mountain
#

it's the name of a text file, sure

#

that's not what the file argument to print takes

fiery cosmos
#

ok so this whole thing goes in its own context manager?

#

or i put it in the one i already have

#

the whole try block

haughty mountain
#

you could put things inside the context manager, sure

#

granted, I would probably break your main function apart a bit, it's starting to get quite long

fiery cosmos
#

bc the context manager comes after all of this

#

wait maybe not

#

maybe i could just put the try block? let me try 👀

#

nah that doesn't work

#

then data doesn't exist yet

#

weird it isn't exiting now

#

bruh. i am so bad at this

haughty mountain
#

having the context manager wrap things wouldn't look so terrible if you only split things into functions

fiery cosmos
#

would you mind deleting this and DMing me

haughty mountain
#

why?

fiery cosmos
#

so another student doesn't use it and make it look like we cheated or conspired or grabbed some random github code

#

if we turn in the same thing, one of us will be thought to be copying the other

haughty mountain
#

you have the link already, right?

fiery cosmos
#

yes

#

ty

#

and rather than use this verbatim, i will study the logic

#

i feel like i am getting pretty close with my impl

haughty mountain
#

it's just extracting parts into functions

#

so the main function doesn't get huge

fiery cosmos
#

that's fair enough

haughty mountain
#

did you put this after the context manager or something?

fiery cosmos
#

i put the try block in its own context manager

#

separate from the one that exists later to write to out

haughty mountain
#

well yeah

fiery cosmos
#

what did i do wrong

haughty mountain
#

output is closed by the time you get to the except clause

#

because that's what context managers do

fiery cosmos
#

getting rid of the close() gives the same error

haughty mountain
#

do stuff when the block is exited

#

the close is irrelevant

fiery cosmos
#

oh oh

haughty mountain
#

you open the file with a context manager, that closes the file when the block is exited

fiery cosmos
#

i see what's wrong ok

haughty mountain
#

this will fail for other reasons

#

yes, that

fiery cosmos
#

ok think i got it

haughty mountain
#

open opens as 'r' by default

fiery cosmos
#

yep

#

yeah i got it

#

and now it's writing to out. so now i have to test a non-error file

haughty mountain
#

but at this point, you might as well put everything in one big with

fiery cosmos
#

yep, it's working fine

haughty mountain
#

and then if that feels messy break things into functions

fiery cosmos
#

i could do that, eyah

#

yeah*

#

guess how many messages you've sent in here

#

that i return by searching for from: yourname

haughty mountain
#

a lot

#

O(10k)?

fiery cosmos
#

omega(10k)

haughty mountain
#

right order of magnitude

fiery cosmos
#

correct

#

ok im looking at your code now

haughty mountain
#

in less than a year

fiery cosmos
#

search goes back 1 year?

#

or you've been contributing for less than 1

haughty mountain
#

I've been in this server since december last year

fiery cosmos
#

ah i see

#

do you like trivia?

#

i like trivia regarding large numbers. like random facts

#

its kind of remarkable you're able to go through and clean up code in the way you do. i guess you have a lot of practice

#

american lottery is up to US $1.9b.. 👀

opal oriole
haughty mountain
#

but yes, I've coded a lot, so doing small refactoring is kinda second nature

fiery cosmos
#

but then your default mindset is that of hatred. maybe you just see things for what they could be. an eternal optimist

#

i guess its the same with anything, when people get good at it.

#

eg, some pro golfer seeing someone else's swing and being like "this is crap and here is why and here is how you fix it"

haughty mountain
#

eternal optimist feels like it misses the mark 😛

opal oriole
#

When working in a team an important thing to do is to realize that others will code in different ways and you kind of just have to let them, or go insane trying to correct them on everything.

haughty mountain
#

I have opinions on roughly what I think good code should look like

fiery cosmos
#

oh i know lol i am painting it in a better light 😂

fiery cosmos
#

@opal oriole are you in charge of software devs?

opal oriole
#

You can ofc have them run their code through a tool.

haughty mountain
#

sometimes you should intervene in code reviews and say that the thing could be a lot cleaner if written differently

fiery cosmos
#

how do y'all feel about these coding tools like where AI will partially write something or auto-suggest

opal oriole
#

Yeah, but it's a balance, do it too much and it creates conflict.

haughty mountain
#

like, I've had colleagues code that I genuinely didn't understand until I went through and re-wrote it

#

because it was a real mess of conditional logic

#

which could have been refactored into something way clearer

opal oriole
haughty mountain
#

if I can easily understand the code easily I rarely have strong opinions, unless it's doing something very silly

opal oriole
#

It's weird grey area that stuff.

opal oriole
haughty mountain
#

I'll be OCD about it only if you break our style guide 😛

#

outside that lies nuance

opal oriole
#

Yeah run through the tools.

haughty mountain
#

style guide is not only tooling though

opal oriole
#

Then it's just the process and not so much personal conflict.

haughty mountain
#

naming schemes, naming standards, restrictions on how you write stuff to keep things sane

opal oriole
#

Some things still require humans to look at it, but what is important is that the rules are written.

stable pecan
#

@sweet roost , @hearty python I had to go, but I thought yall would enjoy another way to parse lists:

def parse(text):
    tokens = iter(
        text
        .replace(",", " ")
        .replace("[", " [ ")
        .replace("]", " ] ")
        .split()
    )

    def _parse():
        for token in tokens:
            if token == "[":
                yield list(_parse())
            elif token == "]":
                return
            else:
                yield int(token)

    return next(_parse())

Both linear and recursive!

haughty mountain
#

they list not only what the rules are, but the motivation behind them

#

so even if you disagree with some choice there is motivation behind the choice

#

(and if you really feel like it's wrong you can try to work to change the style guide by giving some motivation to the contrary)

#

it makes the style guide very long though 😛

opal oriole
#

It does take more work though.

haughty mountain
#

and the google python guideline is still short compared to their C++ one

#

the C++ one has almost 30k words

#

the python one 12k

haughty mountain
#

to warrant that extra cost

opal oriole
#

Otherwise, copy what you see already is generally the rule.

haughty mountain
#

which works great if everyone was a good programmer 😛

#

actually, even with good programmers you have diverging styles

opal oriole
#

(And a big company will have varying skill levels)

fiery cosmos
#

i probably brought this up before, but do you all think anyone can code or it requires a certain type of thinking that is less learnable? like super left brained or whatever (if thats a real thing). could some masterful artist learn to code?

haughty mountain
#

I think "anyone can code" is true at some basic level, but I don't think everyone has the capability of being a great programmer

#

people are quite different

opal oriole
#

Somewhat touchy topic. IMO anyone, and the reason why some seem to not be able is due to various other factors (their life situation).

haughty mountain
#

"anyone" encompasses a lot

opal oriole
#

Probably the most important thing is just interest though.

fiery cosmos
#

i don't think it needs to be a touchy subject. it's just a matter of inherent giftedness toward a particular topic. you'd probably not take a masterful programmer and make them some elite artist, as an example

#

yeah its just nature v nurture

haughty mountain
opal oriole
fiery cosmos
opal oriole
#

But not much can be done if i'm born in a place without food, let alone a computer.

fiery cosmos
#

many brilliant people everywhere

#

of course

haughty mountain
fiery cosmos
haughty mountain
#

your average person being capable doesn't mean everyone is

fiery cosmos
#

of course

haughty mountain
#

I think the average person can learn to become a decent programmer, for sure

fiery cosmos
#

what separates a decent programmer from an elite one

haughty mountain
#

I just don't like the "anyone" framing because there are always outliers

haughty mountain
fiery cosmos
#

fair enough

haughty mountain
#

like, I do interviewing for my company, you can easily tell when people really know their stuff

fiery cosmos
#

like an example would be someone who wrote a great program or platform or app or something?

fiery cosmos
haughty mountain
#

I know google has numbers for number of applications, let me find them

fiery cosmos
#

one of those big techs puts a 6 month cooldown on you if you fail their interview

haughty mountain
#

so this is from a few years back, they got ~3 million applications in a year

fiery cosmos
#

can you believe apple is now worth more than alphabet, meta, amzn, and another big tech combined??

haughty mountain
#

and the acceptance rate is stated as 0.2%

fiery cosmos
#

im surprised amzn isn't more profitable, they also deal in software

#

that's insane

haughty mountain
#

that's still 6k people

opal oriole
#

Big companies get spammed.

#

Which is really annoying for those that know their stuff.

fiery cosmos
#

they have among the best percs though, so there is good reason. if you work at google and die your children get your salary until they turn 18

haughty mountain
#

so order of magnitude thinking, 1/1000 gets hired, google has ~3 stages

#

CV screening (I'm guessing probably only 1/100 gets through that, it's very aggressive)

fiery cosmos
#

CV screening is automated?

haughty mountain
#

phone interview (let's assume 1/10 gets through)
full interview (probably another 1/10)

fiery cosmos
#

are you tooting your own horn rn

haughty mountain
#

the distribution is probably a bit different, but it feels about right

#

I'm just trying to put that number into context

#

many stages, pretty aggressive culling in each

fiery cosmos
#

well, lots of companies need programmers, even if they are mediocre

haughty mountain
#

I have no clue how CV screening works at google, part of it is probably automated

fiery cosmos
#

data science to enable higher sales isn't exactly product breaking

haughty mountain
#

considering 3M of them

fiery cosmos
#

data science at a tent selling company

haughty mountain
#

realistically the CV screening is probably more aggressive than 1/100 pithink

#

since anything after that point will involve a lot of costs

fiery cosmos
#

alright heres my CV: do i get through?

knows good stuff and such, and is a very stand-up individual

#

hired ✅

#

do you know the "you're hired" trick?

haughty mountain
#

my CV is terrible looking and breaks so many "rules" people say you should follow

opal oriole
#

Automated screen is most likely keyword based.

#

(Some people tried just spamming keywords and it works)

haughty mountain
#

thankfully I haven't had to go through a CV screening process

#

it's always been recruiters reaching out to me

fiery cosmos
opal oriole
#

In smaller companies it can often be someone reaching out to you too.

#

Especially if you have been posting things.

#

Doing your own interesting stuff.

fiery cosmos
#

the hired trick is this:

interviewer: "hello, what is your name?"

interveiwee: "hired."

interviewer: "you're hired?"

interveiwee: "great. see you Monday!"

#

ᶦ'ˡˡ ˢᵉᵉ ᵐʸˢᵉˡᶠ ᵒᵘᵗ

#

oh one more question

#

when trying to remove list indices from my stack

haughty mountain
#

wait what are you trying to do?

fiery cosmos
#

i was unexpectedly getting p is not in list

haughty mountain
#

calling remove is a big red flag to me

fiery cosmos
#

i'm trying to go and remove that array location to make the stack of free elements accurate

#

i have some degree of confidence it works, because i am inserting all the keys in my test case. let me try a larger input..

haughty mountain
#

why do you need to remove the array location?

fiery cosmos
#

oh no

haughty mountain
#

like you know when you need to add a new node

fiery cosmos
#

i just tried an execution and entered a forever loop 😭

#

ok so a smaller input size worked, keys = 36

haughty mountain
#

what's that code even doing?

fiery cosmos
#

stack is a list of bucket locations

haughty mountain
#

you try to insert at p (the primary hash) self.tablesize times?

fiery cosmos
#

sorry that's not the whole snippet

#

1s

#

oh duh

#

it only failed bc i didn't update my headers

haughty mountain
#

why do you need the remove?

#

also, don't do this self.stack.pop(0)

fiery cosmos
#

bc they want that "stack" to represent the free bucket locations

haughty mountain
#

unless you decided to use a deque for some reason

fiery cosmos
#

no, i still have a list named stack

fiery cosmos
#

output looks fine

haughty mountain
#

it's O(n)

fiery cosmos
#

this was for k = 84 keys

haughty mountain
#

correctness isn't the issue

fiery cosmos
#

and chaining

haughty mountain
#

it's just super dumb from a performance point

fiery cosmos
#

is there a better way to pop from front?

haughty mountain
#

pop() which pops from the end is O(1)

#

why do you want to pop from the front?

#

if you pop from the front and insert in the back it's not a stack even

fiery cosmos
#

no i'm aware. there is no insertion

haughty mountain
#

if you just want to start picking low indices start with it being a reversed range

#

and pop from the end

fiery cosmos
#

ohh

#

right ok

haughty mountain
#

granted, you are dealing with so small tables basically nothing matters performance wise

#

which kinda sucks

fiery cosmos
#

it's ok, i know why is it wrong

haughty mountain
#

but going back to this, why would you remove?

fiery cosmos
#

i wonder if popping from the back would place things outside the artifical modulo constraint?

#

or sorry

#

popping the highest index first

fiery cosmos
haughty mountain
#

oh, because the first position is special

#

well, that sucks

fiery cosmos
#

i could make the stack only up the the modulo integer..

haughty mountain
fiery cosmos
#

right

haughty mountain
#

rather than the actually usable ones

#

again, this thing is immensely broken

fiery cosmos
#

they "become" usable

#

i am aware, don't remind me

#

had a total meltdown last night over it

haughty mountain
#

doing hacks that shouldn't be needed to accommodate their terrible choice isn't a great idea

#

it only makes things more confusing

fiery cosmos
#

i just wonder if i should let the thing 'overflow' into using the indices beyond the modulo constraint

#

or just only make the stack elements up to that

haughty mountain
fiery cosmos
#

correct

#

i've tried debating w prof over this for hours, she does not understand how its supposed to work

#

its painfully obvious

haughty mountain
#

an O(n) cost for every insertion

fiery cosmos
haughty mountain
#

remove is O(n)

#

actually, I feel you can solve this nicer

#

instead of doing the remove, why not, when getting a new bucket, pop until you get a bucket that you know is free?

opal oriole
haughty mountain
#

given an index you could pretty easily check if the bucket is empty

fiery cosmos
#

uhh right now i have bigger fish to fry, i'm getting IndexError: pop from empty list

#

that is, of course, when i try an input that is one too big for the tablesize

#

i tried key = 121, tablesize 120

#

buckets size 1

#

i was just making sure my error checking still worked, it does not

haughty mountain
#

wait, the chained one is the one exception where you can actually use all the buckets

fiery cosmos
haughty mountain
fiery cosmos
#

no i get that, but can we first solve my error

#

line 131, in chaininsert new_p = self.stack.pop() IndexError: pop from empty list

#

so weird

#

keep in mind, this is only for when there are too many keys to fit in the table

#

lms where i thought i was catching that

haughty mountain
#

so you're inserting the 121th key and it fails?

fiery cosmos
#

ah i think i've got it. i had the error catching in one prog and not the other

#

CRAP

#

i got it working to catch the error but now it's not working for legitimate input. everything beneath my first context man is greyed out. 1s

#

is there some proper way to close a context manager maybe i dont know about?

haughty mountain
#

huh?

#

what are you even doing?

#

the point of context managers are that they handle resources

fiery cosmos
#

i put my error catching logic in the same with open as the one we just developed

#

and it worked great, but now the code is never running past it, as i can tell from everything being greyed out

#

am i maybe missing a continue or pass or break or close() or something

#

i tried like output.close(), close(output) etc

haughty mountain
#

why would you need to close it?

#

that's the point of the context manager

#

that you don't need to

fiery cosmos
#

i have two separate ones

#

this is the one above the rest of my logic

haughty mountain
#

I can't help much without the code...

#

other than making dumb guesses

fiery cosmos
#

i'll pastebin

haughty mountain
#

it's clearly either some infinite loop or you unconditionally exiting in some way

fiery cosmos
#

dm'd

haughty mountain
#

err

#

yes, it exits

#

just like you explicitly told it to

fiery cosmos
#

o m g

#

thank you

fiery cosmos
#

hmm so i am printing but also throwing a command line error

#

what if you want to avoid command line errors from displaying?

haughty mountain
#

in what case?

fiery cosmos
#

so i'm not showing that ugly pop from empty list error

#

in the case that the keys > tablesize

haughty mountain
#

that's an error in your code, no

fiery cosmos
#

yes

haughty mountain
#

why wouldn't you want that shown?

#

fail loudly

#

so you can fix it

fiery cosmos
#

fair enough. i just feel like its cleaner if it runs successfully and they check the output and see the error message

#

rather than both

haughty mountain
#

if anything, the command line is the place where errors for sure should go

#

maybe with a copy also logged to file

fiery cosmos
#

i'll just leave it, i've already spent way too much time on this today. i just need to be sure the core functionality is up and running

#

also i have not yet eaten and its 7:00pm

#

so, i need to do that.

#

ah crap

#

it doesn't work for the tablesize = 40 and bucketsize 3 case. let me check

#

so weird

haughty mountain
#

linearinsert and quadinsert being basically copies of each other is...not great

#

they have one difference which probably is a bug

fiery cosmos
#

i don't understand why this isn't working for the tablesize = 40 and bucketsize = 3 case

#

i'm computing the size of the table as (hashtable.tablesize*hashtable.bucketsize)

#

think i got it

haughty mountain
#

btw, your linearinsert and quadinsert code doesn't make sense to me

fiery cosmos
#

ok we're good

#

how so

#

brb

haughty mountain
#

why do you have like 4 calls to try_insert in it

#

in a sane world the whole linear insert loop is

h = primary_hash(key, self.primary_hash_int)
for i in range(self.tablesize):
  j = (h + i) % self.table_size
  if self.table[j].try_insert(key):
    self.count += 1
    break
```minor difference in the bad reality, different mod and a terrible if check
fiery cosmos
#

does this first try the initial hash location when i = 0?

#

you have to try the primary hash location first, before computing a probe

haughty mountain
#

h + 0 is h yes

fiery cosmos
#

probing is to resolve a collision

#

but then i am modding by primary_hash_int again

#

i just dont know if that'll first check the h location

haughty mountain
#

x % m % m is the same as x % m

fiery cosmos
#

ok

haughty mountain
#

do you know what the mod operation does?

fiery cosmos
#

returns the remainder after dividing the two numbers

haughty mountain
#

well yeah

#

but it puts the number in the range [0, m)

#

by adding/subtracting a multiple of m to put it in that range

#

if you're already in that range, nothing happens

#

hence why modding twice doesn't change anything

fiery cosmos
#

can i ask you something

#

how does the chaining ever get like a pointer to an empty location

#

i feel like that'll never happen

#

oh i does when we pop from the stack

#

but when we first arrive at a bucket, it'll never have a pointer to an open location

#

so why are we checking that

#

why are we following that and trying to insert rather

haughty mountain
fiery cosmos
haughty mountain
fiery cosmos
#

i don't see any chains every occurring though

#

i don't think we'll ever arrive at a bucket that has a pointer. the only pointing we do is instant during our stack pop

haughty mountain
#

we assign pointers when we add buckets

#

if you have a collision you'll follow the link

fiery cosmos
#

i can't see it, i could be wrong

haughty mountain
#

can't see it how?

#

in the table data?

#

in the code logic?

fiery cosmos
#

i cannot see it in the logic, yes. i'll check again

#

i just feel that when we first arrive to a bucket, it'll never point to an empty bucket. maybe that isn't the point. the point is so that we can follow the chain for lookups

haughty mountain
#

it's more relevant when doing lookups for sure

#

in insertion it's just the terminating case

#

though it catches both the first insertion (primary bucket is empty)

#

and the insertion when we need to add a bucket

#

no need for the first if

fiery cosmos
#

i need it, there is a tablesize = 40 and modulo 41 case

haughty mountain
#

you don't need the first if

#

second sure, because of that case

#

but not the first one

fiery cosmos
#

how

#

like, why can't we get something beyond the tablesize in that scenario

#

cause it'll mod to 40 in the highest case?

haughty mountain
#

why would the first if matter for anything?

fiery cosmos
#

if h(key) = 41

#

and tablesize is 40

haughty mountain
#

ok

#

walk through that case in the code

#

in your head

fiery cosmos
#

oh

#

h gets set equal to j

#

ok

haughty mountain
#

other way around

fiery cosmos
#

right right

#

so i can use the same clause for quadinsert

haughty mountain
#

the only difference between those two is the probing

#

you could re-use the same code for both

fiery cosmos
#

right

haughty mountain
#

(h + probing_fun(i)) % mod

#

where probing_fun(i) is i for the linear case and i*(i+1)//2 for the quadratic case

fiery cosmos
#

i'm moving slow bc i am updating two different scripts

#

right, you pointed that out before i recall

#

interesting that there is a case where we can go past the modulo constraint with chaining

#

i guess its "less broken"? idk

#

still, load factors have been a headache

#

i just calculate both

#

tysm for your help!!!!!!!!!!

#

huh. its no longer printing that stack error

#

ooh that was only for chaining, i am running quad probing nvm

haughty mountain
#

the primary hash mod is still dumb

fiery cosmos
#

i still wonder if they want to overflow into that area, i will ask

fiery cosmos
#

i totally did not have a full meltdown over this

haughty mountain
#

the only way to get to the extra few buckets is chaining

fiery cosmos
#

right. at least there is that. but like, the notion of creating a bigger table is totally out the window w linear and quad

#

doesn't matter if you make a bigger table or not 😂

#

i know you still don't like that O(n) insert, i can fix that before due date

haughty mountain
#

you can easily check if a bucket is empty, right?

#

so you can pop until you actually get an empty bucket

#

that removes the need for the .remove

fiery cosmos
#

i would need the remove afterward though no?

haughty mountain
#

so the stack contains potentially empty buckets

#

you wouldn't need to

fiery cosmos
#

its supposed to keep track of the free space, not the potentially free space

#

but yeah, its a great point considering the whole point of a hashtable is those O(1) operations..

haughty mountain
#

I don't know of a way to keep a stack of free buckets that allows removals like the ones you would need

fiery cosmos
#

maybe a deque?

haughty mountain
#

without getting these expensive removal costs

#

why would that help for removal?

#

you still need to find the element to remove

#

which is O(n)

fiery cosmos
#

i think list lookups are O(1) and linear search is O(n)?

#

oh i see why

#

bc im not removing by index, im literally finding and removing the element

#

ok ok

haughty mountain
#

removing by index would be O(n) for deque too

#

deque is basically a linked list complexity-wise

fiery cosmos
#

removing by index is O(n) for a list?

haughty mountain
#

even indexing is O(n) for a list deque

#

well

#

O(distance from either end to the index)

fiery cosmos
#

right ok

haughty mountain
#

err

fiery cosmos
#

but then wouldn't hash tables not be as fast?

haughty mountain
#

deque, not list

fiery cosmos
#

we're doing the same thing w a hashtable (indexing into the array)

haughty mountain
#

indexing into a list if O(1)

fiery cosmos
#

then removal should be O(1) if i am removing by index?