sample-final.pdf - Spring 2017 CS 211 Final Prof Santosh Nagarakatte May 9th 2017 8am-11am Full Name Here RUID NetID Instructions No electronic devices

sample-final.pdf - Spring 2017 CS 211 Final Prof Santosh...

This preview shows page 1 - 6 out of 20 pages.

Spring 2017: CS 211: Final Prof. Santosh Nagarakatte May 9th 2017: 8am-11am Full Name Here: RUID: NetID: Instructions: No electronic devices allowed. Show your ID to the TA before you submit your exam. Regular Credit: 100 points Question Max Points Points 1 20 2 20 3 20 4 20 5 20 Extra Credit: 30 points (7.5% towards the final grade) Question Max Points Points 1 15 2 15 1
Image of page 1
Problem 1: C Programming (20 points) 1. (5 points) You are implementing a hash table using chaining with linked lists where each node is ofthe following type.struct node{char* key;char* value;struct node * next;};Given that the hash table is implemented as an array of pointers to hash table nodes, implement thefollowinghashsearchfunction to search a key in the hash table.If the key is found, the searchfunction returns thechar*value associated with the key and returnsNULLotherwise.The valueMAXENTRIES is the number of buckets in the hash table. Your code should carefully handle allcorner cases, should compile, and should not experience segmentation faults on any input. You canassume that the hash function is already provided in the library and has the following prototype asshown below:int hash_function(char*);struct node * hash_table[MAX_ENTRIES];char* hash_search(char* key){ 2
Image of page 2
2. (5 points) Write arecursiveprogram namedreverse_listto reverse a singly linked list pointed bypointerlist_ptr. The function should return the pointer to the head of the reversed list.struct node{void* data;struct node * next;};struct node* reverse_list(struct node * list_ptr) { 3
Image of page 3
3. (5 points) You are given a binary search tree with each node having a left and a right child. If thereare no children in the left or right branch, the respective pointers are NULL. Complete thelookupC function to look up a key in the binary search tree. The function returns 1 if the key is found andreturns 0 if the key is not found./* structure for the binary search tree */struct node{int value;struct node* left;struct node* right;};/* initially curr points to the root of the tree */int lookup(struct node* root, int key){ 4
Image of page 4
Image of page 5
Image of page 6

You've reached the end of your free preview.

Want to read all 20 pages?

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture