NYU POLY CS2134 HW 1a
NYU POLY CS2134 HW 1a
NYU POLY CS2134 HW 1a
Fall 2014
Due 11:59 p.m. Monday, September 8, 2014
September 2, 2014
Your rst assignment includes a programming portion and a written portion. The programming
portion should consist of a single le called hw01.cpp, and the written portion should consist of a
single le called hw01written in a standard format (.txt, .doc, .htm., or .pdf). Be sure to include
your name at the beginning of each le! You must hand in both les via MyPoly.
Programming Part:
1. (a) Write a function (or 3 seperate functions) to return the minimum item in a vector
containing:
i. chars
ii. ints
iii. strings
(b) Write a function (or 3 seperate functions) to return the maximum item in a vector
containing:
i. chars
ii. ints
iii. strings
2. Using the linked list class
class Node
{
public: // These member variables are made public to simplify your coding.
// Of course these member variables should be private!
chNode( char ch, Node * ptr = nullptr):data(ch),next(ptr){}
char data;
Node * next;
};
1
and a pointer to the class Node * nodePtr; write the code to perform the following:
create a linked list of three nodes containing the items B, D, E.
add a node containing A to the front of your linked list
print out the memory locations of A, B, C D, E and nodePtr (and hand in this
information with the written part).
delete the node containing A, (nodePtr now points the the nodes containing B, C
D, E )
3. For an array, int * intPtr = new int[5];, using only pointers (no array indexing) write
the code to perform the following:
insert items 2, 3,4, 5 into the rst three positions (positions 0,1,2,3).
add item 1 to the front of your array; (you need to move the other items)
Print out the memory locations of 1, 2, 3, 4, 5 and intPtr (and hand in this information
with the written part).
delete the array pointed to by intPtr
2
Written Part:
1. Write each of the following functions in Big-Oh notation:
(a) T(n) = 12n log(n) + 10n
0.5
log
3
(n) + 12
(b) T(n) = n log(n) + n log
2
(n) + 12n
(c) T(n) = 22 log(n
12
) + 12 log(4 n)
(d) T(n) = 1000 n log
5
(n) + 0.002n
3
+ 8n
2
(e) T(n) = (4n
2
+ 4 n) 11n
(f) T(n) = n log(n
12
) + 8n
2
(g) T(n) =
log(n)(12nlog(n)+n
2
)
n
(h) T(n) =
n
2
n
3