Wednesday, 28 June 2023

Types of Trees in C language

Type of Trees in C

A subtree of a tree T is a tree consisting or include of a node in T and its entire issue or descendant in T. (This is different from the set or formal definition of subtree used in graph hypothesis or theory.) The subtree corresponding or keep in touch to the root intersection or node is the entire tree; the subtree corresponding or keep in touch to any other intersection or node is called a proper subtree (in likeness or analogy to the term true or proper subset).

Trees in C language, C Language, C programming
Types of Trees in C Image-1

A balanced tree is one where all of the flag or leaves of the tree are within one sheet or layer of one of each other.

A complete tree is a type of steady or balanced tree, except that it has one more extra or additional constraint or limitation. In a balanced tree, all flag or leaves are of depth n or n+1. In a absolute or complete tree, all of the flag or leaves of depth n+1 are further to the left than the flag or leaves of depth n. Moreover or furthermore, in a complete tree, all branch intersection or nodes (except those at depth n) must have the maximum or largest number of children.

A perfect tree is even more particular or specific. It requires that all of the flag or leaves be of the same depth or drop and that every divide or branching node has the maximum or largest number of children.

A binary tree is a tree data shape or structure in which each intersection or node has at most two children. Typically the first intersection or node is known as the parent and the child intersection or nodes are called left and right. In type theory, a binary tree with intersection or nodes of type A is defined express or inductively as TA=ua. 1+Axaxa. Binary trees are often or commonly used to implement or device binary search trees and binary heaps.

1.1   Traversal

Many problems or trouble require we visit* the intersection or nodes of a tree in a planned or systematic way: tasks or function such as counting or add up how many intersection or nodes exist or finding the maximum or largest element. Three different system or methods are workable or possible for binary trees: preorder, postorder, and in-order, which all do the same three things: recursively or looping traverse both the left and rights subtrees and visit the current intersection or node. The difference is when the task or algorithm visits the current intersection or node:

Visit means execute or performing some running or operation involving or require the current intersection or node of a tree, like incrementing or raise a counter or checking if the value of the current intersection or node is greater than any other recorded.


Computer stuff kit tricks of Topics 70.



Tuesday, 27 June 2023

Trees in C Language

What is Trees in C?

1.1   Introduction

Mathematically, it is not a tree, but arborescence or resembling a tree: an acyclic connected graph where each intersection or node has zero or more children nodes or intersection and at most one parent node. Furthermore, the children of each node or intersection have a specific order.

 A node or intersection is a structure which may carry or contain a value, a condition, or represent a separate information or data structure (which could be a tree of its own). up as they do in creation or nature). A node that has a child is called the child’s parent intersection or node (or superior node, or ancestor). A node or intersection has at most one parent.

Trees in C, C Language, C basic language
Trees in C language image-1

Nodes or intersections that do not have any children are called leaf nodes. They are also referred to as last or terminal nodes.

 The depth of a node or intersection is the length of the path to its tuber or root (i.e., its root path). This is commonly needed in the manipulation or trick of the various self balancing trees, AVL Trees in particular.

 The topmost node or intersection in a tree is called the tuber or root node. Being the topmost intersection or node, the tuber or root node will not have parents. It is the intersection or node at which performance or operations on the tree commonly begin (although some algorithms begin with the leaf intersection or nodes and raise or work up ending at the root). All other intersection or nodes can be reached from it by following edges or links. (in the formal definition, each such path is also unique or single).

 In some trees, such as mass or heaps, the root intersection or node has special properties. Every intersection or node in a tree can be seen as the tuber or root node of the subtree rooted at that node.

An inner node or internal node is any node of a tree that has child intersection or nodes and is thus not a leaf node.


Computer stuff kit tricks of Topics 69.







Monday, 26 June 2023

Searching Algorithms in C

What is searching Algorithms?

Searching is an operation or performance which finds the site or location of a given section or element in a list. The search is said to be victorious or unsuccessful or pointless depending on whether the section or element that is to be searched is begin or found or not. The following are the dissimilar types of searches

1.       Linear Search

2.       Binary Search

 

Algorithms in C, C language, C programming
Searching Algorithms Image-1

1.1   Linear Search

It is also known as successive or sequential search, which is fit or suitable for searching a set of data for a certain or particular value.
It is the easy or simplest procedure or method of searching, and it can be put in or applied to a sorted or an unsorted list.
It work or operates by checking every section or element of a list one at a time in order or sequence until a match is found. Linear search runs in O(N). If the information or data are distributed or give out randomly, on average N/2 balancing or comparisons will be needed.
The best case or instance is that the value is equal to the firs section or element tested, in which case only1 balancing or comparison is needed. The poorest or worst case is that the worth or value is not in the list (or is the last thing or item in the list), in which case N balancing or comparisons are needed.
Suppose or think an array A having section or elements 1 to N is to be searched for a worth or value x: if not found, the result is zero.

1.2   Binary Search

The most effective or fruitful technique that can be applied to sorted data or records is the binary search technique. This technique or ability is faster than the other searching techniques.

1.       The given sorted data or records are divided into two halves.

2.       The key is first compared or measure with the key area or field of the middle record.

3.       If the match or tie is found, the key index or sign is returned.

4.       If it does not match or tie, then required key must be either in the lower or upper half.

5.       If the key is less than the key field or area of the middle data or record, the key is searched in the lower half otherwise it is checked or inspect in the upper half.


Computer stuff kit tricks of Topics 68.




Sunday, 25 June 2023

Sorting Algorithms in C

What is sorting Algorithms?

Sorting means set out or arranging a set of data in some order. There are unlike or different methods that are used to sort the data in arise or ascending or descending or go down order. Few of them are listed and talk about or discussed in detail below.

sorting Algorithms, bubble sort, selection sort, quick sort
Sorting Algorithms in C Image-1


1.       Bubble sort

2.       Selection sort

3.       Insertion sort

4.       Heap sort

5.       Merge sort

6.       Quick sort

1.1   Bubble Sort

Bubble sort is a simple sorting task or algorithm. The task or algorithm gets its name from the way smaller part or elements “bubble” to the top of the list. Because it only uses balancing or comparisons to work or operate on elements, it is a balancing or comparison sort.

1.2   Selection sort

Selection sort is a sorting task or algorithm, particular or specifically an in-place balancing or comparison sort.

1.3   Insertion sort

Insertion sort is a simple sorting task or algorithm, a balancing or comparison sort in which the sorted array (or list) is built one entry at a time. It is much less logical on large lists than more up to date algorithms or task such as quick sort, heap sort, or merge sort. However, insertion sort give several advantages:

1.       Simple implementation or execution

2.       Efficient or adequate for (quite) small data sets

3.       Adaptive or flexible, i.e. efficient for data or record sets that are already substantially or greatly sorted: the time difficulty or complexity is O(n +d), where d is the number of inversions or reversal.

4.       More logical or efficient in practice than most other simple foursquare or quadratic (i.e. O(n square)) algorithms or task such as selection sort or bubble sort: the average running time is n square/4, and the management or running time is linear in the best case

5.       Stable, i.e. does not change the respective or relative order of part or elements with equal keys

6.       In-place, i.e. only requires a continuous or constant amount O(1) of additional memory space

7.       Online, i.e. can sort a list as it collect or receives it.

1.4   Heap sort

The heap sort works as its name submit or suggests. It begins by place or building a heap out of the data set, and then take out or removing the largest item and set or placing it at the end of the sorted array. After removing the largest item, it rebuild or reconstructs the heap, removes the largest last or remaining item, and places it in the next open place or position from the end of the sorted array. This is frequent or repeated until there are no items left in the heap and the sorted array is full. Elementary or easy implementations require two arrays – one to hold the mass or heap and the other to hold the sorted part or elements.

1.5   Merge sort

Merge sort is an O(n log n) balancing or comparison-based sorting task or algorithm. In most implementations or execution it is stable, meaning that it protect or preserves the input order of equal part or elements in the sorted output. It is an example of the divide and conquer algorithmic or task paradigm. It was create or invented by john von Neumann in 1945.

1.6   Quick sort

The quick sort algorithm was grow or developed by C. A. R. Hoare while in the Soviet Union, as a stay with or visiting student at Moscow State University. At that time, Hoare worked in a project a tool or machine translation for the National Physical Laboratory.


Computer stuff kit tricks of Topics 67.






Saturday, 24 June 2023

Data Structure in C

What is Data Structure?

Consider a plan or program to work on the data of students in a school. Each students record would have definite certain fields namely naming or identity number, student name, class etc. From what we have take in or learnt so far we could use a structure to summarize or encapsulate these fields. We store these data or records in files, so we could use structure flexible or variables to read a record from a file or write a data or record to a file.

Data Structure, c language, C program
Data Structure Image-1

If we wanted to operate or manipulate several data or records at once we would need an array of structures. Say if we wanted to show, all the students data or records in the order of their naming or identity numbers we would need to read them from the file they are keep or stored into an array of structures.

This is because the C language does not offer any file company or organization methods other than the uninterrupted or sequential file operation or organization. In other words when you write data or records into a file in the C language you write the data or records in a sequence. The language does not offer any operation or organization such as sign or index File Company or organization where the data or records can be read or accessed at random on a key value.

The fseek function does allow random read or access to file data but only based on the byte balance or offset. Therefore we first have to access or read them into an array of structures, sort the array by the key area or field, and display each element of the array.

Here is where we can see the issue or problem with arrays during coding or programming. The question, which appear or arises, is what should the size of the array? Obviously or clearly our array must have at least as many elements or components as the biggest or maximum number of records we plan or intend reading from the file.

Now, if we utilize or use an array that is too big (say there are only five hundred data or records in the data file and the array size we have put or set, to read or access these data or records into, is one thousand elements or components long) every time we run the plan or program we are going to set aside or reserve memory for one thousand structures but use only five hundred.

Worse or poor would be the case if the number of students in the school grow or increases to over a thousand. Then we would have to change the plan or program code and grow or increase the army size and keep doing so forever.


Computer stuff kit tricks of Topics 66.





Thursday, 22 June 2023

Compilation Stages in C

What is Compilation Stages?

Consider a simple program hello.c

#include<stdio.h>
int main()
{
printf(“hello, computer\n”);
return 0;
}

C language, compilation stages tips, tips and tricks
Compilation stage image-1

The first work or action is to activate a preliminary or opening process called the initialization or pre-processor. In the case of hello.c all it does is to return or replace the line #include <stdio.h> with the file stdio.h from the cover or include files library. The file stdio.h provides or gives us with a suitable or convenient way of telling the author or compiler that all the i/o task or functions exist. There are a few other little item or things in stdio.h but they need not cover or concern us at this stage.

In order to see what the initialization or pre-processor actually outputs, you might like to topic or issue the command:

cc-E hello.c – o hello.i

The ‘cc’ command will operate or activate the ‘C’ compilation or collection system and the –E option will stop the collection or compilation process after the pre-processing stage, and another file will have look or appeared in your directory. Have a look, find hello.i and use the editor in view method or mode to have a look at it. So issue the command:

vi hello.i

You will see that a number of lines of work or text have been added at the front of the hello.c plan or program. What’s all this matter or stuff? Well, have a look in the file called /usr/include/stdio.h again using the view instruct or command.

vi /usr/include/stdio.h

Now the next period or stage of getting from your program text to a perform or executing plan or program is the collection or compilation of your text into an assembler code program. After all that is what a editor or compiler is for – to turn a high level language script into a plan or program.

Let’s see what happens by issuing the instruct or command

cc –C hello.s –o hello.o

Now, yet again there is another file in your index or directory – this time the suffix is “.o”. This file or folder is called the object file. It carry or contains the machine command or instructions keep in touch or corresponding exactly to the help or mnemonic codes in the .s file. The next stage in the collection or compilation process is called by a diversity or variety of names –“loading”, “link editing”, “linking”. What happens is that the tool or machine instructions in the object file (.o) are joined to many more order or instructions selected from a huge or enormous collection of functions in a library.


Computer stuff kit tricks of Topics 65.

What is C Preprocessor in C language?


Wednesday, 21 June 2023

Including files in C

What is including files in C?

The preprocessor directive #include is used to include or cover a file into the birthplace or source code. We have already used this command or directive to include header files in our plan or programs. The filename should be within viewpoint or angle brackets or double repeat or quotes. The syntax is –

#include <filename>

#include “filename”

Preprocessor, define, files in C, C language
C program library files Image-1

The preprocessor return or replaces the #include directive or command by the satisfy or contents of the specified file. After including the file, the total or entire contents of file can be used in the plan or program. If the filename is in double repeat or quotes, first it is look or searched in the current directory (where the birthplace or source file is present), if not found there then it is look or searched in the include directory. If the filename is with viewpoint or angle brackets, then the file is searched in the quality or standard include directory only. The statement or specification of standard or quality include directory is execution or implementation defined.

Include files can be fixed or nested i.e. an included file can carry or contain another #include directive.

1.1 The #define and #undef Directives

The #define directive is the most usual or common preprocessor directive, which tells the preprocessor to return or replace every event or occurrence of a particular character string (that is, a macro name) with a define or specified value (that is, a macro body).

The syntax for the #define directive is

                #define macro_name macro_body

Here macro_name is a proof or identifier that can carry or contain letters, numerals, or underscores. Macro_body may be a string or a data item, which is old or used to substitute each macro_name found in the program or plan.

As bring up or mentioned earlier, the running or operation to replace event or occurrences of macro_name with the value define or specified by macro_body is known as macro exchange or substitution or macro expansion.

The value of the macro body define or specified by a #define directive can be any character string or number.

                                #define STATE_NAME “Texas”

Then, during preprocessing, all event or occurrences of STATE_NAME will be replaced by “Texas”.

                #define SUM (12+8)

On the other hand, you can use the #undef directive to separate or remove the definition of a macro name that has been previously defined.

The syntax for the #undef directive is

                                #undef macro_name

Here macro_name is an identifier that has been previously explain or defined by a #define directive.

The #undef directive “undefines” a macro name.

For case or instance, the following segment of code:
#define STATE_NAME “Texas”
printf (“I am moving out of %s. \n”, STATE_NAME);
#undef STATE_NAME


Computer stuff kit tricks of Topics 64.