C# Data Structures and Algorithms
Marcin Jamro
- 292 pagine
- English
- ePUB (disponibile sull'app)
- Disponibile su iOS e Android
C# Data Structures and Algorithms
Marcin Jamro
Informazioni sul libro
A complete guide on using data structures and algorithms to write sophisticated C# code
Key Features
- Master array, set and map with trees and graphs, among other fundamental data structures
- Delve into effective design and implementation techniques to meet your software requirements
- Explore illustrations to present data structures and algorithms, as well as their analysis in a clear, visual manner
Book Description
Data structures allow organizing data efficiently. They are critical to various problems and their suitable implementation can provide a complete solution that acts like reusable code. In this book, you will learn how to use various data structures while developing in the C# language as well as how to implement some of the most common algorithms used with such data structures.At the beginning, you will get to know arrays, lists, dictionaries, and sets together with real-world examples of your application. Then, you will learn how to create and use stacks and queues. In the following part of the book, the more complex data structures will be introduced, namely trees and graphs, together with some algorithms for searching the shortest path in a graph. We will also discuss how to organize the code in a manageable, consistent, and extendable way. By the end of the book, you will learn how to build components that are easy to understand, debug, and use in different applications.
What you will learn
- How to use arrays and lists to get better results in complex scenarios
- Implement algorithms like the Tower of Hanoi on stacks of C# objects
- Build enhanced applications by using hashtables, dictionaries and sets
- Make a positive impact on efficiency of applications with tree traversal
- Effectively find the shortest path in the graph
Who this book is for
This book is for developers who would like to learn the Data Structures and Algorithms in C#. Basic C# programming knowledge would be an added advantage.
]]>
Domande frequenti
Informazioni
Variants of Trees
- Basic trees
- Binary trees
- Binary search trees
- AVL trees
- Red-black trees
- Binary heaps
- Binomial heaps
- Fibonacci heaps
Basic trees
Implementation
Node
public class TreeNode<T> { public T Data { get; set; } public TreeNode<T> Parent { get; set; } public List<TreeNode<T>> Children { get; set; } public int GetHeight() { int height = 1; TreeNode<T> current = this; while (current.Parent != null) { height++; current = current.Parent; } return height; } }
Tree
public class Tree<T> { public TreeNode<T> Root { get; set; } }
Example – hierarchy of identifiers
Tree<int> tree = new Tree<int>(); tree.Root = new TreeNode<int>() { Data = 100 }; tree.Root.Children = new List<TreeNode<int>> { new TreeNode<int>() { Data = 50, Parent = tree.Root }, new TreeNode<int>() { Data = 1, Parent = tree.Root }, new TreeNode<int>() { Data = 150, Parent = tree.Root } }; tree.Root.Children[2].Children = new List<TreeNode<int>>() { new TreeNode<int>() { Data = 30, Parent = tree.Root.Children[2] } };
Example – company structure
public class Person { public int Id { get; set; } public string Name { get; set; } public string Role { get; set; } public Person() { } public Person(int id, string name, string role) { Id = id; Name = name; Role = role; } }
Tree<Person> company = new Tree<Person>(); company.Root = new TreeNode<Person>() { Data = new Person(100, "Marcin Jamro", "CEO"), Parent = null }; company.Root.Children = new List<TreeNode<Person>>() { new TreeNode<Person>() { Data = new Person(1, "John Smith", "Head of Development"), Parent = company.Root }, new TreeNode<Person>() { Data = new Person(50, "Mary Fox", "Head of Research"), Parent = company.Root }, new TreeNode<Person>() { Data = new Person(150, "Lily Smith", "Head of Sales"), Parent = company.Root } }; company.Root.Children[2].Children = new List<TreeNode<Person>>() { new TreeNode<Person>() {
Data = new Person(30, "Anthony Black", "Sales Specialist"),
Parent = company.Root.Children[2] } };