answersLogoWhite

0

📱

Computer Programming

A category for questions about computer programming and programming languages.

10,506 Questions

When is a number called a 'Sunny' number?

A number is said to be 'sunny' when, 1 added to that number, the square root of it becomes a whole number...

What is license key of Advanced System Protector 2.1 rather than downloading it's freeware and thank you?

If it's freeware - it doesn't require a licence key ! The whole point of freeware, shareware etc - is that the end user can use the software without charge. However, IF the user feels the software is useful, they can voluntarily donate whatever sum of money they feel the software is worth - to the program's writer.

The SSID is also known as the?

service set identifier, a 32-character unique identifier attached to theheader of packets sent over a WLAN that acts as a password when a mobiledevice tries to connect to the BSS. The SSID differentiates one WLAN from another, so all access points and all devices attempting to connect to a specific WLAN must use the same SSID. A device will not be permitted to join the BSS unless it can provide the unique SSID. Because an SSID can be sniffed inplain text from a packet it does not supply any security to the network.

An SSID is also referred to as a network name because essentially it is a name that identifies a wireless network.

How do you create Write a program that takes 10 integers as input The program will place these integers into an array and display the following 1. List in ascending order 2. mean 3. median 4.max val?

import java.util.Arrays;

import java.util.Scanner;

public class Answers {

public static void main(String[] args) {

//Creates a scanner object named console.

Scanner console = new Scanner(System.in);

//Variabels

int [] numbers = new int [10];

double avg = 0.0;

double median = 0.0;

int max = numbers[0];

double count = 0.0;

//User input.

for (int i = 0; i < numbers.length; i++){

System.out.print("Number: ");

numbers[i] = console.nextInt();

}

//break

System.out.println("===============");

//finds the average and max value.

for (int i = 0; i < numbers.length; i++){

count += numbers[i];

avg = count / numbers.length; //average

if (numbers[i] > max){ //finds the max value.

max = numbers[i];

}

}

median = (numbers[4] + numbers[5])/2; //Median value

//Display to user.

System.out.println("Highest value found: " + max); //Show maximum value found in array

System.out.printf("Median is: %.3f \n",median); //Show median

System.out.printf("Average is: %.3f \n",avg); //Show average

sortAsc(numbers); //Print out whole array ascending

}

//Method for sorting an Array ascending.

public static void sortAsc(int [] array){

for (int i = 0; i < array.length; i++){

Arrays.sort(array);

System.out.println(array[i]);

}

}

}

This should do everything you asked for, hope this helps!

1.difference between stack using arrays and queue using arrays and 2.difference between stack using linked list and queue using linked list?

Both questions really boil down to the difference between a stack and a queue, so let's deal with that first. A stack is used when you want a last-in, first-out collection (LIFO), like a stack of plates; the last plate you place on the stack is the first to come off the stack. A queue is a first-in, first out collection (FIFO); the first person in a queue is the first to be served.

Secondly, we would never use an array for a stack or a queue. Arrays must be resized dynamically, both to cater for new elements and to remove redundant elements. When catering for a new element, it may be necessary to reallocate the entire array because arrays must reside in contiguous memory. We can alleviate some of this burden by allocating more elements than we actually need, but this wastes precious memory unnecessarily. Alternatively, we can use a two-dimensional array to allocate non-contiguous blocks of memory (which is important when the array is large), but it still wastes memory unnecessarily.

Linked lists are the optimum model for both stacks and queues as the nodes need not reside in contiguous memory and memory can be allocated and deallocated on a per-node basis with minimum impact on performance and memory consumption. While it is true some additional memory is required per-node to cater for each node pointing to the next, there is no redundant memory. And while arrays do allow constant-time random access to any element, stacks and queues do not require random access.

The main feature of a stack is that we require constant time access to the head of the stack. Insertions and extractions are made only to the head of the stack, therefore we need only maintain one pointer to the head of the stack. When a new node is inserted, its next node points to the existing head of the stack (which may be NULL if the stack is empty), and then the head pointer points to the new node. When the head node is extracted, its next node (which may be NULL) becomes the new head pointer.

The main feature of a queue is that we require constant time access to both the head and the tail. Insertions occur at the tail and extractions at the head, therefore we need two pointers, one at the head node, the other at the tail node. Initially both point to NULL. When a new node is inserted and the tail is NULL, both the head and tail point to the new node, otherwise the tail node points to the new node and the new node becomes the tail. The tail node always points to NULL. Extracting the head node is the same as in a stack, except the tail node is set to NULL whenever the head is set to NULL.

To fully address the question, let's consider stacks and queues using arrays. We'll ignore the resizing issues simply by assuming that there are initially 10 unused elements, and whenever there are fewer than 5 unused elements the array will be resized by an extra 10 elements, and reduced by 10 elements whenever there are more than 15 unused elements. Thus there will always be at least 10 elements. There are better methods than this, but it will suffice for the purpose of this answer.

Since insertions at the start of the array would require us to copy all elements into the next element to make room for the insertion, all insertions will occur at the end of the array in the first unused element. Therefore we must maintain a zero-based index of the first unused element (the tail). When we insert an element at that index, the tail is simply incremented.

For the stack, extractions also occur at the tail. Therefore, if the tail is non-zero, we simply decrement the tail and extract the element at that index. If the tail is zero, the stack is empty. Otherwise the tail tells us how many elements have been used for resizing purposes. Resizing should be done after an insertion or extraction.

For the queue, extractions occur at the head, therefore we initially point at element zero. If the head and tail are different, an item exists at the head element so we extract it and increment the head. If the head and tail are the same, then there are no elements in use so both can be reset to zero. The only real complication is in working out how many unused elements there are for resizing purposes. For this we simply subtract the head from the tail to determine how many elements are in use. This should be done prior to any insertion. If a resize is required it would be prudent to shunt all used elements to the start of the array and adjust the head and tail accordingly, then perform the insertion.

As you can appreciate, a queue is more complex than a stack when using an array, but ultimately an array is more complex than a linked list for both stacks and queues.

What is a virtual directory?

virtual directory are that directory throgh which we map to location of the directory.suppose you need to make a directory on a place but we dont have the sufficient place for creating directory then for mapping the directory on that place we create directoy on different location and map to current location.this is called virtual directory.

What is the advantage of using functions and write a c program to explain about built-in functions with examples?

C does not have any built-in functions as such. The language allows the programmer to create functions or to include functions contained in external function libraries, but the language itself has no functions whatsoever. The C standard library is not considered built-in since programmers are free to ignore the standard library completely. However, the library contains highly efficient, optimised functions that are considered "general purpose" and therefore useful to the majority of programmers. The programmer can use these functions as the basis for more complex, more specialised functions.

The main advantage of functions is that they allow programmers to break programs down into a series of simple subroutines, each of which is handled by a function. Functions can call other functions, including themselves, and can be called as often as required. Although some code duplication is inevitable in any program, by placing duplicate code in a function, the programmer ensures that the code remains consistent. Since the function code is in one place, it is much easier to maintain that code, there is no need to make multiple changes across all duplicates, which is error prone and could introduce inconsistencies. Also, with well-named functions, code becomes self-documenting, making it easier to express ideas in code without the need for verbose comments within the code itself, which tends to be distracting rather than helpful.

Where does thread come from?

Thread originated in Kelowna in the 1940's, the creater was Stephany Vienneau.

What are the disadvantages of having two users on your computer?

They cannot use the same computer in the same time, only if it runs a multiuser operating system (unix).

What is sub VI in labview programming?

It is similar to a function in other languages. It allows you to create your own "block" which can be used to reuse code and organise code.

What is the difference between searching and sorting in design analysis algorithm?

When you're searching for something you are simply examining each entity, comparing them with another entity in order to locate a match. When you're sorting entities, you are re-arranging the order of those entities. In both cases you will perform a comparison between two entities at a time, the only real difference is that you do not re-arrange the entities when searching.

How to design a finite automata to accept a palindrome no?

Design a pushdown automata for the same.

Otherwise, you can use the following grammer :

S -> aSb|bSa|<NULL>

Why void is used in c language?

void as function return-type means no return value

void as function parameter means no parameter

void * as pointer type means generic pointer

How can algorithm discovery be made easier?

Algorithm discovery can be made easier by leveraging automated machine learning (AutoML) tools that streamline the selection and optimization of algorithms based on the specific characteristics of the data. Additionally, utilizing techniques like evolutionary algorithms or reinforcement learning can aid in exploring the solution space more efficiently. Collaborative platforms that share insights and results can also foster knowledge exchange and inspire new approaches. Finally, simplifying the user interface and providing better visualization tools can help users from diverse backgrounds engage in the discovery process more effectively.