Posts

Showing posts with the label Data Structures

Graph Data Structure for Powershell

Image
A Graph is a non-linear data structure consisting of nodes and edges. The nodes are sometimes also referred to as vertices and the edges are lines or arcs that connect any two nodes in the graph. Graphs are used to solve many real-life problems such as representing networks - like paths in a city or telephone network or circuit network. Graphs are also used in social networks like Linkedin and Facebook.   There are many times that I've come across problems in the IT industry that graphs could help solve. To demonstrate the use of graphs to process connections between items, we'll use Exchange server mailboxes as nodes and the permissions between them as edges. The mailboxes variable shown below is loaded with mailbox info for five users. The majority of the objects' properties have been removed to simplify the demo: We'll start with importing the DataStructures module that contains the Graph type and then create a graph object: There are no nodes in the graph so it is e...

Data Structures in Powershell

Image
A good algorithm is not always the solution to a given problem. In most cases, a mechanism to save the data used by the algorithm is required, in order not only to organise the data but also optimise its execution. Such mechanisms are called Data Structures and you can think of them as small databases. Data Structures not only hold data, but also expose methods to access and update it. My DataStructures module contains the most frequently used data structures, implemented for Powershell objects in C#. At the time this post is written, the module contains the stack and queue structures, but more are on the way. Stack The idea behind the stack data structure is to save objects in order to be processed later in the execution of an algorithm. The below figure shows the way stacks work: As we insert items in the stack, the items already in it are pushed to the bottom. When removing an item, the item to be removed is the most recent one, hence the alternate naming LIFO - Last In First Out...