# 1(a) show, using the definition of the big oh, that the function f

Document Sample

```					CHU HAI COLLEGE Department of Computer Science BSc Degree in Computer Science CSC120 Data Structure Assignment 1 –Introduction to ADT & Performance Analysis

1(a) Show, using the definition of the big-Oh, that the function f(n) = 0.5n3 + 25n - 2 is O(n3). (b) Characterize, using the big-Oh notation, the worst-case running time of the following algorithm: (only count the assignment statements) Let A be a given array of n integers. for i ← 0 to (n*n)-1 do for j ← 0 to (2 * log(n)) do Let A[i mod n] ← A[i mod n] + j end for end for 2(a) Suppose a program contains the following statements: int num, *ptr;

Write C statements to print each of the following: i. ii. iii. iv. (b) the address of num; the content of num; the address of ptr; the integer value to which the ptr points.

Assume we declare an array as follows: short int array[] = {3, 1997, 2000, 1776, 12888, 1, 9999} If array is stored at memory location 1000, what is the value of each of the expression below: i. ii. iii. iv. v. array[3] &array[2] array *array *(array + 2)

CSC120 – Assignment P 1

3(a)

Assuming the queue is initially empty. The function enqueue() adds an item to the rear of the queue whereas the function dequeue() removes an item from the front of the queue. enqueue(46); enqueue(14); enqueue(28); dequeue(); dequeue(); enqueue(69); enqueue(27); enqueue(99); dequeue(); enqueue(24); enqueue(85); enqueue(16); dequeue();

(a) (b)

Show the contents of the queue in each step. What is final content of the queue? Is it ALWAYS correct to intermix the dequeue()operations with the enqueue() operations as above? If no, under what situations there will be errors? Consider the following declaration: struct Node { int key; struct Node * Next; }; struct Node *A, *P, *Q, Temp; Assume A is pointing to the first node of a singly linked list with the declaration above. For example, A can be pointing to a linked list:

4.

(a) (b) (c) (d)

Write a C function to return the sum of all the keys in the linked list pointed by A. Assume another pointer P is pointing to the node that contains 32. Write the C statements that allocate a new node Q. Put the number 25 into the new node and add it to the list after 32 but before 14. Re-draw the figure to reflect the insertion of the new node. Write C statements to delete the node that is pointed by A. The deleted node must be returned to the heap memory. Is it easier to insert a new node before or after a specified node in a singly linked list? Give your reasons to support your argument.

CSC120 – Assignment P 2

5.

.Suppose you have a stack S, which contains two elements in the following order: <3 6> where 6 is the top element and 3 is the bottom element. Note that the last number in the sequence is the top element in the stack.

(a) Write down the elements in the stack S for each step. What is the final content in the stack? top(S); pop(S); push(S,8); push(S,top(S)); push(S,9); push(S,pop(S)); (b) (c) Describe the algorithm how to convert an infix expression to a postfix expression. Convert the following infix expression to postfix expression and evaluate the answer step by step: 4*3/5-8-(6+2)^7 - END -

CSC120 – Assignment P 3

```
DOCUMENT INFO
Shared By:
Categories:
Stats:
 views: 50 posted: 12/20/2009 language: English pages: 3
Description: 1(a) show, using the definition of the big oh, that the function f
How are you planning on using Docstoc?