PP 18.1 The bubble sort algorithm shown in this chapter is less efficient than it can be. If a pass is made throught the list without exchanging any elements, this means that the list is sorted and there is no reason to continue. Modify this alforithm so that it will stop as soon as it recognizes that the list is sorted. Do not use a break statement.
Chapter 18:
EX 18.4: Consider the following list
90 8 7 56 123 235 9 1 653
Show a trace of execution for:
- selection sort
- insertion sort
- bubble sort
- quick sort
- merge sort
PP 18.1 The bubble sort algorithm shown in this chapter is less efficient than it can be. If a pass is made throught the list without exchanging any elements, this means that the list is sorted and there is no reason to continue. Modify this alforithm so that it will stop as soon as it recognizes that the list is sorted. Do not use a break statement.
Chapter 14:
EX 14.1 Hand trace a queue X through the following operations:
X.enqueue( new Integer(4) );
X.enqueue( new Integer(1) );
Object Y = X.dequeue();
X.enqueue( new Integer(8) );
X.enqueue( new Integer(2) );
X.enqueue( new Integer(5) );
X.enqueue( new Integer(3) );
Object Y = X.dequeue();
X.enqueue( new Integer(4) );
X.enqueue( new Integer(9) );
EX 14.2 Given the queue X that results from Exercise 14.1, what would be the result of each of the following?
- X.first();
- Y = X.dequeue();
X.first();
c) Y = X.dequeue();
d) X.first();
EX 14.9 Explain why the array implementation of a stack does not require elemnts to be shifted but the non circular array implementation of a queue does.
PP 14.9 Create a system using a stack and a queue to test whether a given string is a palindrome ( that is, whether the characters read the same both forwards and backwards).