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

02_2017_Spring_CS211_Final.pdf - Spring 2017 CS 211 Final...

This preview shows page 1 - 6 out of 21 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 of the 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 a C program that takes a pointer to a linked list and creates two lists. The firstlist contains elements at even positions in the original list. The second list contains elements at oddpositions in the original list. Since you cannot return two pointers from a function, the function takestwo additional arguments—pointers to the head pointers of the two lists–and returns the list pointersin them.struct node{void* data;struct node * next;};void two_lists(struct node* orig_list,struct node** list1_ptr,struct node** list2_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 there are 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

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture