answersLogoWhite

0

📱

Computer Programming

A category for questions about computer programming and programming languages.

10,506 Questions

How many algorithms are there for sorting purpose and what are they?

There are many sorting algorithms however there are only a small handful that we actually use: insertion sort (stable) is typically used for small sets while large data sets primarily use heapsort (unstable), merge sort (stable) or quicksort (unstable). Efficient implementations typically use a hybrid sort such as Timsort (stable) or introsort (unstable).

The following lists all the documented algorithms currently listed in Wikipedia's "Sorting algorithm" page:

Quicksort, merge sort, in-place merge sort, heapsort, insertion sort, introsort, selection sort, Timsort, cubesort, shell sort, bubble sort, binary tree sort, cycle sort, library sort, patience sorting, smoothsort, strand sort, tournament sort, cocktail sort, comb sort, gnome sort, unshuffle sort, Franceschini's sort, block sort, odd-even sort, pigeonhole sort, bucket sort (uniform keys), bucket sort (integer keys), counting sort, LSD radix sort, MSD radix sort, MSD radix sort in-place, spreadsort, burstsort, flashsort, postman sort bead sort, simple pancake sort, spaghetti sort, sorting network, bitonic sorter, bogo sort, stooge sort, Han's algorithm, Thorup's algorithm.

How data can be read or write from sim?

We can use the SIM Application Toolkit (STK) to both read and write to a SIM.

What does translating algorithms known for?

Translating algorithms (such that a machine can understand them) is known as programming.

Can you write an algorithm and flowchart for finding the largest and smallest numbers in a given list of N numbers.?

We can't draw flowcharts in a text-based website such as this. We can only answer questions.

Assuming the list is unsorted, the most efficient algorithm is as follows:

1. Assume the first value is the largest and save the value (MAX)

2. Assume the first value is the smallest and save the value (MIN)

3. Traverse the remainder of the list:-

  • If the current value is greater than MAX, assign that value to MAX
  • Otherwise, if the current value is less than MIN, assign that value to MIN
4. Return the value of MAX and MIN

The following demonstrates a general-purpose implementation of this algorithm in C++.

// a data structure to store a range of type T [min:max]:

template

struct range {

T min;

T max;

};

// determine the range of a list of type T (assume the list is unsorted)

template

range get_range (const std::list& list) {

if (list.empty()) throw std::range_error(); // sanity check! std::list::const_iterator iter = list.cbegin(); // refer to first item

range result {*iter, *iter}; // initialise the range with the value of the first item

while (++iter != list.end()) // repeat for all other items...

if (*iter

else if (result.max<*iter) result.max = *iter; // or update the maximum if current item is larger

return result;

}

What is the function ipconfigrenew?

ipconfig /renew is used to renew your DHCP IP address after releasing it with ipconfig /release. If no adaptor is specified, all adaptors are renewed.

What is the assembly language development phases?

Really no different than development in any other language: requirements definition, general design, detail design, coding, testing and implementation.

When do we use Python coding in every day life?

You do not use Python coding in every day life. Most people in every day life are not programmers of any kind. Of those who are programmers, nobody uses Python in everyday life unless they happen write or maintain server-side scripts in Python every day. Other languages are available, of course.

How do you write a void function to delete all nodes in a doubly linked list?

void delete_all (list* lst) {

if (!lst !lst->count) return; // sanity check!

while (lst->count) { // repeat until the list is empty

node* tail = lst->tail; // store the current tail

lst->tail = tail->prev; // set the new tail

if (lst->tail) lst->tail->next = NULL; // detach the old tail from the new tail (if there is one)

else (lst->head = NULL); // if there is no tail then here can be no head either

free (tail->data); // release the old tail's data

free (tail); // release the old tail

lst->count--; // update the count

}

}

The above function assumes your list uses the following C-style structures:

typedef struct node_t {void* data; node* next; node* prev; } node;

typedef struct list_t {node* head; node* tail; unsigned count; } list;

What strategies are most useful in helping me develop algorithms for adding subtracting multiplying and dividing positive and negative numbers?

You mean arithmetic. Your best strategy would be to use the algorithms that already exist. They are already well-established, highly-efficient and bug-free. By all means study them to improve your understanding of how they work (although you should already know how they work), but don't waste any time trying to improve upon them. After all, humans have been performing arithmetic for thousands of years, the only thing that's actually changed in all that time is the notation; the algorithms themselves were already in place long before we ever had computers.

How does the use of a variable instead of a value help to reduce detail and focus?

We try to generalise our code as much as we can. We cannot avoid using values completely, however a value is a literal constant and if we use the same constant over and over it makes sense to use a named constant variable rather than a value, if only to make it much easier to change the value throughout our code.
To use a real world example, suppose we are writing a Sudoku solving program. The value 9 crops up quite a lot because there are 9 rows, 9 columns, 9 boxes and 9 digits, one of which is the digit 9. However, Sudoku is not a number puzzle, we just use digits for notational convenience. Any 9 unique symbols would do, so using variables instead of values would give us the ability to change symbols.

Moreover, Sudoku puzzles are not just limited to 9 rows, columns and boxes, we can use any number that is a square. 9 is the square of 3 thus a standard Sudoku has order 3. We can also use order 2 (a 4x4 Sudoku), order 4 (a 16x16 Sudoku) and so on. The size of the Sudoku does not change the logic of solving it, so by using a variable to keep track of the order we can cater for any size Sudoku without changing the code. Our code becomes more generalised (less detailed) because it no longer focuses on a standard Sudoku.

What are the Advantages of updating files?

Updating files ensures that the files contain the most up-to-date information available. In most cases updates will provide new information that wasn't previously available, or will correct information that was previously in error. A well-organised database will also provide a complete history of all amendments made to a file, when they were made, why they were made and who updated them. This ensures the quality of the information provided is as reliable as possible.

Program plus program?

Programs are not limited to single use. They can and are often used as components for larger more complex programs. The term for these programs are 'libraries'. In the development of good software, reuse is a highly important concept. Writing good code takes a lot of time. It takes many tests and versions to come up with good code that is error free. By using libraries that are already heavily tested and optimized, time can be saved.

Why do we use programming languages?

A computer can carry out millions, even billions, of operations every second. Thus, it can do things much faster - and usually much more accurately - than a human. To tell the computer what to do, you write instructions in a special language, called a "programming language".

To be accurate, internally the computer uses very specific instructions, the so-called "machine language". Since programming in machine language is awkward, programmers program in higher-level languages, that are easier to understand for humans - such as Assembly language, Java, C, Pascal, etc. Then, a special program called a "compiler" then converts this to instructions the computer can understand.

A computer can carry out millions, even billions, of operations every second. Thus, it can do things much faster - and usually much more accurately - than a human. To tell the computer what to do, you write instructions in a special language, called a "programming language".

To be accurate, internally the computer uses very specific instructions, the so-called "machine language". Since programming in machine language is awkward, programmers program in higher-level languages, that are easier to understand for humans - such as Assembly language, Java, C, Pascal, etc. Then, a special program called a "compiler" then converts this to instructions the computer can understand.

A computer can carry out millions, even billions, of operations every second. Thus, it can do things much faster - and usually much more accurately - than a human. To tell the computer what to do, you write instructions in a special language, called a "programming language".

To be accurate, internally the computer uses very specific instructions, the so-called "machine language". Since programming in machine language is awkward, programmers program in higher-level languages, that are easier to understand for humans - such as Assembly language, Java, C, Pascal, etc. Then, a special program called a "compiler" then converts this to instructions the computer can understand.

A computer can carry out millions, even billions, of operations every second. Thus, it can do things much faster - and usually much more accurately - than a human. To tell the computer what to do, you write instructions in a special language, called a "programming language".

To be accurate, internally the computer uses very specific instructions, the so-called "machine language". Since programming in machine language is awkward, programmers program in higher-level languages, that are easier to understand for humans - such as Assembly language, Java, C, Pascal, etc. Then, a special program called a "compiler" then converts this to instructions the computer can understand.

What does U0001f52aU0001f60f mean?

It's 32-bit unsigned hexadecimal notation for two decimal values, 128298 and 128527. However, the spacing is wrong and there should be an operator between the two values.

E.g., U0001f52a OR U0001f60f = U0001f72f

In binary, this would equate to:

00000000000000011111010100101010

OR

00000000000000011111011000001111

=

00000000000000011111011100101111

When is it better to use a condition-controlled loop rather then a count-controlled loop?

All loops must be condition-controlled with at least one terminating condition that is reachable. The two main types of loop are called counted loops and infinite loops.

Counted loops are typically implemented using a for statement. Although you can use while, do-while or goto loops to achieve the same thing, we must always strive to express our ideas directly in code and the for loop directly expresses the notion of a counted loop:

for(int i=0; i<100; ++i) {

// ...

}

Here, the body of the loop will execute 100 times. There is no need to comment the loop to state this fact because the for statement contains everything we need to know about this loop; it's all up front at the start of the loop. The initialiser (int i=0) executes one-time only. The conditional expression (i<100) is evaluated before each iteration and the action (++i) is executed at the end of each iteration.

Each of the three arguments in a for statement is optional, thus it is the most versatile of the looping statements. We can also use the comma-operator to perform two or more actions at the end of each loop if we need to. If we leave out all the arguments then we create an infinite loop:

for (;;) {

//...

}

A for statement with no arguments is simply taken to mean "for ever" (or forever). However, the while loop arguably expresses the notion of an infinite loop better:

while (1) {

// ...

}

Of course, even with an infinite loop we still need a terminating condition otherwise our code would literally get stuck in the loop forever. We can place break statements anywhere in the body, however terminating conditions are ideally placed up front at the start of the loop where they are easy to see:

while (1) {

if (!condition1) break; if (!condition2) break;

if (!condition3) break;

// ...

}

In this case it would arguably make far more sense to place the conditions in the loop statement itself:

while (condition1 && condition2 && condition3) {

// ...

}

How you structure your loops is entirely up to you, however the aim is to express the logic of the loop as clearly as possible. Placing the logic up-front simply makes your code easier to read and easier to maintain.

A do-while loop differs from a for loop and a while loop in that the condition is always evaluated at the end of each iteration. Thus the loop body will always execute at least once. If you need to use this looping structure, it helps to comment the start of the loop with the terminating condition in order to help the reader:

int i = random();

do { // until i is 100

// ...

// ... lots of code...

// ...

} while (i!=100);

We can also use goto loops to create highly-complex looping structures with multiple entry and exit points however these are best avoided as they are difficult to read. Anything that is difficult to read is also difficult to maintain, but goto loops can turn even the simplest code into incomprehensible "spaghetti" code. The only practical use of a goto statement is in order to break out of a nested loop:

for (int x=0; x<10; ++x)

{

for (int y=0; y<10; ++y)

{

if(x*y>50) goto exit_door;

// ...

}

}

exit_door:

// ...

What provides access to system programs for editing compiling and so on?

Editing and compiling a systems program requires access to the source code as well as included source/header files and libraries. Commercial source code is only available if it is distributed under an open source licence while closed source is only available if you receive or purchase rights to the source code from the vendor.

Once you have access to the source code, any text editor can be used to edit the code although A code editor specific to the language may make things easier. You also need a compiler to compile the edited code, including the "make" file if there is one. Source code may be compiler-dependent and/or architecture-dependent and you may need the same compiler and/or architecture used for the original source.

What is the function for rounding off numbers?

In Excel, the function is Round(number, num_digits) where

number is the number that you want to round,

and

num_digits is the number of digits after the decimal point that you want.

If num_digits < 0 then the number is rounded to that many digits to the left of the decimal point.

What is sieve technique in selection algorithm?

The sieve technique in selection algorithms refers to a method for efficiently filtering or selecting elements from a dataset based on specific criteria. It is often used in algorithms like the Sieve of Eratosthenes for finding prime numbers, where non-prime numbers are systematically eliminated from the list. This technique can be adapted for other selection problems, allowing for reduced computational complexity by narrowing down candidates before making final selections. Overall, the sieve approach enhances performance by minimizing the number of comparisons or evaluations needed.

What are the 3 primitive logic structures?

The three primitive logic structures in programming are selection, loop and sequence. Any algorithm can be written using just these three structures.

What is the purpose of placing comments in your source code?

Comments are useful to explain what lines of your source code do. When a new member is assigned to a project that has already been worked on the comments allow them to better see where the last programmer left off. It would also be helpful if you were assigned to a project that was already started ;)