MostafaTwfiq/C-DataStructures-And-Algorithms

Repository files navigation

  • Generic
  • Unit tested
  • Terminating errors
  • Documented

General overview:

library C filestotal lines of codetotal lines of comments
implemented data structuresimplemented algorithms

  1. Red Black Tree

    • Initialization
    • Insertion
    • Deletion
    • Searching
    • Contains
    • Print
    • Pre order traversal
    • In order traversal
    • Post order traversal
    • Get Size
    • Is Empty
    • Transform to array
    • Clear
    • Destroy
  2. AVL Tree

    • Initialization
    • Insertion
    • Deletion
    • Searching
    • Contains
    • Pre order traversal
    • In order traversal
    • Post order traversal
    • Breadth first traversal
    • Get Size
    • Is Empty
    • Transform to array
    • Clear
    • Destroy
  3. Binary Tree

    • Initialization
    • Insertion
    • Deletion
    • Searching
    • Contains
    • Pre order traversal
    • In order traversal
    • Post order traversal
    • Get Size
    • Is Empty
    • Transform to array
    • Clear
    • Destroy
  4. Splay Tree

    • Initialization
    • Insertion
    • Deletion
    • Searching
    • Contains
    • Get Size
    • Is Empty
    • Transform to array
    • Clear
    • Destroy
  5. Binary Heap

    • Initialization
    • Insertion
    • Deletion
    • Searching
    • Contains
    • Get Size
    • Is Empty
    • Transform to array
    • Clear
    • Destroy
  6. Trie

    • Initialization
    • Add word
    • Remove Word
    • Contains Word
    • Auto completion
    • Generate suggestions
    • Print words
    • Clear
    • Destroy
  1. Directed Graph

    • Initialization
    • Add node
    • remove node
    • add edge
    • remove edge
    • Contains node
    • Contains edge
    • Get size
    • Is empty
    • Print
    • Depth first traversal
    • Breadth first traversal
    • Topological sort
    • Check if node is a part of cycle
    • Graph Contains Cycles
    • Clear
    • Destroy
  2. Undirected Graph

    • Initialization
    • Add node
    • remove node
    • add edge
    • remove edge
    • Contains node
    • Contains edge
    • Get edge weight
    • Get size
    • Is empty
    • Print
    • Shortest distance (Dijkstra's algorithm)
    • Shortest path (Dijkstra's algorithm)
    • Minimum spanning graph (Prim's algorithm)
    • Check if node is a part of cycle
    • Graph Contains Cycles
    • Clear
    • Destroy
  1. Hashmap

  2. Linked list hashmap

    • Initialization
    • Insertion
    • Deletion
    • Search for value
    • Search for key
    • Contains
    • Transform to value array
    • Transform to entry array
    • Get size
    • Is empty
    • Clear
    • Destroy
  3. Hashset

    • Initialization
    • Insertion
    • Deletion
    • Search
    • Contains
    • Transform to array
    • Get size
    • Is empty
    • Clear
    • Destroy
  1. String
    • Initialization
    • Append character
    • Add character at index
    • Update character
    • Remove character
    • Append char array or string
    • Change string by another char array or string
    • Get character index
    • Get character at index
    • Is sub string of another char array or string
    • Convert to char array
    • Convert to char array between specific range
    • Is equal to char array or to string
    • Compare with char array or with string
    • Get length
    • Trim, trim start, and trim end
    • Custom trim, trim start, and trim end
    • Scan input
    • Print
    • Split
    • Clear
    • Destroy
  1. Vector

  2. Array list

    • Initialization
    • Insertion
    • Deletion
    • Contains
    • Get
    • Get index and get last index
    • Transform to array and sub array
    • Sort
    • Get length
    • Is empty
    • Print
    • Clear
    • Destroy
  3. Set

    • Initialization
    • Insertion
    • Deletion
    • Contains
    • Get
    • Get index
    • Transform to array
    • Get length
    • Is empty
    • Clear
    • Destroy
  4. Linked list

  5. Doubly linked list

    • Initialization
    • Insertion
    • Deletion
    • Get
    • Get index
    • Get item
    • Get at index
    • Get first and last
    • Contains
    • Transform to array
    • Get length
    • Is empty
    • Print
    • Clear
    • Destroy
  1. Matrix

    • Initialization
    • Insertion
    • Deletion
    • Get
    • Get index
    • Contains
    • Add row at last and at index
    • Add column at last and at index
    • Remove row at index
    • Remove column at index
    • Get number of rows
    • Get number of columns
    • Get number of items
    • Is empty
    • Transform to array
    • Print
    • Clear
    • Destroy
  1. Pair

    • Initialization
    • Get first and second
    • Set first and second
    • Set first and second without freeing the old elements
    • Swap elements
    • Destroy
  1. Stack

  2. Doubly linked list stack

    • Initialization
    • Push
    • Pop
    • Peek
    • Contains
    • Is equal to another stack
    • Transform to array
    • Get length
    • Is empty
    • Clear
    • Destroy
  1. Queue

  2. Linked list queue

  3. Stack queue

  4. Priority queue

  5. Priority queue implemnted using binary heap

    • Initialization
    • Enqueue
    • Dequeue
    • Peek
    • Get length
    • Is empty
    • Transform to array
    • Clear
    • Destroy
  1. Deque

  2. Doubly linked list deque

    • Initialization
    • Insert front and end
    • Get front and end
    • Peek front and end
    • Get length
    • Is Empty
    • Transform to array
    • Clear
    • Destroy
FunctionComplexityComments
reverse arrayO (n)
get most frequent value AO (n ^ 2)this function will use a resizable array to store the repeated values
get most frequent value HO (n)this function will use a hash map to store the repeated values
print arrayO (n)this function will need a helper printing function
resize arrayO (n)
array resize and copyO (n)this function will allocate a new array with the new length and then it will copy the values in the original array into the new one
array resize and copy of rangeO (k) and k is the length of the copying rangethis function will allocate a new array with the new length and then it will copy the values between the provided into the new array
array copyO (n)this function will allocate a new array then it will copy the values in the original array into the new one
array copy of rangeO (k) and k is the length of the copying rangethis function will allocate a new array then it will copy the values between the provided range into the new array
fill arrayO (n)
fill array in rangeO (k) and k is the length of the range
compare arraysO (n)
compare arrays in rangeO (k) and k is the length of the range
array mismatchO (n)
array mismatch in rangeO (k) and k is the length of the range
array anagrams SO (n log(n))this function will sort the array first to determine if they are equals
array anagrams HO (n)this function will use a hash map the compare the arrays
array remove duplicates AO (n ^ 3)this function will use a resizable array to detect the duplicates
array remove duplicates HO (n ^ 2)this function will use a hash map to detect the duplicates
array count valuesO (n)
is sub arrayO (n ^ 2)
array get indexO (n)
array containsO (n)
array remove at indexO (n)
array sortO (n log(n))this function will use quick sort algorithm to sort the array, note that quick sort complexity can be O (n ^ 2)
array get firstO (n)
array get lastO (n)
array get allO (n)
array binary searchO (log(n))
array is palindromeO (n)
array is rotation of an arrayO (n)
array update elementO (1)
array addO (n)
array add allO (n)
array swap two indicesO (1)
FunctionComplexityComments
is sub stringO (n ^ 2)
reverse wordsO (n)
custom trim startO (n ^ 2)
trim startO (n ^ 2)
custom trim endO (n)
trim endO (n)
custom trimO (n ^ 2)
trimO (n ^ 2)
containsO (n)
remove characterO (n)
is integerO (n)
is floating pointO (n)
sum characters ASCIIO (n)
hash char arrayO (n)this function actually will return the sum the the characters ASCII
generate char arrayO (n)this function will allocate a new char array then it will copy the original char array into the new one
generate char pointerO (1)this function will generate a char pointer to a character
is alphabet CO (1)this function will take a character value then it will check if it's an alphabet character
is alphabetO (1)this function will take a character pointer then it will check if it's an alphabet character
comparison function PO (1)this function will take two character pointers then it will compare there ASCII values
comparison functionO (1)this function will take two character value then it will compare there ASCII values
split SO (n)this function will split the char array into strings vector
split CO (n)this function will split the char array into char arrays vector
most repeated characterO (n)this function will use a hash map
FunctionComplexityComments
binary searchO (log(n))the log is to base 2
ternary searchO (log(n))the log is to base 3
linear searchO (n)
jump searchO (sqrt(n))
exponential searchO (log(i)) and i represents the length of searching area )
FunctionComplexityComments
bubble sortO (n ^ 2)in best case the complexity could be O ( n )
selection sortO (n ^ 2)
insertion sortO (n ^ 2)in best case the complexity could be O ( n )
merge sortO (n log(n))there are two implementations first one with space complexity O ( n ) and worst case time complexity O ( n log(n) ), and the another one with space complexity O ( 1 ) and worst case time complexity O ( n ^ 2 )
quick sortO (n log(n))in the worst case the complexity could be O (n ^ 2)
heap sortO (n log(n))
counting sort AO (n)this type of sorting works only on unsigned integers, note this function will use an array to count the values so it will allocate an extra memory
counting sort HO (n)this type of sorting works only on unsigned integers, note this function will use a hashmap so it will use less memory that the array implementation
  • Get number of digits
  • Transform to char array
  • Max int
  • Min int
  • Compare integers
  • Compare integers reverse
  • Compare integers pointers
  • Compare integers pointers reverse
  • Generate integer pointer from another integer pointer
  • Generate integer pointer from an integer value
  • Integer hash function
  • Sum two integers
  • Sum array of integers
  1. Text File Loader

    • Initialization
    • Read file as string or as char array
    • Read file lines
    • Read file using a delimiter
    • Count lines
    • Read a specific line as a string or a char array
    • Write a string or a char array
    • Append a string or a char array at the end of the file
    • Append a string or a char array at the end of a specific line
    • Add a string or a char array at a specific line index
    • Update a specific line using a string or a char array
    • Remove a specific line
    • Change file
    • Clear the text file
    • Destroy
  2. Input Scanner

    You should pass stdin file to the function to scan the input.

    • Scan String
    • Scan char array
    • Scan character
    • Scan integer
    • Scan long
    • Scan long long
    • Scan short
    • Scan double
    • Scan float

The errors codes generated by summing the words ASCII values of the characters and multiply every character value by it's ( index + 1 ).
The first four error code numbers are the sum of the "DATA_STRUCTURE" characters,
and the rest of the error code is the sum of the error enum.
ex: INVALID_ARG is 4987.

ErrorError codeMessage
FAILED_ALLOCATION-833811484"The %s allocation in %s failed."
FAILED_REALLOCATION-833814245"The %s reallocation in %s failed."
FAILED_COPY-83385167"Copying %s in %s failed."
INVALID_ARG-83384987"The passed arg %s in %s is invalid."
NULL_POINTER-83386157"The %s pointer in %s is NULL."
OUT_OF_RANGE-83385991"The passed index is out of the %s range."
EMPTY_DATA_STRUCTURE-833816740"The passed %s pointer is empty."
SOMETHING_WENT_WRONG-833816834"Can't %s in %s."