Algorithms and Data Structures - Assignment 2 | CS 303, Assignments of Computer Science

Material Type: Assignment; Class: Algorithms and Data Structures; Subject: Computer Science; University: University of Alabama - Birmingham; Term: Unknown 1989;

Typology: Assignments

Pre 2010

Uploaded on 04/12/2010

koofers-user-wj7
koofers-user-wj7 🇺🇸

5

(2)

10 documents

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CS 303 - Assignment 2
Written Homework:
1. (Exercise 4.5 in textbook) A letter means push and an asterisk means pop in the
sequence
E A S * Y * Q U E * * * S T * * * I O * N * * *.
Give the sequence of values returned by the pop operations.
2. (Exercise 4.6 in textbook) Using the conventions of question 2, give a way to
insert asterisks in the sequence E A S Y so that the sequence values returned
by the pop operations is (i) E A S Y ; (ii) Y S A E ; (iii) A S Y E ; (iv) A Y E S ; or, in
each instance, prove that no such sequence exists.
3. Give the preorder-, inorder- and postorder-traversals of the following tree.
4. Show how each of the algorithms sort the sample the numbers {9,4,5,3,1,8}.
(a) Insertion Sort; (b) Selection Sort; (c) Bubble Sort. Show each step during the
process.
5. What is the time complexity (O()) of each of above algorithms?
pf3

Partial preview of the text

Download Algorithms and Data Structures - Assignment 2 | CS 303 and more Assignments Computer Science in PDF only on Docsity!

CS 303 - Assignment 2

Written Homework:

  1. (Exercise 4.5 in textbook) A letter means push and an asterisk means pop in the sequence E A S * Y * Q U E * * * S T * * * I O * N * * *. Give the sequence of values returned by the pop operations.
  2. (Exercise 4.6 in textbook) Using the conventions of question 2, give a way to insert asterisks in the sequence E A S Y so that the sequence values returned by the pop operations is (i) E A S Y ; (ii) Y S A E ; (iii) A S Y E ; (iv) A Y E S ; or, in each instance, prove that no such sequence exists.
  3. Give the preorder-, inorder- and postorder-traversals of the following tree.
  4. Show how each of the algorithms sort the sample the numbers {9,4,5,3,1,8}. (a) Insertion Sort; (b) Selection Sort; (c) Bubble Sort. Show each step during the process.
  5. What is the time complexity (O()) of each of above algorithms?

Programming Problem:

Warmup:

Create a class named Rectangle with properties: length, breadth and functions: GetHeight(), GetLength, SetHeight(value), SetLength(value), GetArea(), GetPerimeter(). Create another class where an object of type Rectangle is instantiated. Set height and length and print the values: height, length, area and perimeter calling appropriate functions.

Assignment:

1. Write a program to implement Stack/Queue with the linked list data structure

that you developed in your last assignment. Stack has two functions: Push(value) which puts a value to the top of stack , Pop() removes and returns the value in the top of stack. Queue has two functions: EnQueue(value) which puts a value to the end of queue , Pop() removes and returns the value from the beginning of the queue. a) Create a class MyStack with respective functions from above and required properties for Stack(you will need a linked list to store data). Create another class that creates object of MyStack. Use provided class for reading numbers from a file and store the values read into stack. Display the returned values as you pop out all the elements from the stack in a loop. b) Repeat above for Queue.

2. A binary tree is a datastructure which has nodes comprising of

  1. value, 2. right pointer, 3. left pointer. The right and left pointers are either null or they point to another nodes. A Binary Search Tree (BST) has numbers stored in each node in such a way that each element to the left of a node are less than or equal to (<=) the node's value and all the nodes to the right are greater(>). Write a program to construct a binary tree and traverse it in orders: preorder, inorder, postorder. The value of each node should be displayed while it is being traversed. The traversal is done recursively. Functions to be implemented by tree: Insert(int value) Traverse(Node n) Functions to be implemented by Node: Visit()