Git Product home page Git Product logo

patmorin / ods Goto Github PK

View Code? Open in Web Editor NEW
1.2K 63.0 249.0 261.59 MB

Mission: To provide a high-quality open content data structures textbook that is both mathematically rigorous and provides complete implementations.

Home Page: http://opendatastructures.org/

License: Other

Makefile 0.74% C 10.55% C++ 10.37% Java 17.17% TeX 47.90% Shell 0.03% Python 11.30% Gnuplot 0.08% CSS 0.04% Perl 1.82%
textbook data-structures

ods's Introduction

latex/ contains the latex sources
java/ods contains the java sources
cpp contains the C++ sources (still under development)

To make the books (ods-java.pdf and ods-cpp.pdf and ods-python.pdf):
  mkdir ~/texmf/tex/latex/ods/
  cp ods-colors.sty ~/texmf/tex/latex/ods/
  cd latex ; make
This will require a decent installation of pdflatex, perl, ipe, inkscape,
gnuplot, and pdftk.  

If you have problems with tikz figures, consult the solution here: 
http://goo.gl/hCvlyp

If ipetoipe generates errors about ods-colors.sty, then try this:

  mkdir -p ~/texmf/tex/latex/ods/
  ln -s $PWD/latex/ods-colors.sty ~/texmf/tex/latex/ods/
  texhash


To make the Java archive ods.jar:
  cd java ; make

To make both:
  make

What's in here:
  java/test    - Test code from Sun/Oracle and Apache
  java/junk    - Small sample code snippets used in the text
  java/ods     - The Java data structures sources
  cpp          - The C++ data structures sources and sample code
  python       - The Python code used to generate the pseudocode version
  python/tests - Unit tests for the Python code
  latex        - The book's latex source code and scripts
  latex/figs   - The book's ipe figures
  latex/images - Images used in the book


How it works:
The Makefile and Perl script in ./latex do the following:
  1. Convert ipe figures in ./latex/figs into pdf
  2. Convert svg figures in ./latex/images into pdf
  3. Scan the latex sources and generate -java.tex and -cpp.tex files
     that include source code from ./java and ./cpp directories
  4. Run pdflatex and bibtex to generate the file ods-java.pdf and
     ods-cpp.pdf

ods's People

Contributors

caprice-j avatar cdelahousse avatar fluxrider avatar hugelgupf avatar ianedington avatar neomantra avatar patmorin avatar ruiixu23 avatar tekinozbek avatar yinyanghu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ods's Issues

Possible typo in Section 1.3.1

In section 1.3.1 (pseudocode edition):

The expression b^x denotes the number b raised to the power of x. If x is a positive integer, then this is just the value of b multiplied by itself x-1 times:

Shouldn't it be x times instead of x-1? It even shows so in the accompanying picture:

Make process error

cd images ; make
make[1]: Entering directory '/home/aveyond/Downloads/ods/latex/images'
make[1]: Nothing to be done for 'all'.
make[1]: Leaving directory '/home/aveyond/Downloads/ods/latex/images'
cd figs ; make
make[1]: Entering directory '/home/aveyond/Downloads/ods/latex/figs'
ipetoipe -pdf selist-remove-b.ipe
Document selist-remove-b.ipe has 1 pages (1 views)
There were Latex errors.
Makefile:15: recipe for target 'selist-remove-b.pdf' failed
make[1]: *** [selist-remove-b.pdf] Error 1
make[1]: Leaving directory '/home/aveyond/Downloads/ods/latex/figs'
Makefile:24: recipe for target 'figs' failed
make: *** [figs] Error 2

All required packages are installed.

Error in math statement ??

In page 10 there is the following mention
'When x is a negative integer, b^-x = 1/b^-x'

Shouldn't this be
When x is a negative integer, b^-x = 1/b^x

?

python/util.py

lines 14/15

def new_boolean_matrix(n, m):
    return numpy.zeros([n, n], numpy.bool_)

shouldn't this be

def new_boolean_matrix(n, m):
    return numpy.zeros([n, m], numpy.bool_)

?

Bibliography URL for "Mathematics for Computer Science" returns with 404 Not Found

It appears the URL in the bibliography for L, L, and M's Mathematics for Computer Science is broken: http://courses.csail.mit.edu/6.042/spring12/mcsfull.pdf returns with a 404 "resource not found" response.

A bit of exploration of the 6.042 course page lead me to this URL—http://courses.csail.mit.edu/6.042/spring12/mcs.pdf—which does resolve to a PDF text. I am uncertain if it is equivalent to the intended resource, so I'll leave the actual correction of the bibliography to someone who can confirm this is the same.

Note: thanks for the helpful (and fabulously licensed) text! :-)

Conflict between package babel and fancyhead

When I try to use \usepackage[portuguese]{babel} to translate headers to portuguese (for example Chapter to Capítulo),
there is a error in the LaTeX compilation: "Argument of @ "rightmarksection" has an extra }"

If I comment the following lines in ods.tex the error disappear but the fancy style is lost.

\fancyhead[CO]{\small\rightmarktitle} % section title, right center
\fancyhead[RO,LE]{{\small\rightmarksection}}

How to fix the error without losing the style?

audio in skiplist-i

The last audio clip for the skiplist-i video needs to be rerecorded at home.

Change of parameter of inkscape in latex/images/Makefile

inkscape changed how to identify export file.

Now it is
%.pdf : %.svg
inkscape --export-pdf=$@ $<

%.eps : %.svg
inkscape --export-eps=$@ $<

It should be now:

%.pdf : %.svg
inkscape --export-type=pdf --export-filename=$@ $<

%.eps : %.svg
inkscape --export-type=eps --export-filename=$@ $<

4:3 screen pdf make option request

The screen pdf format file doesn't fit screen well, because most e-readers
such as iPad, kindle, etc. holds a screen of 4:3, which makes the "screen pdf" hard to fit the screen. Could you please provide 4:3 version screen pdf file or a compilation option in makefile? Thank You!

RootishArrayStack Space usage subsection

There is a question about ods-cpp 2.6.2 Space Usage " The number of blocks r, used by a RootishArrayStack that stores n elements therefore satisfies (r − 2)(r − 1) ≤ n " . I think n should satisfies (r-2)(r-1)/2 ≤ n. And the following proof process should be changed correspondingly.

height(u) on section 6.11 - binary tree

Hi. I think there is an error on function height(u), section 6.11, for binary trees. The right function must be

height(u)
  if u = nil then return -1
  return 1 + max(height(u.left), height(u.right))

in order to give the right answer. Thank you for your great work. I'm preparing a translation to brazilian portuguese from your book.

DLList.remove and SLList.remove in the python version do not return values.

The remove method of DLList of the Python version does not return values. The following is the snippet of the code.

   def remove(self, i):
        if i < 0 or i >= self.n: raise IndexError()
        self._remove(self.get_node(i))

The "remove" operation should return the removed values in this textbook. The same problem exists in the remove method of SEList of the Python version.

ArrayStack looks bogus

I started the book and the first datastructure feels strange and it gave a strange view on the rest of the book.
See
https://github.com/Ducasse/Containers-XP/blob/master/Containers-XP/CTArrayStack.class.st

and copied here.

Started to implement ArrayStack from this book https://opendatastructures.org/
But the first datastructure feels strange and it gave a strange view on the rest of the book.
The book defines the state of ArrayStack as an array and a number representing the number of elements.

T[] a;
int n; 
int size() {
   return n; }

For example add is defined as follows:

void add(int i, T x) {
   if (n + 1 > a.length) resize();
   for (int j = n; j > i; j--)
     a[j] = a[j-1];
   a[i] = x;
   n++;
}

Set is defined as follows:

 T set(int i, T x) {
   T y = a[i];
   a[i] = x;
   return y;
}

To me these definition are bogus.
Indeed

  • first set does not update the number of elements, so using set break the invariant that n is the number of elements stored.
  • second set should not return the previous value because it propagates null value
  • third why set and get are needed (I renamed them as at: at:put:) but they are not needed in a Stack API.

C++ version of BinaryTree::bfTraverse() is quirky/broken

The book text, as well as the Java and Python implementations, all use Queues to accumulate nodes to visit, but in the C++ code, the supporting data structure is ArrayDeque<Node*>. Elements are added at q.size() but instead of being removed at the other end, they're removed at q.size()-1. (See full implementation pasted in below.)

This strikes me as odd; I'm happy to submit a PR to fix this, but I wanted to check that I'm not overlooking something.

void BinaryTree<Node>::bfTraverse() {
	ArrayDeque<Node*> q;
	if (r != nil) q.add(q.size(),r);
	while (q.size() > 0) {
		Node *u = q.remove(q.size()-1);
		if (u->left != nil) q.add(q.size(),u->left);
		if (u->right != nil) q.add(q.size(),u->right);
	}
}

[Java] Exception in BFS/DFS algorithm for graph

In section 12.3.1, the algorithm for BFS & DFS is given as below:

void bfs(Graph g, int r) {
   boolean[] seen = new boolean[g.nVertices()];
   Queue<Integer> q = new SLList<Integer>();
   q.add(r);
   seen[r] = true;
   while (!q.isEmpty()) {
     int i = q.remove();
     for (Integer j : g.outEdges(i)) {
      if (!seen[j]) {
         q.add(j);
         seen[j] = true;
} }
} }

There is mistake in the below highlighted line. It iterates over the value of the edges rather than index.
for (Integer j : g.outEdges(i)) {

If graph doesn't have sequenced number as value, the following line will throw ArrayIndexOutOfBoundsException.

if (!seen[j]) {

For example, graph like this: 0->1, 0->5, 3 -> 5, 0 -> 3 where size of the graph is 4.
while i = 0 and j = 5, It'll try access the seen array with index value 5. which won't exist and throw exception. Because, seen array won't have 5th index.

It also applies to section 12.3.2 (DFS).

In cpp implementation, ChainedHashTable never uses allocTable

Hello,

There is a function called allocTable declared inside ChainedHashTable but it is not used anywhere in the class itself, nor is there any implementation for it.
I thus believe that the implementation of ChainedHashTable will not work because items inside t will not be initialized properly.
I may have missed something as it's been years since I did serious C++, and if that's the case I would greatly appreciate an explanation.

Regards

PDFs contain no table of contents

The pdf files contain no table of contents. I mean, well, there IS table of contents as just a lot of hyperreferences in the beginning of the document, but there's no table of contents that pdf viewer is aware of.

It is a pain to navigate especially if I use pocket book device.

And thank you very much for this project, it is really incredible. Thanks.

[Java] Book update

In Section 1.2.3 of the book. The dictionary/map was compared to the USet interface. One subtle issue here that we won't be able to update the dictionary/map using the add(x) method of USet, since 1) according to the text, two pairs are treated as equal if their keys are equal and 2) the USet add(x) interface states that the element x will be added to the set if not already present.

To create a dictionary/map, one forms compound objects called Pairs, each of which contains a key and a value. Two Pairs are treated as equal if their keys are equal. If we store some pair (k,v) in a USet and then later call the find(x) method using the pair x = (k, null) the result will be y = (k, v). In other words, it is possible to recover the value, v, given only the key, k.

SLList wrong function addAfter

Line 120

protected void addAfter(Node u, Node v) {
		v = u.next.next;
		u.next = v;
		if (u == tail) 
			tail = v;
}

the v=u.next.next; seems wrong, this function will only delete the node after u

Integer Overflow (?) on implementation pp. 127, in section 5.3.3 Hash Codes for Arrays and Strings, C++ edition

I suspect the line

long p = (1L<<32)-5; // prime: 2ˆ32 - 5

causes overflow. long on my machine is 32-bit (printf("%ld\n", LONG_MAX); prints 2147483647), and compiler would give a warning -Wshift-count-overflow on that line. Indeed long type cannot hold that prime number.

I suspect it could be corrected as

unsigned long p = (1L<<32) - 5;

with printf("%lu\n", p); prints 4294967291, which is desired.

However the -Wshift-count-overflow warning: left shift count >= width of type still persists.

With

unsigned long p = (~0L) - 4;

(*)
the warning vanishes.

In summary, I think that line should be (*).

5.2.3 tabulation hashing

In section 5.2.3,w=32 and r=4 as the case which been used in hash method.But as described above ,the size of arrays used by tabulation hashing is w/r = 8 and each array's length is 2^r=8,meanwhile,under the code,the text says:

In this case, tab is a two-dimensional array with four columns and 2^(32/4) = 256 rows

Would this is wrong or something?Maybe r is 8?By the way ,at the begin of the LinearHashTable code(java version),r is inited by 8.
image

Truncated text in pseudocode version

In this line of the intro, the pseudocode version of the book shows the following truncated text:

[...] use of an implementation of the relevant interface (Stack, Queue, Deque, USet, or SSet) provided by the .

5.3.2 the proof of theorem 5.3

At the last paragraph of proo(in page 125),the text says 'By theorem 5.3',but this proof just proves this theorem.Accoding to this section says above,maybe would this be Lemma5.1 which proofs Pr{hash(x) = hash(y)}<=2/2^d?

Fail to make ods document

I am having a problem making the odds document. I am on OS X 10.10. The make fails to make the figures. When I try to use ipetoipe -pdf on a single figure, for example 24rb.ipe, it returns

bash-3.2$ ipetoipe -pdf 24rb.ipe
Document 24rb.ipe has 1 pages (3 views)
There were Latex errors.

If I load the figure into ..ipe.. and run latex from inside ..ipe..I get:

(/Users/emisshula/Library/texmf/tex/latex/ods/ods-colors.sty

! LaTeX Error: Option clash for package xcolor.

See the LaTeX manual or LaTeX Companion for explanation.
Type H for immediate help.
...

l.3 \definecolor
{keyword}{named}{RoyalPurple}
The package xcolor has already been loaded with options:
[]
There has now been an attempt to load it with options
[usenames,dvipsnames]
Adding the global options:
,usenames,dvipsnames
to your \documentclass declaration may fix this.
Try typing to proceed.

! Package xcolor Error: Undefined color `RoyalPurple'.

If I try to run a minimal document using dos-colors:

\documentclass{article}
\usepackage{ods-colors}
\begin{document}
Hello, World!
\end{document}

It writes without error. Any guidance would be appreciated. Thank you.

Can't access the website

I was trying to refer the book to a friend, but the website has been down for quite some time now. Tried through several different connections without any luck.

Python 2 scripts

Python 2 reached its end of life on January 1st of 2020.
Scripts ./figs-python/snarf-fig.py and ./snarf-python.py in latex/ should use explicitly python2 path:

#!/usr/bin/python2

figure 2.3 error?

Possible error in figure 2.3
Text says elements will be moved left if i < n/2, but for example when i=4 and n=9 that means diagram should show moving elements right since 4 >= 9/2

Some very serious error at page 184

Those nil's are considered as nodes when calculation, but not included in data_nodes(T)=n.

So given a red-black tree T with n data nodes, the two highlighted parts should be: log(n+1)+1, log(n+1).

Then height(T)= ((log(n+1)+1)+log(n+1)) - 1= 2log(n+1). (when calculating height, nil's are included; both CLRS, GeeksForGeeks gives the same result.)

This error has to be fixed immediately.

image

Typo in §1.2.1

In §1.2.1 it is written "The remove(x) operation on a priority Queue is usually called deleteMin() in other texts." I believe that this should say "The remove() operation ...": remove takes no parameter.

length is never defined

The length of a path is never defined (it's the number of edges not the number of vertices in the path).

Piece of (pseudo)code missing

In the paragraph

Big-Oh notation is not new or unique to computer science. It was used by the number theorist Paul Bachmann as early as 1894, and is immensely useful for describing the running times of computer algorithms. Consider the following piece of code: One execution of this method involves

in 1.3.3 Asymptotic Notation (pseudocode version), there's a reference to a piece of code that's missing. This refers to the function

void snippet() {
    for (int i = 0; i < n; i++)
        a[i] = i;
    }
}

in the Java version.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.