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 the following hash search function to search a key in the hash table. If the key is found, the search function returns the char* value associated with the key and returns NULL otherwise. The value MAX ENTRIES is the number of buckets in the hash table. Your code should carefully handle all corner cases, should compile, and should not experience segmentation faults on any input. You can assume that the hash function is already provided in the library and has the following prototype as shown 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 first list contains elements at even positions in the original list. The second list contains elements at odd positions in the original list. Since you cannot return two pointers from a function, the function takes two additional arguments—pointers to the head pointers of the two lists–and returns the list pointers in 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 the lookup C function to look up a key in the binary search tree. The function returns 1 if the key is found and returns 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
4. (5 points) Write a C function to allocate a two-dimensional integer matrix with p rows and q columns.
Image of page 5
Image of page 6

You've reached the end of your free preview.

Want to read all 21 pages?

  • Spring '08
  • Chakraborty
  • Leal, Question Max Points Points

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture