Coder Social home page Coder Social logo

assignment_trees_graphs's Introduction

assignment_graphs_trees

Rise over run.

by Tim Scott

A Data Structures and Algorithms Ruby Assignment from the Viking Code School using Trees and Graphs

  1. What are the advantages and disadvantages of using an Adjacency Matrix vs an Adjacency List relative to size and speed of common operations?

The adjacency matrix has a bunch of blank/wasteful space but is very easy to index and access what you want. It is also easy to insert and delete data.

  1. What would the Big O be of inserting a new EDGE to: An Edge List? O(n), you have to build a new array to add an element

    An Adjacency Matrix? O(n), you have to traverse the matrix and add an element to each row, as well as a new row

    [0,0,0,1] [0,0,0,2] [0,0,0,3] [4,5,6,7]

    An Adjacency List? O(n) (best case is O(1)) You have to index the linked list, and then traverse it to add an item to the end

  2. What would the Big O be of inserting a new VERTEX to: An Edge List? O(n) You have to build a new array to add an element

An Adjacency Matrix?  O(1) You have to index the array and change the value (1 step)


An Adjacency List? O(n)  You have to overwrite the array to add an element
  1. What would the Big O be of REMOVING a vertex or edge from: An Edge List? O(n). Have to rewrite array in memory An Adjacency Matrix? O(n). Have to remove whole column and row and rewrite the array An Adjacency List? O(n) worst case, O(1) best case
5. How would you find all the nodes connected to a particular vertex in:
    An Edge List? O(n). You have to traverse the entire list and find any edges that originate or depart from particular vertex

    An Adjacency Matrix? O(n) Have to index and then traverse entire row. Also have to do the same for columns.

    An Adjacency List? O(1) just get the list at the corresponding index

assignment_trees_graphs's People

Contributors

eriktrautman avatar ttscott2 avatar bideowego avatar

Watchers

James Cloos 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.