Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Logarithmic Cons-Pair Lists

Name: Anonymous 2014-05-26 3:13

What is the name of immutable data structure, which has O(1) access to the head element and logarithmic increasing access cost for the following elements?

It can be implemented by converting tail into an array, when prefix size becomes larger than the tail size. I.e. (cons prefix array)

Name: Anonymous 2014-05-26 3:46

>>1
balanced binary tree with path copying for insertion and deletion.

Name: Anonymous 2014-05-26 4:17

Endotensors.

Name: Anonymous 2014-05-26 4:19

>>1
Heap

I win!

Name: Anonymous 2014-05-26 5:13

>>2

binary tree doesn't give O(1) access to the CAR.

Name: Anonymous 2014-05-26 5:15

>>4

Nope. The heap is "complete binary tree", which means it is balanced and doesn't give O(1) access.

Name: Anonymous 2014-05-26 5:32

>>5
It does if the car is the root.

Name: Anonymous 2014-05-26 5:47

>>7
No warranty that required node will be root.

Name: Anonymous 2014-05-26 5:52

>>8
just do it leik this


1
2 3
4 5 6 7

Name: Anonymous 2014-05-26 6:51

>>9

so how do you do (cons x xs)?

Name: Anonymous 2014-05-26 7:23

>>10
You could do it, but it would be ineffient for this data structure. As long as you treat it like an immutable array you are fine.

Name: >>11 2014-05-26 7:24

good operations would be random access, creating a clone of the array where an item at a specific index is changed, and creating clones where new elements are inserted at the back.

Name: >>11 2014-05-26 7:30

Though you could implement it as a balanced binary tree sorted by the index of the element and then just save another reference to the front element at the left end of the tree to improve its access time.

Name: Anonymous 2014-05-26 7:31

>>13

(cons x xs) and (cdr xs) would still be O(log2(n))

Name: Anonymous 2014-05-26 7:34

>>14
I don't think you can get around (cons x xs) being O(log2(n)) but since its immutable you could save a reference to the old tree to speed up (cdr xs). But it would use memory up the ass.

Name: Anonymous 2014-05-26 7:59

also cdr is typically used for traversal, which can be replaced with a functional iterator.

Name: Anonymous 2014-05-26 9:11

>>14-15
No need to specify the log base in time complexities.

Name: Anonymous 2014-05-26 18:04

>>17
I'll express whatever log base I want, MUTHERFOCKER!

Name: Anonymous 2014-05-26 19:44

>>18
And you wouldn't be wrong. O(lg(n)) == O(log(n)) == O(log666(n))

Don't change these.
Name: Email:
Entire Thread Thread List