Reader small image

You're reading from  Learn Data Structures and Algorithms with Golang

Product typeBook
Published inMar 2019
Reading LevelIntermediate
PublisherPackt
ISBN-139781789618501
Edition1st Edition
Languages
Right arrow
Author (1)
Bhagvan Kommadi
Bhagvan Kommadi
author image
Bhagvan Kommadi

Bhagvan Kommadi, Founder, Architect Corner has around 18 years experience in the industry ranging from large-scale enterprise development to incubating software product startups. He has done Masters in Industrial Systems Engineering at Georgia Institute of Technology (1997) and Bachelors in Aerospace Engineering from Indian Institute of Technology, Madras (1993). He is currently working as CTO of Crystal Delta Solutions. He is the member of IFX forum and an Individual member of Oracle JCP. He has developed Go language based blockchain solutions in retail, education, banking, and financial services sectors. These blockchain solutions were based on Chain Core (Go language based), Ethereum and Hyperledger blockchain platforms. He has experience in building high transactional applications using Java, C, C++, C#, Python, Go, Ruby and JavaScript frameworks. He has reviewed books such as Beyond Software Architecture-Creating and sustaining winning solutions by Luke Hohmann and Algorithms of the intelligent Web by Dr. Haralambos (Babis) Marmanis.
Read more about Bhagvan Kommadi

Right arrow

Network and Sparse Matrix Representation

A sparse matrix is a matrix in which most of the values are zero. The ratio of zero values to non-zero values is known as the sparsity. An estimation of a matrix's sparsity can be helpful when creating hypotheses about the availability of networks. Extensive big sparse matrices are commonly used in machine learning and natural language parsing. It is computationally costly to work with them. Recommendation engines use them for representing products inside a catalog. Computer vision uses sparse matrices and network data structures when working with pictures that contain sections with dark pixels. Network and sparse matrix data structures are also used in social graphs and map layouts. In this chapter, we will cover the following topics:

  • Network representations using graphs:
    • Social network representation
    • Map layouts
    • Knowledge graphs...

Technical requirements

Network representation using graphs

A graph is a representation of a set of objects that's connected by links. The links connect vertices, which are points. The basic operations on a graph are the addition and removal of links and vertices. These are some different types of graphs:

  • Directed graph
  • Non-directed graph
  • Connected graph
  • Non-connected graph
  • Simple graph
  • Multi-graph

An adjacency list consists of adjacent vertices of a graph that have objects or records. An adjacency matrix consists of source and destination vertices. An incidence matrix is a two-dimensional Boolean matrix. The matrix has rows of vertices and columns that represent the links (edges).

Network representation using a graph is shown in the following code. A social graph consists of an array of links:

///main package has examples shown
// in Go Data Structures and algorithms book
package main

// importing...

Sparse matrix representation using a list of lists

A sparse matrix is a two-dimensional list of m rows and n columns. The shape of a matrix is m x n if it consists of m rows and n columns. Sparse matrices are used for solving large-scale problems that do not require dense matrices. For example, partial differential equations are solved by using the finite element method (FEM). Tuples of a sparse matrix are non-zero elements of the matrix.

In the following code, a sparse matrix is modeled as a list of lists. A sparse matrix consists of cells that are a list of lists. Each cell has properties such as Row, Column, and Value:

///main package has examples shown
// in Go Data Structures and algorithms book
package main

// importing fmt package
import (
"fmt"
)

//List of List
type LOL struct {
Row int
Column int
Value float64
}

The next section talks about the SparseMatrix class...

Summary

This chapter covered how to present networks and sparse matrices using graphs and a list of lists, respectively. Social network representation, map layouts, and knowledge graphs were discussed in detail with code examples. The different sparse matrix methods were also implemented with the appropriate code.

In the next chapter, algorithms such as garbage collection, cache management, and space allocation will be presented with code examples and an efficiency analysis.

Questions

  • What data structure is used to represent a set of linked objects?
  • What is a two-dimensional matrix with Boolean values called?
  • Give a code example for a network representation using a graph.
  • Which metrics can be calculated from a social graph?
  • What is a cartographic design?
  • Give an example of a knowledge graph and define the class, slots, and facets.
  • What are the applications of sparse matrices?
  • Define a list of lists and write a code sample.
  • What is a map layout?
  • What different operations can be performed using graphs?

Further reading

The following books are recommended if you want to know more about graphs and list of lists:

  • Design Patterns, by Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides
  • Introduction to Algorithms – Third Edition, by Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, and Clifford Stein
  • Data structures and Algorithms: An Easy Introduction, by Rudolph Russell
lock icon
The rest of the chapter is locked
You have been reading a chapter from
Learn Data Structures and Algorithms with Golang
Published in: Mar 2019Publisher: PacktISBN-13: 9781789618501
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Bhagvan Kommadi

Bhagvan Kommadi, Founder, Architect Corner has around 18 years experience in the industry ranging from large-scale enterprise development to incubating software product startups. He has done Masters in Industrial Systems Engineering at Georgia Institute of Technology (1997) and Bachelors in Aerospace Engineering from Indian Institute of Technology, Madras (1993). He is currently working as CTO of Crystal Delta Solutions. He is the member of IFX forum and an Individual member of Oracle JCP. He has developed Go language based blockchain solutions in retail, education, banking, and financial services sectors. These blockchain solutions were based on Chain Core (Go language based), Ethereum and Hyperledger blockchain platforms. He has experience in building high transactional applications using Java, C, C++, C#, Python, Go, Ruby and JavaScript frameworks. He has reviewed books such as Beyond Software Architecture-Creating and sustaining winning solutions by Luke Hohmann and Algorithms of the intelligent Web by Dr. Haralambos (Babis) Marmanis.
Read more about Bhagvan Kommadi