Homework 3 Questions - Algorithms and Data Structures | CSE 331, Assignments of Computer Science

Material Type: Assignment; Professor: Weng; Class: Algorithms and Data Structures; Subject: Computer Science & Engineering; University: Michigan State University; Term: Spring 2009;

Typology: Assignments

Pre 2010

Uploaded on 07/22/2009

koofers-user-om2
koofers-user-om2 🇺🇸

10 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CSE 331: Homework 3 Spring 2009
Due by 11:59 PM Friday 6 Feb 2009
Submission
Submit your work via Handin. Name your file <name>Results.pdf, where
<name>is your last name, as in jonesResults.pdf. Please make sure that your
name and your MSU net ID appear at the top of every page and once at the
beginning of any code that you may submit.
Problems:
Do the following problems from Chapter 7 of the text. As always, we do not
want just the “answers”, we want the reasoning behind the answers.
1. (35 points) Show how the quick-sort algorithm (page 286, but do not call
insertion sort) sorts the following list: [ 64, 12, 34, 44, 86, 3, 7, 55, 99, 11,
41]. The purpose of this assignment is to help you understand how the
quicksort algorithm works, in detail.
Draw the calling diagram as a tree.
(a) The root is the original call.
(b) Use median3 with no randomness (i.e. left, right, center) in calculat-
ing the result.
(c) Show each list after the median3 step.
(d) Show each list after the swap step.
(e) Give the parameters of every call to quicksort.
(f) The order of the numbers needs to be correct at every step.
(g) After each median step and swapping step, the pivot should be de-
noted in some way.
(h) It is not necessary to show the quicksort step on a list of three num-
bers or less. Similarly, it’s not necessary to show the median step on
a list of a single number.
(i) For this exercise implement the quicksort exactly as it is in the book
although there are other, alternative, ways to do quicksort.
(j) Do not use insertion sort at all, even though the algorithm in
the book on page 286 does for smaller inputs.
1
pf2

Partial preview of the text

Download Homework 3 Questions - Algorithms and Data Structures | CSE 331 and more Assignments Computer Science in PDF only on Docsity!

CSE 331: Homework 3 Spring 2009

Due by 11:59 PM Friday 6 Feb 2009

Submission

Submit your work via Handin. Name your file Results.pdf, where is your last name, as in jonesResults.pdf. Please make sure that your name and your MSU net ID appear at the top of every page and once at the beginning of any code that you may submit.

Problems:

Do the following problems from Chapter 7 of the text. As always, we do not want just the “answers”, we want the reasoning behind the answers.

  1. (35 points) Show how the quick-sort algorithm (page 286, but do not call insertion sort) sorts the following list: [ 64, 12, 34, 44, 86, 3, 7, 55, 99, 11, 41]. The purpose of this assignment is to help you understand how the quicksort algorithm works, in detail. Draw the calling diagram as a tree.

(a) The root is the original call. (b) Use median3 with no randomness (i.e. left, right, center) in calculat- ing the result. (c) Show each list after the median3 step. (d) Show each list after the swap step. (e) Give the parameters of every call to quicksort. (f) The order of the numbers needs to be correct at every step. (g) After each median step and swapping step, the pivot should be de- noted in some way. (h) It is not necessary to show the quicksort step on a list of three num- bers or less. Similarly, it’s not necessary to show the median step on a list of a single number. (i) For this exercise implement the quicksort exactly as it is in the book although there are other, alternative, ways to do quicksort. (j) Do not use insertion sort at all, even though the algorithm in the book on page 286 does for smaller inputs.

Take a look at the document hw03p1example.doc for an example of the type of answer that is expected. The particular example here was made with Open Office Draw, but you can make your figure by hand or however you like.

  1. (20 points) Problem 7.32 (a-c) on page 309. Describe your algorithm in detail for each size N. Try to keep the running time of your algorithm as efficient as possible. Additionally, provide the complexity (in terms of big O) of each of your algorithms. Try to find as tight an upper bound as possible.
  2. (20 points) Problem 7.33 on page 309. Prove for any algorithm that uses comparisons. Your proof must work in the average case, not just in the best case.
  3. (15 points) Problem 7.17 on page 307.
  4. (10 points) Do problem 3.2 on page 108 of Weiss. You are given a pointer P to the first node of the swap. Assume that you have at least two elements in the list, but maybe more. Write pseudo code in your report. Assume the data structure for the singly linked list is of the following form:

struct Node { int data; Node *next; };

For the doubly linked list, you will use:

struct Node { int data; Node *next; Node *prev; };