Disadvantages of using System.currentTimeMillis( ) or any other time measurements to measure
runtimes→ Runtimes would be different depending on the hardware and software used
Reversal of a stack using an array:
→ Temp array is created, all elements are pushed to it and then popped back into the array as pushing in the order 1, 2, 3 will always pop in
the order 3, 2, 1 and vice versa.
1 /** A generic method for reversing an array. */
2 public static <E> void reverse(E[ ] a) { 3 Stack<E> buffer = new ArrayStack<>(a.length);
4 for (int i=0; i < a.length; i++)
5 buffer.push(a[i]);
6 for (int i=0; i < a.length; i++)
7 a[i] = buffer.pop( );
8}
All operations of a stack or queue using an array occur in O(1) time and O(n) space is used (array of variable size
therefore linear space complexity)
In the linked list implementation of a queue class, the insert method (enqueue) adds the data at the tail.
A single queue or a single stack can be used to check the syntactic validity of a post-fix arithmetic expression
If the times it takes to run a particular program for two sets of inputs, one of size 2000 items and another of size
4000 items, were 2 ms and 32 ms, respectively. And, assuming that the time (T) it takes to run this program has a
power relationship (of the form: aNb ) to the size of the input set (N), what is b?
Exponentials always increase at a greater pace than powers as they approach infinity
Adding at head has the longest runtime as that would mean shifting all remaining elements one index to the
right so O(n)
Euler tour traversal: traversing through the tree thrice →
1- from the left → preorder (P → L → R)
2- from the right → postorder (L → R → P)
3- From the bottom → Inorder (L → P → R)
Inorder traversal → first node = last one on the left
→ last node = last one on the right