Docsity

5 Questions on Sorting Set of Integer - Problem Solving in Cpp | CSCI 1100, Study Guides, Projects, Research of Computer Science

Toggle sidebar
bg1
CSCI 1100 RPI
Problem Solving in C++ Fall 2006
Select one problem.
Problems are graded on a 0−
1
2
−1scale.
Code must be submitted according to the submission guidelines.
Any written work must be submitted in class on the due date.
Write your name, RIN, RCS id and section # on your work, and staple written work together.
The Sorter – Part 1
This problem deals with sorting a set of integers. Remember that a sequence x1, x2,...,xnof nintegers is
sorted in increasing order if x1≤x2≤ · · · ≤ xn. Similarily one could define sorted in decreasing order. In
this project, when we say sorted, we will mean in increasing order.
When we talk about sorting a sequence of integers, you cannot assume that the integers are all distinct.
1. [10 pts] Give pseudo-code for a function which takes as input a vector of integers and two indices
idxbeg and idxend. The function should check first if the two indices are valid indices for the vector
and that idxbeg≤idxend. If this check fails, then the function should return 0; If the check passes, then
the function should check if the elements in positions idxbeg to idxend are sorted. The function should
return 1 if they are sorted and 0 otherwise.
2. [20 pts] Give pseudo-code for a function which takes as input a vector of integers of size 3 and
rearranges the vector so that it is sorted.
3. [30 pts] Give pseudo-code for a function which takes as input a vector of integers and rearranges the
vector so that it is sorted.
[Hint: A good first step is to switch the first element with the minimum element. Now what will you
do with the second element?]
4. [40 pts] Give pseudo-code for a function which takes as input a file containing an unknown number of
integers in arbitrary order, and creates a second file which contains those same integers sorted.
You may assume that the list of integers though of unspecified size, is not too large – i.e., it can all fit
into the RAM.
5. [50 pts] Give pseudo-code for a function which takes as input a file containing an unknown number of
integers in arbitrary order, and creates a second file which contains those same integers sorted.
You may not assume that the list of integers is small enough to fit into the RAM.
1

Partial preview of the text

Download 5 Questions on Sorting Set of Integer - Problem Solving in Cpp | CSCI 1100 and more Study Guides, Projects, Research Computer Science in PDF only on Docsity!

CSCI 1100 RPI

Problem Solving in C++ Fall 2006

Select one problem. Problems are graded on a 0 − 12 − 1 scale. Code must be submitted according to the submission guidelines. Any written work must be submitted in class on the due date. Write your name, RIN, RCS id and section # on your work, and staple written work together.

The Sorter – Part 1

This problem deals with sorting a set of integers. Remember that a sequence x 1 , x 2 ,... , xn of n integers is sorted in increasing order if x 1 ≤ x 2 ≤ · · · ≤ xn. Similarily one could define sorted in decreasing order. In this project, when we say sorted, we will mean in increasing order. When we talk about sorting a sequence of integers, you cannot assume that the integers are all distinct.

  1. [10 pts] Give pseudo-code for a function which takes as input a vector of integers and two indices idxbeg and idxend. The function should check first if the two indices are valid indices for the vector and that idxbeg≤idxend. If this check fails, then the function should return 0; If the check passes, then the function should check if the elements in positions idxbeg to idxend are sorted. The function should return 1 if they are sorted and 0 otherwise.
  2. [20 pts] Give pseudo-code for a function which takes as input a vector of integers of size 3 and rearranges the vector so that it is sorted.
  3. [30 pts] Give pseudo-code for a function which takes as input a vector of integers and rearranges the vector so that it is sorted. [Hint: A good first step is to switch the first element with the minimum element. Now what will you do with the second element?]
  4. [40 pts] Give pseudo-code for a function which takes as input a file containing an unknown number of integers in arbitrary order, and creates a second file which contains those same integers sorted. You may assume that the list of integers though of unspecified size, is not too large – i.e., it can all fit into the RAM.
  5. [50 pts] Give pseudo-code for a function which takes as input a file containing an unknown number of integers in arbitrary order, and creates a second file which contains those same integers sorted. You may not assume that the list of integers is small enough to fit into the RAM.