Category: Data Structure and Algorithms

Data Structure and Algorithms

Struct/Record Examples in C Programming Language

Print an Adjacency List Graph

Build an Adjacency List Graph from Node Labels in a File

Nodes: Vertices and Edges. Nodes for them

define MaxWordSize 100

Build a Number Hash in C

Create a Hash Table to store numbers. Also, search numbers in that Hash Table. Write Code in C define _CRT_SECURE_NO_WARNINGS include include include define MaxNumbers 50 // to divide with define N 100 define Empty 0 define STORAGESIZE 100 int hashTable[STORAGESIZE + 1]; //initialize hash tablevoid initializeHashTable() { } //find a number and return found/not-foundint …

Continue reading

Build a Word Hash

Store Words in a Hash Table. Also, search a word in that Hash Table define _CRT_SECURE_NO_WARNINGS include include include //#define MaxNumbers 100 define MaxWordLen 50 define Empty 0 define STORAGESIZE 15 // to divide with define N 15 char hashTable[STORAGESIZE][MaxWordLen]; //initialize hash tablevoid initializeHashTable() {for (int counter = 0; counter < STORAGESIZE; counter++) {strcpy(hashTable[counter], “”);}} …

Continue reading

Input: Tree Traversal Data Output: Build the Tree

•From In-order Output to Build the Tree •Take In-order Traversal Output Data •And Build the Tree •Take the middle (N) or so as the root •Keep going/taking alternate left (nodeLabels) (K D) from there •Make those also roots/parents (left sub tree) •The last may be at the last left in this flow •Then from the …

Continue reading

Input: Post order Tree Traversal data, Output: Tree

• Last one (E) becomes the root • Some immediate (backward) right ones ones (L A T) up until middle (you can choose)  also becomes parents (downward right side parent) • – Then put some immediate ones (backward) ( N F ) as left  children to come to root Then take alternate (K P) to …

Continue reading

From Pre-order Tree Traversal Output to Build the Tree

From Pre-order Tree Traversal Output to Build the TreeFirst one becomes the root such as NSome immediate ones (D G) also becomes parents up until middle (you can choose) – left sub tree parens Then put some immediate ones (K P) as right children (in left subtree) to come to root Then take alternate (E …

Continue reading

Build the Tree from Tree Traversal Output

From In-order Output to Build the Tree •Take In-order Traversal Output Data •And Build the Tree •Take the middle (N) or so as the root •Keep going/taking alternate left (nodeLabels) (K D) from there •Make those also roots/parents (left sub tree) •The last may be at the last left in this flow •Then from the …

Continue reading