Insert one value into a set02.01
Insert adds a value if it was absent. Size grows only then. If it was present, the set is unchanged. After insert(x), contains(x) is true.
Insert does not append a second slot. There is one membership bit per value.
Same skill, three traces. Read all three before you try it.
01new value - given
a = [4, 1, 9]as{4,1,9}, insert8- walk
8was outsize
3→4- result
{4, 1, 9, 8}
02duplicate - given
a = [4, 1, 9]as{4,1,9}, insert1- walk
1already insize stays
3- result
{4, 1, 9}
03onto empty - given
a = [], insert4- walk
first member
- result
{4}
insert(s, x).s is the hash set. x is the value to add.If
x is absent, add it and grow size by 1. If x is present, leave s unchanged. Then contains(x) is true.a = [4, 1, 9] as {4,1,9}, insert 8 → {4, 1, 9, 8}.a = [4, 1, 9] as {4,1,9}, insert 1 → {4, 1, 9}.a = [], insert 4 → {4}.constraintsvalues are integers. The set may be empty.
- Contains Duplicate0/3 skills ready · hash sets · easyopen
- Contains Duplicate0/3 skills ready · hash sets · easyopen
Every Check with Awel is frozen here. Open one to read the code or load it back into the editor.