Code Monkey home page Code Monkey logo

sparse_array's Introduction

Sparse_Array

This project aims to implement the sparse array in C.

Sparse array is defined as a data structure that is sparsely filled. We want to be able to access the array via indices. And the complexity of indexing should be constant.

Design:
Trie is used. Assume the index is by a unsigned int array (32-bit). Therein, each 8 bits are used for selecting the nodes in next level. e.g. bits 0-7 are used to select among the 256 children of root, bits 8-15 are used to select among the children of next level.

The data structure is designed as follow:

struct Trie{
  union Content {
    struct Trie **children_;
    int value_;
  }content_;
};

There will be 5 functions designed (pseudocode) as follows:
construct_trie_( ) : constructor function
=== create the root node of the trie and initialized the pointers to NULL.

destruct_trie_( struct Trie * ) : destruct all dynamically created variables
=== post order traversal and free the dynamically allocated memory.

insert_( struct Trie *, index, value ) : insert or update the value at the provided index
=== check the passed in parameters
=== check from the root (level 0) to the corresponding leaf. if any node is not
=== created, create it (malloc). if the node has no children, create 256 children
=== and assign the pointer to the pointer (trie ** children).

get_( struct Trie *, index ) : return the value at the provided index
=== check the exsitance of element, if existed, return the value, otherwise, return -1

iterate( struct Trie * ) : iterate through the sparse array and print the elements

============

sparse_array's People

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.