项目作者: ritulsingh

项目描述 :
This repository for data structure (array, stacks, linked list) code in C language.
高级语言: C
项目地址: git://github.com/ritulsingh/DataStructreCode.git
创建时间: 2020-08-30T08:44:28Z
项目社区:https://github.com/ritulsingh/DataStructreCode

开源协议:

下载


DataStructreCode

This repository for data structure (array, stacks, linked list) code in C language.

Data Structure Operations Cheat Sheet

Note: For best case operations, the time complexities are O(1).



















































































































Data Structure NameAverage Case Time ComplexityWorst Case Time ComplexitySpace Complexity
Accessing nth elementSearchInsertionDeletionAccessing nth elementSearchInsertionDeletionWorst Case
ArraysO(1)O(n)O(n)O(n)O(1)O(n)O(n)O(n)O(n)
Singly Linked Listθ(n)θ(n)θ(1)θ(1)O(n)O(n)O(1)O(1)O(n)
StacksO(n)O(n)O(1)O(1)O(n)O(n)O(1)O(1)O(n)
QueuesO(n)O(n)O(1)O(1)O(n)O(n)O(1)O(1)O(n)
Binary TreesO(n)O(n)O(n)O(n)O(n)O(n)O(n)O(n)O(n)
Binary Search TreesO(logn)O(logn)O(logn)O(logn)O(n)O(n)O(n)O(n)O(n)
Balanced Binary Search TreesO(logn)O(logn)O(logn)O(logn)O(logn)O(logn)O(logn)O(logn)O(logn)
Hash TablesN/AO(1)O(1)O(1)N/AO(n)O(n)O(n)O(n)



## Sorting Algorithm Cheat Sheet



















































































































Storting Algorithm NameTime ComplexitySpace ComplexityIs Stable?Storting Class TypeRemarks
Best CaseAverage CaseWorst CaseWorst Case
Bubble SortO(n)O(n2)O(n2)O(1)YesComparisonNot a preferred sorting algorithm
Insertion SortO(n)O(n2)O(n2)O(1)YesComparisonIn the best case (already sorted), every insert requires constant time.
Selection SortO(n2)O(n2)O(n2)O(1)NoComparisonEven a perfectly sorted array requires scanning the entire array.
Merge SortO(nlogn)O(nlogn)O(nlogn)O(n)YesComparisonOn array, it requires O(n) space and on linked lists, it requires constant space.
Heap SortO(nlogn)O(nlogn)O(nlogn)O(1)NoComparisonBy using input array as storage for the heap, it is possible to achieve constant space.
Quick SortO(nlogn)O(nlogn)O(n2)O(logn)NoComparisonRandomly picking a pivot value can help avoid worst case scenarios such as a perfectly sorted array.
Tree SortO(nlogn)O(nlogn)O(n2)O(n)YesComparisonPerforming inorder traversal on the balanced binary search tree.
Counting SortO(n + k)O(n + k)O(n + k)O(k)YesLinearWhere k is the range of the non-negative key value.
Bucket SortO(n + k)O(n + k)O(n2)O(n)YesLinearBucket sort is stable, if the underlying sorting algorithm is stable.
Radix SortO(dn)O(dn)O(dn)O(d + n)YesLinearRadix sort is stable, if the underlying sorting algorithm is stable.

Linked List

  • Linked List can be defined as collection of objects called nodes that are randomly stored in the memory.
  • A node contains two fields i.e. data stored at that particular address and the pointer which contains the address of the next node in the memory.
  • The last node of the list contains pointer to the null.

    Uses of Linked List

  • The list is not required to be contiguously present in the memory. The node can reside any where in the memory and linked together to make a list. This achieves optimized utilization of space.
  • List size is limited to the memory size and doesn’t need to be declared in advance.
  • We can store values of primitive types or objects in the singly linked list.