Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Conceptual Mechanics - Introduction to Computer Science | CMSI 182, Assignments of Computer Science

Material Type: Assignment; Class: Intro Computer Science; Subject: Computer Science; University: Loyola Marymount University; Term: Fall 2006;

Typology: Assignments

Pre 2010

Uploaded on 08/16/2009

koofers-user-4e2-2
koofers-user-4e2-2 🇺🇸

10 documents

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CMSI 182
IN T R O D U C T I O N T O CO M P U T E R SC I E N C E
Fall 2006
Assignment 1121
Having (presumably) assimilated the conceptual mechanics of the sequential search, binary search, insertion
sort, and quicksort algorithms, as well as the general approaches for iteration and recursion, it’s time to try
writing out iterative and recursive algorithms yourself, either in JavaScript or in pseudocode.
Not for Submission
As has been mentioned, we are currently on Chap-
ter 5 of the Brookshear book.
For Submission
Implement the following algorithms. Use the
JavaScript scratch page for the iteration algorithms,
and use pseudocode for the recursive one.
Iteration
Exponent of a number Use Input 1 to accept a
number, and use Input 2 to accept the power to
which that number should be raised. Provide an
alert that displays the calculated exponent. For
example, if Input 1 holds “3” and Input 2 holds
“4,” then the answer is 81 = 34.
Highest/lowest number finder Use Input 1 to ac-
cept a comma-separated list of numbers. Pro-
vide an alert that displays the highest and lowest
numbers in that list.
Sequential search Use Input 1 to accept a
comma-separated list of items, and use Input 2 to
take the item being searched. Provide an alert
that says “yes” if the target is found and “no” if
it isn’t found.
Recursion
Descendant counter (pseudocode) Given a person
and that person’s family tree, count all of his or
her descendants, across all generations. Provide
this one in pseudocode.
For example: if John has 2 children, Sally and
Jane, Sally has 4 children, and Jane has 1 child,
then John has 7 descendants (Sally, Jane, and the
5 grandchildren). Assume that there is a getDi-
rectDescendants(p) function that will provide the list
of direct descendants for person p. If p has no
direct descendants, then an empty list is returned.
Extra Credit
You will get extra credit if you also implement one
of these algorithms in JavaScript, using the
JavaScript scratch page:
Insertion sort (numbers) Use Input 1 to accept a
comma-separated list of numbers. Provide an
alert that shows the sorted version of this list.
Binary search Use Input 1 to accept a comma-
separated list of items, and use Input 2 to take the
item being searched. Provide an alert that says
“yes” if the target is found and “no” if it isn’t
found. Note that this works exactly like sequen-
tial search on the outside; it’s the internal work
done by the program that is different.
Quicksort (numbers) Use Input 1 to accept a
comma-separated list of numbers. Provide an
alert that shows the sorted version of this list.
Note that this works exactly like insertion sort on
the outside; it’s the internal work done by the
program that is different.

Partial preview of the text

Download Conceptual Mechanics - Introduction to Computer Science | CMSI 182 and more Assignments Computer Science in PDF only on Docsity!

CMSI 182

I N T R O D U C T I O N T O C O M P U T E R S C I E N C E

Fall 2006

Assignment 1121

Having (presumably) assimilated the conceptual mechanics of the sequential search, binary search, insertion sort, and quicksort algorithms, as well as the general approaches for iteration and recursion, it’s time to try writing out iterative and recursive algorithms yourself, either in JavaScript or in pseudocode.

Not for Submission

As has been mentioned, we are currently on Chap- ter 5 of the Brookshear book.

For Submission

Implement the following algorithms. Use the JavaScript scratch page for the iteration algorithms, and use pseudocode for the recursive one.

Iteration

  • Exponent of a number^ — Use^ Input 1^ to accept a number, and use Input 2 to accept the power to which that number should be raised. Provide an alert that displays the calculated exponent. For example, if Input 1 holds “3” and Input 2 holds “4,” then the answer is 81 = 3^4. - Highest/lowest number finder^ — Use^ Input 1^ to ac- cept a comma-separated list of numbers. Pro- vide an alert that displays the highest and lowest numbers in that list.
  • Sequential^ search^ —^ Use^ Input^1 to^ accept^ a comma-separated list of items, and use Input 2 to take the item being searched. Provide an alert that says “yes” if the target is found and “no” if it isn’t found.

Recursion

  • Descendant counter (pseudocode)^ — Given a person and that person’s family tree, count all of his or her descendants, across all generations. Provide this one in pseudocode. For example: if John has 2 children, Sally and Jane, Sally has 4 children, and Jane has 1 child, then John has 7 descendants (Sally, Jane, and the 5 grandchildren). Assume that there is a getDi- rectDescendants(p) function that will provide the list of direct descendants for person p. If p has no direct descendants, then an empty list is returned.

Extra Credit

You will get extra credit if you also implement one of these algorithms in JavaScript, using the JavaScript scratch page:

  • Insertion sort (numbers)^ — Use^ Input 1^ to accept a comma-separated list of numbers. Provide an alert that shows the sorted version of this list.
  • Binary search^ — Use^ Input 1^ to accept a comma- separated list of items, and use Input 2 to take the item being searched. Provide an alert that says “yes” if the target is found and “no” if it isn’t found. Note that this works exactly like sequen- tial search on the outside; it’s the internal work done by the program that is different.
  • Quicksort (numbers)^ — Use^ Input 1^ to accept a comma-separated list of numbers. Provide an alert that shows the sorted version of this list. Note that this works exactly like insertion sort on the outside; it’s the internal work done by the program that is different.