Skip to content

vikhyath/c-runs

Repository files navigation

c-runs

c exercises

  • interpolation-search:
    O(log(log(n))), does better than binary search if the elements in the array are uniformly distributed, else O(n) worst than binary search.

  • n-way merge sort:
    Program to do to n-way merge, where n is the SIZE of n*n array. Emulating n-way merge from file through arrays, where each array row corresponds to a sorted file
    O(n^2 log(n)) run time since min-heap is used, else O(n^3) run time.
    TODO: Fix code to check previous columns are not exhausted while removing from array.

    1. Get sizeof(min-heap) elements from n*n array
    2. Put in min heap, remove the root element O(log n)
    3. Fill min heap with a new element from array O(#elements) = O(n^2)
    4. Do steps 2-3 till n*n array is exhausted
    5. Now remove the root from min heap as many times as there are elements left in heap
  • Trie: add, find and delete O(m), where m is the size of the word being added (theory from http://www.cs.bu.edu/teaching/c/tree/trie/)

    1. Advantages: BST takes O(mlogn) to add, find and delete words.Because there are logn keys to check and each key has to do m comparisions. Trie is also better than hash because a bad hash collision resolution method with need O(n) comparisions to lookup a key, rather O(mn) if the key is a word and the hash bucket has n keys. Also, we do not need an explicit hash function to resolve buckets and no need of rebuilding hash table if it gets full. We also need less space with tries. Longest prefix matching is easily possible with tries.
    2. Disadvantages: Tries can be slower in some cases when compared to hash tables for lookups if the data is directly accessed from the disk where the random access time is high.
  • integer-array-sum: You have two integer arrays. Treat these arrays as if they were big numbers, with one digit in each slot. Perform addition on these two arrays and store the results in a new array. Ref: http://www.careercup.com/question?id=6330205329162240

===== Starting to use makefiles hereon. =====

  • Graph: simple graph in C (theory from http://www.cs.bu.edu/teaching/c/graph/linked/), supported operations:
    1. add_vertex()
    2. add_edge()
    3. graph_checkpath(vertex, vertex) # using DFS for now
    4. graph_bfs(vertex) # Using BFS - shortest path to all nodes from a given node
    5. graph_is_euler(vertex) # checks if a given graph is euler/semi/none using DFS and connected components theory. Currenly only for undirected graphs.

About

c exercises and misc challenges

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published